From 86959c752528e1e96f44c87bbd811998b502dca9 Mon Sep 17 00:00:00 2001 From: neerajp99 Date: Tue, 11 Jun 2019 05:02:46 +0530 Subject: [PATCH 01/24] Add tests for Controller --- tests/src/Unit/ControllerTest.php | 40 +++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 tests/src/Unit/ControllerTest.php diff --git a/tests/src/Unit/ControllerTest.php b/tests/src/Unit/ControllerTest.php new file mode 100644 index 0000000..1bf3f44 --- /dev/null +++ b/tests/src/Unit/ControllerTest.php @@ -0,0 +1,40 @@ +getMockBuilder(SocialPostNetworkInterface::class) + ->getMock(); + $this->assertTrue( + method_exists($socialPostNetworkInterface, 'post'), + 'SocialPostNetworkInterface does not implements post function/method' + ); + } + +} From e8c40ad6ca8b99dbd4d7476b532f3bfcb84a92fd Mon Sep 17 00:00:00 2001 From: neerajp99 Date: Tue, 11 Jun 2019 05:03:00 +0530 Subject: [PATCH 02/24] Add tests for Network --- tests/src/Unit/NetworkTest.php | 46 ++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 tests/src/Unit/NetworkTest.php diff --git a/tests/src/Unit/NetworkTest.php b/tests/src/Unit/NetworkTest.php new file mode 100644 index 0000000..2d4bba5 --- /dev/null +++ b/tests/src/Unit/NetworkTest.php @@ -0,0 +1,46 @@ +getMockBuilder(ControllerBase::class) + ->getMock(); + $listBuilder = $this->createMock(SocialPostListBuilder::class); + $controllerBase->method('buildList') + ->with('facebook') + ->willReturn($listBuilder->render()); + $this->assertTrue( + method_exists($controllerBase, 'buildList'), + 'ControllerBase does not implements buildList function/method' + ); + $this->assertEquals($listBuilder->render(), $controllerBase->buildList('facebook')); + } + +} From 3cb6a4c810b42f7504377c1832eb0b59ee4907ac Mon Sep 17 00:00:00 2001 From: neerajp99 Date: Tue, 11 Jun 2019 05:03:24 +0530 Subject: [PATCH 03/24] Add tests for SocialPostManager --- tests/src/Unit/SocialPostManagerTest.php | 99 ++++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 tests/src/Unit/SocialPostManagerTest.php diff --git a/tests/src/Unit/SocialPostManagerTest.php b/tests/src/Unit/SocialPostManagerTest.php new file mode 100644 index 0000000..3e1849c --- /dev/null +++ b/tests/src/Unit/SocialPostManagerTest.php @@ -0,0 +1,99 @@ +createMock(EntityTypeManagerInterface::class); + $current_user = $this->createMock(AccountProxy::class); + $data_handler = $this->createMock(SocialPostDataHandler::class); + $socialPostManager = $this->getMockBuilder(SocialPostManager::class) + ->setConstructorArgs(array($entity_type_manager, + $current_user, + $data_handler, + )) + ->getMock(); + $this->assertTrue( + method_exists($socialPostManager, 'setPluginId'), + 'SocialPostManager does not implements setPluginId function/method' + ); + $this->assertTrue( + method_exists($socialPostManager, 'getPluginId'), + 'SocialPostManager does not implements getPluginId function/method' + ); + $this->assertTrue( + method_exists($socialPostManager, 'getAccountsByUserId'), + 'SocialPostManager does not implements getAccountsByUserId function/method' + ); + $this->assertTrue( + method_exists($socialPostManager, 'checkIfUserExists'), + 'SocialPostManager does not implements checkIfUserExists function/method' + ); + $this->assertTrue( + method_exists($socialPostManager, 'getCurrentUser'), + 'SocialPostManager does not implements getCurrentUser function/method' + ); + $this->assertTrue( + method_exists($socialPostManager, 'addRecord'), + 'SocialPostManager does not implements addRecord function/method' + ); + $this->assertTrue( + method_exists($socialPostManager, 'setSessionKeysToNullify'), + 'SocialPostManager does not implements setSessionKeysToNullify function/method' + ); + $this->assertTrue( + method_exists($socialPostManager, 'nullifySessionKeys'), + 'SocialPostManager does not implements cnullifySessionKeys function/method' + ); + $this->assertTrue( + method_exists($socialPostManager, 'updateToken'), + 'SocialPostManager does not implements updateToken function/method' + ); + $this->assertTrue( + method_exists($socialPostManager, 'getToken'), + 'SocialPostManager does not implements getToken function/method' + ); + $this->assertTrue( + method_exists($socialPostManager, 'encryptToken'), + 'SocialPostManager does not implements encryptToken function/method' + ); + $this->assertTrue( + method_exists($socialPostManager, 'decryptToken'), + 'SocialPostManager does not implements decryptToken function/method' + ); + $this->assertTrue( + method_exists($socialPostManager, 'getSalt'), + 'SocialPostManager does not implements getSalt function/method' + ); + } + +} From 7a015b93cad12c1802bdc49f7b91eb9ad61bc0e3 Mon Sep 17 00:00:00 2001 From: neerajp99 Date: Tue, 11 Jun 2019 05:03:48 +0530 Subject: [PATCH 04/24] Add tests for class UserAccessController --- .../src/Unit/UserAccessControlHandlerTest.php | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 tests/src/Unit/UserAccessControlHandlerTest.php diff --git a/tests/src/Unit/UserAccessControlHandlerTest.php b/tests/src/Unit/UserAccessControlHandlerTest.php new file mode 100644 index 0000000..a4d007a --- /dev/null +++ b/tests/src/Unit/UserAccessControlHandlerTest.php @@ -0,0 +1,61 @@ +createMock(EntityInterface::class); + $account = $this->createMock(AccountInterface::class); + $entity_type = $this->createMock(EntityTypeInterface::class); + $collection = $this->getMockBuilder(EntityAccessControlHandler::class) + ->setConstructorArgs(array($entity_type)) + ->getMock(); + $userAccessControlHandler = $this->getMockBuilder(UserAccessControlHandler::class) + ->setConstructorArgs(array($entity_type)) + ->getMock(); + + // $userAccessControlHandler->checkAccess($entity, 'view', $account); + // $reflection = new ReflectionClass(UserAccessControlHandler::class); + // $method = $reflection->getMethod('checkAccess'); + // $method->setAccessible(true); + // return $method; + $this->assertTrue( + method_exists($userAccessControlHandler, 'checkAccess'), + 'ControllerBase does not implements checkAccess function/method' + ); + $this->assertTrue( + method_exists($userAccessControlHandler, 'checkCreateAccess'), + 'ControllerBase does not implements checkCreateAccess function/method' + ); + } + +} From 33cffc319ae239dbbd13850668303fbe0e858aa5 Mon Sep 17 00:00:00 2001 From: neerajp99 Date: Tue, 11 Jun 2019 06:13:17 +0530 Subject: [PATCH 05/24] Add tests for Plugin --- tests/src/Unit/PluginTest.php | 40 +++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 tests/src/Unit/PluginTest.php diff --git a/tests/src/Unit/PluginTest.php b/tests/src/Unit/PluginTest.php new file mode 100644 index 0000000..1bf3f44 --- /dev/null +++ b/tests/src/Unit/PluginTest.php @@ -0,0 +1,40 @@ +getMockBuilder(SocialPostNetworkInterface::class) + ->getMock(); + $this->assertTrue( + method_exists($socialPostNetworkInterface, 'post'), + 'SocialPostNetworkInterface does not implements post function/method' + ); + } + +} From 23821011959861ca9094d0ba8c006c1131d992f9 Mon Sep 17 00:00:00 2001 From: neerajp99 Date: Tue, 11 Jun 2019 06:13:35 +0530 Subject: [PATCH 06/24] Add tests for Controller --- tests/src/Unit/ControllerTest.php | 22 +++++++++------ tests/src/Unit/NetworkTest.php | 46 ------------------------------- 2 files changed, 14 insertions(+), 54 deletions(-) delete mode 100644 tests/src/Unit/NetworkTest.php diff --git a/tests/src/Unit/ControllerTest.php b/tests/src/Unit/ControllerTest.php index 1bf3f44..2d4bba5 100644 --- a/tests/src/Unit/ControllerTest.php +++ b/tests/src/Unit/ControllerTest.php @@ -1,7 +1,8 @@ getMockBuilder(SocialPostNetworkInterface::class) - ->getMock(); + public function testControllerBase() { + $controllerBase = $this->getMockBuilder(ControllerBase::class) + ->getMock(); + $listBuilder = $this->createMock(SocialPostListBuilder::class); + $controllerBase->method('buildList') + ->with('facebook') + ->willReturn($listBuilder->render()); $this->assertTrue( - method_exists($socialPostNetworkInterface, 'post'), - 'SocialPostNetworkInterface does not implements post function/method' + method_exists($controllerBase, 'buildList'), + 'ControllerBase does not implements buildList function/method' ); + $this->assertEquals($listBuilder->render(), $controllerBase->buildList('facebook')); } } diff --git a/tests/src/Unit/NetworkTest.php b/tests/src/Unit/NetworkTest.php deleted file mode 100644 index 2d4bba5..0000000 --- a/tests/src/Unit/NetworkTest.php +++ /dev/null @@ -1,46 +0,0 @@ -getMockBuilder(ControllerBase::class) - ->getMock(); - $listBuilder = $this->createMock(SocialPostListBuilder::class); - $controllerBase->method('buildList') - ->with('facebook') - ->willReturn($listBuilder->render()); - $this->assertTrue( - method_exists($controllerBase, 'buildList'), - 'ControllerBase does not implements buildList function/method' - ); - $this->assertEquals($listBuilder->render(), $controllerBase->buildList('facebook')); - } - -} From fd033e54a8c3b9f6586812f1381048098008f18d Mon Sep 17 00:00:00 2001 From: neerajp99 Date: Thu, 13 Jun 2019 05:38:36 +0530 Subject: [PATCH 07/24] Modified Controller --- tests/src/Unit/ControllerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/src/Unit/ControllerTest.php b/tests/src/Unit/ControllerTest.php index 2d4bba5..9f4f707 100644 --- a/tests/src/Unit/ControllerTest.php +++ b/tests/src/Unit/ControllerTest.php @@ -35,7 +35,7 @@ public function testControllerBase() { $listBuilder = $this->createMock(SocialPostListBuilder::class); $controllerBase->method('buildList') ->with('facebook') - ->willReturn($listBuilder->render()); + ->will($this->returnValue($listBuilder->render())); $this->assertTrue( method_exists($controllerBase, 'buildList'), 'ControllerBase does not implements buildList function/method' From 0767daed8005e0b7f4b1163572a6ba6ee165561a Mon Sep 17 00:00:00 2001 From: neerajp99 Date: Thu, 13 Jun 2019 05:38:50 +0530 Subject: [PATCH 08/24] Add tests for class SocialPostMaager --- tests/src/Unit/SocialPostManagerTest.php | 45 ++++++++++++++++++++---- 1 file changed, 38 insertions(+), 7 deletions(-) diff --git a/tests/src/Unit/SocialPostManagerTest.php b/tests/src/Unit/SocialPostManagerTest.php index 3e1849c..ae6ee23 100644 --- a/tests/src/Unit/SocialPostManagerTest.php +++ b/tests/src/Unit/SocialPostManagerTest.php @@ -14,7 +14,6 @@ */ class SocialPostManagerTest extends UnitTestCase { - protected $plugin_id = 'drupal'; /** * Define __construct function. */ @@ -27,21 +26,48 @@ public function __construct() { */ public function setUp() { parent::setUp(); + $provider_user_id = 'drupaluser'; } /** * Tests for class UserAccessControlHandler. */ public function testSocialPostManager() { + $plugin_id = 'drupal'; + $user_id = 'drupaluser'; $entity_type_manager = $this->createMock(EntityTypeManagerInterface::class); $current_user = $this->createMock(AccountProxy::class); $data_handler = $this->createMock(SocialPostDataHandler::class); $socialPostManager = $this->getMockBuilder(SocialPostManager::class) - ->setConstructorArgs(array($entity_type_manager, - $current_user, - $data_handler, - )) - ->getMock(); + ->setConstructorArgs(array($entity_type_manager, + $current_user, + $data_handler, + )) + ->getMock(); + + $socialPostManager->setPluginId('drupal123'); + $socialPostManager->method('getPluginId') + ->willReturn('drupal123'); + + $socialPostManager->method('getCurrentUser') + ->willReturn(123); + + $socialPostManager->method('getAccountsByUserId') + ->with($plugin_id, $user_id) + ->will($this->returnValue(array( + 'user_id' => $user_id, + 'plugin_id' => $plugin_id, + ))); + + $socialPostManager->method('addRecord') + ->with('drupaluser','drupal123', 'drupal', $additional_data = NULL) + ->will($this->returnValue(TRUE)); + + $socialPostManager->setSessionKeysToNullify(array('drupal')); + + $socialPostManager->method('getSalt') + ->willReturn('drupal3ab9'); + $this->assertTrue( method_exists($socialPostManager, 'setPluginId'), 'SocialPostManager does not implements setPluginId function/method' @@ -94,6 +120,11 @@ public function testSocialPostManager() { method_exists($socialPostManager, 'getSalt'), 'SocialPostManager does not implements getSalt function/method' ); + $this->assertEquals('drupal123', $socialPostManager->getPluginId()); + $this->assertEquals(123, $socialPostManager->getCurrentUser()); + $this->assertEquals(['user_id' => 'drupaluser', 'plugin_id' => 'drupal'], + $socialPostManager->getAccountsByUserId($plugin_id, $user_id)); + $this->assertEquals('drupal3ab9', $socialPostManager->getSalt()); + $this->assertTrue($socialPostManager->addRecord('drupaluser','drupal123', 'drupal', $additional_data = NULL)); } - } From 75b254e55df6efeef4d08d07578442c24a6a93a9 Mon Sep 17 00:00:00 2001 From: neerajp99 Date: Thu, 13 Jun 2019 06:24:03 +0530 Subject: [PATCH 09/24] Add tests for class SocialPost --- tests/src/Unit/EntityTest.php | 67 +++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 tests/src/Unit/EntityTest.php diff --git a/tests/src/Unit/EntityTest.php b/tests/src/Unit/EntityTest.php new file mode 100644 index 0000000..5c6d0c8 --- /dev/null +++ b/tests/src/Unit/EntityTest.php @@ -0,0 +1,67 @@ +getMockBuilder(SocialPost::class) + ->disableOriginalConstructor() + ->getMock(); + + $socialPost->expects($this->any()) + ->method('getProviderUserId') + ->willReturn('drupalUser'); + + $socialPost->expects($this->any()) + ->method('getPluginId') + ->willReturn('implementerName'); + + $socialPost->expects($this->any()) + ->method('getName') + ->willReturn('providerName'); + + $socialPost->expects($this->any()) + ->method('getId') + ->willReturn('providerId'); + + $socialPost->expects($this->any()) + ->method('getUserId') + ->willReturn(123); + + $this->assertSame('drupalUser', $socialPost->getProviderUserId()); + $this->assertSame('implementerName', $socialPost->getPluginId()); + $this->assertSame('providerName', $socialPost->getName()); + $this->assertSame('providerId', $socialPost->getId()); + $this->assertSame(123, $socialPost->getUserId()); + } + +} From 3f649567389eea3eec3d74c72c34ecbb33569a12 Mon Sep 17 00:00:00 2001 From: neerajp99 Date: Thu, 13 Jun 2019 23:46:30 +0530 Subject: [PATCH 10/24] Edit tests for class SocialPostManager --- tests/src/Unit/SocialPostManagerTest.php | 30 ++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/tests/src/Unit/SocialPostManagerTest.php b/tests/src/Unit/SocialPostManagerTest.php index ae6ee23..3ab3069 100644 --- a/tests/src/Unit/SocialPostManagerTest.php +++ b/tests/src/Unit/SocialPostManagerTest.php @@ -127,4 +127,34 @@ public function testSocialPostManager() { $this->assertEquals('drupal3ab9', $socialPostManager->getSalt()); $this->assertTrue($socialPostManager->addRecord('drupaluser','drupal123', 'drupal', $additional_data = NULL)); } + + // public function testencryptToken($token = "drupal") { + // $entity_type_manager = $this->createMock(EntityTypeManagerInterface::class); + // $current_user = $this->createMock(AccountProxy::class); + // $data_handler = $this->createMock(SocialPostDataHandler::class); + // $socialPostManager = $this->getMockBuilder(SocialPostManager::class) + // ->setConstructorArgs(array($entity_type_manager, + // $current_user, + // $data_handler, + // )) + // ->getMock(); + // + // $socialPostManager->method('getSalt') + // ->willReturn('drupal3ab9'); + // $key = $socialPostManager->getSalt(); + // + // // Remove the base64 encoding from our key. + // $encryption_key = base64_decode($key); + // + // // Generate an initialization vector. + // $iv = openssl_random_pseudo_bytes(openssl_cipher_iv_length('aes-256-cbc')); + // + // // Encrypt the data using AES 256 encryption in CBC mode + // // using our encryption key and initialization vector. + // $encrypted = openssl_encrypt($token, 'aes-256-cbc', $encryption_key, 0, $iv); + // + // // The $iv is just as important as the key for decrypting, + // // so save it with our encrypted data using a unique separator (::). + // var_dump(base64_encode($encrypted . '::' . $iv)); + // } } From 3f41ea76be152fce8500b3524b223afefc473903 Mon Sep 17 00:00:00 2001 From: neerajp99 Date: Thu, 13 Jun 2019 23:46:47 +0530 Subject: [PATCH 11/24] Add tests for class SocialPostListBuilder --- tests/src/Unit/EntityTest.php | 77 +++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) diff --git a/tests/src/Unit/EntityTest.php b/tests/src/Unit/EntityTest.php index 5c6d0c8..bf36615 100644 --- a/tests/src/Unit/EntityTest.php +++ b/tests/src/Unit/EntityTest.php @@ -6,6 +6,13 @@ use Drupal\Core\Entity\EntityTypeInterface; use Drupal\Core\Entity\ContentEntityInterface; use Drupal\Core\Entity\EntityChangedTrait; +use Drupal\social_post\Entity\Controller\SocialPostListBuilder; +use Drupal\Core\Entity\EntityInterface; +use Drupal\Core\Entity\EntityListBuilder; +use Drupal\Core\Entity\EntityStorageInterface; +use Drupal\Core\Routing\UrlGeneratorInterface; +use Drupal\Core\Url; +use Symfony\Component\DependencyInjection\ContainerInterface; use Drupal\Tests\UnitTestCase; /** @@ -57,6 +64,27 @@ public function testSocialPost() { ->method('getUserId') ->willReturn(123); + $this->assertTrue( + method_exists($socialPost, 'getProviderUserId'), + 'SocialPost does not implements getProviderUserId function/method' + ); + $this->assertTrue( + method_exists($socialPost, 'getPluginId'), + 'SocialPost does not implements getPluginId function/method' + ); + $this->assertTrue( + method_exists($socialPost, 'getName'), + 'SocialPost does not implements getName function/method' + ); + $this->assertTrue( + method_exists($socialPost, 'getId'), + 'SocialPost does not implements getId function/method' + ); + $this->assertTrue( + method_exists($socialPost, 'getUserId'), + 'SocialPost does not implements getUserId function/method' + ); + $this->assertSame('drupalUser', $socialPost->getProviderUserId()); $this->assertSame('implementerName', $socialPost->getPluginId()); $this->assertSame('providerName', $socialPost->getName()); @@ -64,4 +92,53 @@ public function testSocialPost() { $this->assertSame(123, $socialPost->getUserId()); } + /** + * tests for class SocialPostListBuilder + */ + public function testSocialPostListBuilder() { + $entity_type = $this->createMock(EntityTypeInterface::class); + $storage = $this->createMock(EntityStorageInterface::class); + $user_entity = $this->createMock(EntityStorageInterface::class); + $url_generator = $this->createMock(UrlGeneratorInterface::class); + $entity = $this->createMock(EntityInterface::class); + $container = $this->createMock(ContainerInterface::class); + $entity_type = $this->createMock(EntityTypeInterface::class); + $socialPostListBuilder = $this->getMockBuilder(SocialPostListBuilder::class) + ->setConstructorArgs(array($entity_type, + $storage, + $user_entity, + $url_generator, + )) + ->getMock(); + // print_r(get_class_methods($socialPostListBuilder)); + $socialPostListBuilder->setProvider('providerName'); + $this->assertTrue(true); + // $header = array( + // 'social_id' => 'socialId', + // 'social_post_name' => 'socialPostName', + // 'user' => 123, + // ); + $this->assertTrue( + method_exists($socialPostListBuilder, 'createInstance'), + 'SocialPostListBuilder does not implements createInstance function/method' + ); + $this->assertTrue( + method_exists($socialPostListBuilder, 'setProvider'), + 'SocialPostListBuilder does not implements setProvider function/method' + ); + $this->assertTrue( + method_exists($socialPostListBuilder, 'buildHeader'), + 'SocialPostListBuilder does not implements buildHeader function/method' + ); + $this->assertTrue( + method_exists($socialPostListBuilder, 'buildRow'), + 'SocialPostListBuilder does not implements buildRow function/method' + ); + $this->assertTrue( + method_exists($socialPostListBuilder, 'getDefaultOperations'), + 'SocialPostListBuilder does not implements getDefaultOperations function/method' + ); + // entityinterface is called from core, maybe we need to call this: /social_post/sr/Entity/SocialPost + } + } From 2c8efda39b20ee206c225f797ffb4b1e58741481 Mon Sep 17 00:00:00 2001 From: neerajp99 Date: Sun, 16 Jun 2019 21:50:32 +0530 Subject: [PATCH 12/24] Edit tests for Controller --- tests/src/Unit/ControllerTest.php | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/tests/src/Unit/ControllerTest.php b/tests/src/Unit/ControllerTest.php index 9f4f707..c774278 100644 --- a/tests/src/Unit/ControllerTest.php +++ b/tests/src/Unit/ControllerTest.php @@ -12,34 +12,24 @@ */ class ControllerTest extends UnitTestCase { - /** - * Define __construct function. - */ - public function __construct() { - parent::__construct(); - } - - /** - * {@inheritdoc} - */ - public function setUp() { - parent::setUp(); - } - /** * Tests for class Network. */ public function testControllerBase() { $controllerBase = $this->getMockBuilder(ControllerBase::class) ->getMock(); + $listBuilder = $this->createMock(SocialPostListBuilder::class); + $controllerBase->method('buildList') ->with('facebook') ->will($this->returnValue($listBuilder->render())); + $this->assertTrue( method_exists($controllerBase, 'buildList'), 'ControllerBase does not implements buildList function/method' ); + $this->assertEquals($listBuilder->render(), $controllerBase->buildList('facebook')); } From 357cdd1a933b5a19a0df4c92fd3612081b40fb39 Mon Sep 17 00:00:00 2001 From: neerajp99 Date: Sun, 16 Jun 2019 21:51:08 +0530 Subject: [PATCH 13/24] Edit tests for Social Post Entity --- tests/src/Unit/EntityTest.php | 30 ++++++++---------------------- 1 file changed, 8 insertions(+), 22 deletions(-) diff --git a/tests/src/Unit/EntityTest.php b/tests/src/Unit/EntityTest.php index bf36615..482a1be 100644 --- a/tests/src/Unit/EntityTest.php +++ b/tests/src/Unit/EntityTest.php @@ -22,24 +22,11 @@ */ class EntityTest extends UnitTestCase { - /** - * Define __construct function. - */ - public function __construct() { - parent::__construct(); - } - - /** - * {@inheritdoc} - */ - public function setUp() { - parent::setUp(); - } - /** * Tests for class SocialPost. */ public function testSocialPost() { + $socialPost = $this->getMockBuilder(SocialPost::class) ->disableOriginalConstructor() ->getMock(); @@ -103,6 +90,7 @@ public function testSocialPostListBuilder() { $entity = $this->createMock(EntityInterface::class); $container = $this->createMock(ContainerInterface::class); $entity_type = $this->createMock(EntityTypeInterface::class); + $socialPostListBuilder = $this->getMockBuilder(SocialPostListBuilder::class) ->setConstructorArgs(array($entity_type, $storage, @@ -110,35 +98,33 @@ public function testSocialPostListBuilder() { $url_generator, )) ->getMock(); - // print_r(get_class_methods($socialPostListBuilder)); + $socialPostListBuilder->setProvider('providerName'); - $this->assertTrue(true); - // $header = array( - // 'social_id' => 'socialId', - // 'social_post_name' => 'socialPostName', - // 'user' => 123, - // ); + $this->assertTrue( method_exists($socialPostListBuilder, 'createInstance'), 'SocialPostListBuilder does not implements createInstance function/method' ); + $this->assertTrue( method_exists($socialPostListBuilder, 'setProvider'), 'SocialPostListBuilder does not implements setProvider function/method' ); + $this->assertTrue( method_exists($socialPostListBuilder, 'buildHeader'), 'SocialPostListBuilder does not implements buildHeader function/method' ); + $this->assertTrue( method_exists($socialPostListBuilder, 'buildRow'), 'SocialPostListBuilder does not implements buildRow function/method' ); + $this->assertTrue( method_exists($socialPostListBuilder, 'getDefaultOperations'), 'SocialPostListBuilder does not implements getDefaultOperations function/method' ); - // entityinterface is called from core, maybe we need to call this: /social_post/sr/Entity/SocialPost } } From e9c2521e46cad2bb37fc035a9d234557b2bb4b62 Mon Sep 17 00:00:00 2001 From: neerajp99 Date: Sun, 16 Jun 2019 22:20:17 +0530 Subject: [PATCH 14/24] Edit tests for Plugin class --- tests/src/Unit/PluginTest.php | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/tests/src/Unit/PluginTest.php b/tests/src/Unit/PluginTest.php index 1bf3f44..bcbe188 100644 --- a/tests/src/Unit/PluginTest.php +++ b/tests/src/Unit/PluginTest.php @@ -11,24 +11,11 @@ */ class NetworkTest extends UnitTestCase { - /** - * Define __construct function. - */ - public function __construct() { - parent::__construct(); - } - - /** - * {@inheritdoc} - */ - public function setUp() { - parent::setUp(); - } - /** * Tests for class Network. */ public function testSocialPostNetworkInterface() { + $socialPostNetworkInterface = $this->getMockBuilder(SocialPostNetworkInterface::class) ->getMock(); $this->assertTrue( From cc2348e1262eaa4de78890320b1b1511799beb10 Mon Sep 17 00:00:00 2001 From: neerajp99 Date: Sun, 16 Jun 2019 22:20:32 +0530 Subject: [PATCH 15/24] Edit tests for class SocialPostManager; --- tests/src/Unit/SocialPostManagerTest.php | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/tests/src/Unit/SocialPostManagerTest.php b/tests/src/Unit/SocialPostManagerTest.php index 3ab3069..1ce73cd 100644 --- a/tests/src/Unit/SocialPostManagerTest.php +++ b/tests/src/Unit/SocialPostManagerTest.php @@ -46,6 +46,7 @@ public function testSocialPostManager() { ->getMock(); $socialPostManager->setPluginId('drupal123'); + $socialPostManager->method('getPluginId') ->willReturn('drupal123'); @@ -55,8 +56,8 @@ public function testSocialPostManager() { $socialPostManager->method('getAccountsByUserId') ->with($plugin_id, $user_id) ->will($this->returnValue(array( - 'user_id' => $user_id, - 'plugin_id' => $plugin_id, + 'user_id' => 'drupaluser', + 'plugin_id' => 'drupal', ))); $socialPostManager->method('addRecord') @@ -72,14 +73,17 @@ public function testSocialPostManager() { method_exists($socialPostManager, 'setPluginId'), 'SocialPostManager does not implements setPluginId function/method' ); + $this->assertTrue( method_exists($socialPostManager, 'getPluginId'), 'SocialPostManager does not implements getPluginId function/method' ); + $this->assertTrue( method_exists($socialPostManager, 'getAccountsByUserId'), 'SocialPostManager does not implements getAccountsByUserId function/method' ); + $this->assertTrue( method_exists($socialPostManager, 'checkIfUserExists'), 'SocialPostManager does not implements checkIfUserExists function/method' @@ -88,18 +92,22 @@ public function testSocialPostManager() { method_exists($socialPostManager, 'getCurrentUser'), 'SocialPostManager does not implements getCurrentUser function/method' ); + $this->assertTrue( method_exists($socialPostManager, 'addRecord'), 'SocialPostManager does not implements addRecord function/method' ); + $this->assertTrue( method_exists($socialPostManager, 'setSessionKeysToNullify'), 'SocialPostManager does not implements setSessionKeysToNullify function/method' ); + $this->assertTrue( method_exists($socialPostManager, 'nullifySessionKeys'), 'SocialPostManager does not implements cnullifySessionKeys function/method' ); + $this->assertTrue( method_exists($socialPostManager, 'updateToken'), 'SocialPostManager does not implements updateToken function/method' @@ -108,6 +116,7 @@ public function testSocialPostManager() { method_exists($socialPostManager, 'getToken'), 'SocialPostManager does not implements getToken function/method' ); + $this->assertTrue( method_exists($socialPostManager, 'encryptToken'), 'SocialPostManager does not implements encryptToken function/method' @@ -116,10 +125,12 @@ public function testSocialPostManager() { method_exists($socialPostManager, 'decryptToken'), 'SocialPostManager does not implements decryptToken function/method' ); + $this->assertTrue( method_exists($socialPostManager, 'getSalt'), 'SocialPostManager does not implements getSalt function/method' ); + $this->assertEquals('drupal123', $socialPostManager->getPluginId()); $this->assertEquals(123, $socialPostManager->getCurrentUser()); $this->assertEquals(['user_id' => 'drupaluser', 'plugin_id' => 'drupal'], From 6caa6ddbded11628bcaa9a91c17f254d88b76fe1 Mon Sep 17 00:00:00 2001 From: neerajp99 Date: Sun, 16 Jun 2019 22:20:54 +0530 Subject: [PATCH 16/24] Edit tests for class UserAccessControlHandler --- tests/src/Unit/UserAccessControlHandlerTest.php | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/tests/src/Unit/UserAccessControlHandlerTest.php b/tests/src/Unit/UserAccessControlHandlerTest.php index a4d007a..4421302 100644 --- a/tests/src/Unit/UserAccessControlHandlerTest.php +++ b/tests/src/Unit/UserAccessControlHandlerTest.php @@ -15,20 +15,6 @@ */ class UserAccessControlHandlerTest extends UnitTestCase { - /** - * Define __construct function. - */ - public function __construct() { - parent::__construct(); - } - - /** - * {@inheritdoc} - */ - public function setUp() { - parent::setUp(); - } - /** * Tests for class UserAccessControlHandler. */ @@ -36,9 +22,11 @@ public function testUserAccessControlHandler() { $entity = $this->createMock(EntityInterface::class); $account = $this->createMock(AccountInterface::class); $entity_type = $this->createMock(EntityTypeInterface::class); + $collection = $this->getMockBuilder(EntityAccessControlHandler::class) ->setConstructorArgs(array($entity_type)) ->getMock(); + $userAccessControlHandler = $this->getMockBuilder(UserAccessControlHandler::class) ->setConstructorArgs(array($entity_type)) ->getMock(); @@ -52,6 +40,7 @@ public function testUserAccessControlHandler() { method_exists($userAccessControlHandler, 'checkAccess'), 'ControllerBase does not implements checkAccess function/method' ); + $this->assertTrue( method_exists($userAccessControlHandler, 'checkCreateAccess'), 'ControllerBase does not implements checkCreateAccess function/method' From adad325ed86f4789ca8d85be28902a9a0bfba79a Mon Sep 17 00:00:00 2001 From: neerajp99 Date: Sun, 16 Jun 2019 22:35:34 +0530 Subject: [PATCH 17/24] Fixed coding standard violations in Controller --- tests/src/Unit/ControllerTest.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/tests/src/Unit/ControllerTest.php b/tests/src/Unit/ControllerTest.php index c774278..a28cbc8 100644 --- a/tests/src/Unit/ControllerTest.php +++ b/tests/src/Unit/ControllerTest.php @@ -1,7 +1,6 @@ getMockBuilder(ControllerBase::class) - ->getMock(); + ->getMock(); $listBuilder = $this->createMock(SocialPostListBuilder::class); $controllerBase->method('buildList') - ->with('facebook') - ->will($this->returnValue($listBuilder->render())); + ->with('facebook') + ->will($this->returnValue($listBuilder->render())); $this->assertTrue( method_exists($controllerBase, 'buildList'), From b09a91321d773f9baf688f0e335c5abbe51b7a46 Mon Sep 17 00:00:00 2001 From: neerajp99 Date: Sun, 16 Jun 2019 22:37:34 +0530 Subject: [PATCH 18/24] Fixed coding standard violations in Social Post Entity --- tests/src/Unit/EntityTest.php | 44 +++++++++++++++-------------------- 1 file changed, 19 insertions(+), 25 deletions(-) diff --git a/tests/src/Unit/EntityTest.php b/tests/src/Unit/EntityTest.php index 482a1be..61ad087 100644 --- a/tests/src/Unit/EntityTest.php +++ b/tests/src/Unit/EntityTest.php @@ -1,17 +1,11 @@ getMockBuilder(SocialPost::class) - ->disableOriginalConstructor() - ->getMock(); + ->disableOriginalConstructor() + ->getMock(); $socialPost->expects($this->any()) - ->method('getProviderUserId') - ->willReturn('drupalUser'); + ->method('getProviderUserId') + ->willReturn('drupalUser'); $socialPost->expects($this->any()) - ->method('getPluginId') - ->willReturn('implementerName'); + ->method('getPluginId') + ->willReturn('implementerName'); $socialPost->expects($this->any()) - ->method('getName') - ->willReturn('providerName'); + ->method('getName') + ->willReturn('providerName'); $socialPost->expects($this->any()) - ->method('getId') - ->willReturn('providerId'); + ->method('getId') + ->willReturn('providerId'); $socialPost->expects($this->any()) - ->method('getUserId') - ->willReturn(123); + ->method('getUserId') + ->willReturn(123); $this->assertTrue( method_exists($socialPost, 'getProviderUserId'), @@ -80,7 +74,7 @@ public function testSocialPost() { } /** - * tests for class SocialPostListBuilder + * Tests for class SocialPostListBuilder. */ public function testSocialPostListBuilder() { $entity_type = $this->createMock(EntityTypeInterface::class); @@ -92,12 +86,12 @@ public function testSocialPostListBuilder() { $entity_type = $this->createMock(EntityTypeInterface::class); $socialPostListBuilder = $this->getMockBuilder(SocialPostListBuilder::class) - ->setConstructorArgs(array($entity_type, - $storage, - $user_entity, - $url_generator, - )) - ->getMock(); + ->setConstructorArgs([$entity_type, + $storage, + $user_entity, + $url_generator, + ]) + ->getMock(); $socialPostListBuilder->setProvider('providerName'); From 8ce0d59bde7ea446b9b7ecc98f954bfbae29919b Mon Sep 17 00:00:00 2001 From: neerajp99 Date: Sun, 16 Jun 2019 22:38:14 +0530 Subject: [PATCH 19/24] Fixed coding standard violations in Plugin Test class --- tests/src/Unit/PluginTest.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/src/Unit/PluginTest.php b/tests/src/Unit/PluginTest.php index bcbe188..697b37a 100644 --- a/tests/src/Unit/PluginTest.php +++ b/tests/src/Unit/PluginTest.php @@ -1,7 +1,6 @@ getMockBuilder(SocialPostNetworkInterface::class) - ->getMock(); + ->getMock(); $this->assertTrue( method_exists($socialPostNetworkInterface, 'post'), 'SocialPostNetworkInterface does not implements post function/method' From 9fcbf902b3399d29df33071122c476d1f14f9567 Mon Sep 17 00:00:00 2001 From: neerajp99 Date: Sun, 16 Jun 2019 22:44:38 +0530 Subject: [PATCH 20/24] Fixed Coding Standard Violations in class SocialPostManager --- tests/src/Unit/SocialPostManagerTest.php | 86 ++++++------------------ 1 file changed, 22 insertions(+), 64 deletions(-) diff --git a/tests/src/Unit/SocialPostManagerTest.php b/tests/src/Unit/SocialPostManagerTest.php index 1ce73cd..86b6eac 100644 --- a/tests/src/Unit/SocialPostManagerTest.php +++ b/tests/src/Unit/SocialPostManagerTest.php @@ -3,7 +3,6 @@ use Drupal\social_post\SocialPostManager; use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Session\AccountProxy; -use Drupal\Core\Site\Settings; use Drupal\social_post\SocialPostDataHandler; use Drupal\Tests\UnitTestCase; @@ -14,21 +13,6 @@ */ class SocialPostManagerTest extends UnitTestCase { - /** - * Define __construct function. - */ - public function __construct() { - parent::__construct(); - } - - /** - * {@inheritdoc} - */ - public function setUp() { - parent::setUp(); - $provider_user_id = 'drupaluser'; - } - /** * Tests for class UserAccessControlHandler. */ @@ -39,35 +23,35 @@ public function testSocialPostManager() { $current_user = $this->createMock(AccountProxy::class); $data_handler = $this->createMock(SocialPostDataHandler::class); $socialPostManager = $this->getMockBuilder(SocialPostManager::class) - ->setConstructorArgs(array($entity_type_manager, - $current_user, - $data_handler, - )) - ->getMock(); + ->setConstructorArgs([$entity_type_manager, + $current_user, + $data_handler, + ]) + ->getMock(); $socialPostManager->setPluginId('drupal123'); $socialPostManager->method('getPluginId') - ->willReturn('drupal123'); + ->willReturn('drupal123'); $socialPostManager->method('getCurrentUser') - ->willReturn(123); + ->willReturn(123); $socialPostManager->method('getAccountsByUserId') - ->with($plugin_id, $user_id) - ->will($this->returnValue(array( - 'user_id' => 'drupaluser', - 'plugin_id' => 'drupal', - ))); + ->with($plugin_id, $user_id) + ->will($this->returnValue([ + 'user_id' => 'drupaluser', + 'plugin_id' => 'drupal', + ])); $socialPostManager->method('addRecord') - ->with('drupaluser','drupal123', 'drupal', $additional_data = NULL) - ->will($this->returnValue(TRUE)); + ->with('drupaluser', 'drupal123', 'drupal', $additional_data = NULL) + ->will($this->returnValue(TRUE)); - $socialPostManager->setSessionKeysToNullify(array('drupal')); + $socialPostManager->setSessionKeysToNullify(['drupal']); $socialPostManager->method('getSalt') - ->willReturn('drupal3ab9'); + ->willReturn('drupal3ab9'); $this->assertTrue( method_exists($socialPostManager, 'setPluginId'), @@ -133,39 +117,13 @@ public function testSocialPostManager() { $this->assertEquals('drupal123', $socialPostManager->getPluginId()); $this->assertEquals(123, $socialPostManager->getCurrentUser()); - $this->assertEquals(['user_id' => 'drupaluser', 'plugin_id' => 'drupal'], - $socialPostManager->getAccountsByUserId($plugin_id, $user_id)); + $this->assertEquals([ + 'user_id' => 'drupaluser', + 'plugin_id' => 'drupal', + ], + $socialPostManager->getAccountsByUserId($plugin_id, $user_id)); $this->assertEquals('drupal3ab9', $socialPostManager->getSalt()); - $this->assertTrue($socialPostManager->addRecord('drupaluser','drupal123', 'drupal', $additional_data = NULL)); + $this->assertTrue($socialPostManager->addRecord('drupaluser', 'drupal123', 'drupal', $additional_data = NULL)); } - // public function testencryptToken($token = "drupal") { - // $entity_type_manager = $this->createMock(EntityTypeManagerInterface::class); - // $current_user = $this->createMock(AccountProxy::class); - // $data_handler = $this->createMock(SocialPostDataHandler::class); - // $socialPostManager = $this->getMockBuilder(SocialPostManager::class) - // ->setConstructorArgs(array($entity_type_manager, - // $current_user, - // $data_handler, - // )) - // ->getMock(); - // - // $socialPostManager->method('getSalt') - // ->willReturn('drupal3ab9'); - // $key = $socialPostManager->getSalt(); - // - // // Remove the base64 encoding from our key. - // $encryption_key = base64_decode($key); - // - // // Generate an initialization vector. - // $iv = openssl_random_pseudo_bytes(openssl_cipher_iv_length('aes-256-cbc')); - // - // // Encrypt the data using AES 256 encryption in CBC mode - // // using our encryption key and initialization vector. - // $encrypted = openssl_encrypt($token, 'aes-256-cbc', $encryption_key, 0, $iv); - // - // // The $iv is just as important as the key for decrypting, - // // so save it with our encrypted data using a unique separator (::). - // var_dump(base64_encode($encrypted . '::' . $iv)); - // } } From c8a9d04f74c1c57c0f7c63ba384d4cd62eead3b1 Mon Sep 17 00:00:00 2001 From: neerajp99 Date: Thu, 20 Jun 2019 02:17:55 +0530 Subject: [PATCH 21/24] Edit Social Post tests --- tests/src/Unit/ControllerTest.php | 6 ------ tests/src/Unit/EntityTest.php | 6 ++++++ tests/src/Unit/SocialPostManagerTest.php | 15 +++------------ tests/src/Unit/UserAccessControlHandlerTest.php | 5 ----- 4 files changed, 9 insertions(+), 23 deletions(-) diff --git a/tests/src/Unit/ControllerTest.php b/tests/src/Unit/ControllerTest.php index a28cbc8..0b58442 100644 --- a/tests/src/Unit/ControllerTest.php +++ b/tests/src/Unit/ControllerTest.php @@ -20,16 +20,10 @@ public function testControllerBase() { $listBuilder = $this->createMock(SocialPostListBuilder::class); - $controllerBase->method('buildList') - ->with('facebook') - ->will($this->returnValue($listBuilder->render())); - $this->assertTrue( method_exists($controllerBase, 'buildList'), 'ControllerBase does not implements buildList function/method' ); - - $this->assertEquals($listBuilder->render(), $controllerBase->buildList('facebook')); } } diff --git a/tests/src/Unit/EntityTest.php b/tests/src/Unit/EntityTest.php index 61ad087..77b79be 100644 --- a/tests/src/Unit/EntityTest.php +++ b/tests/src/Unit/EntityTest.php @@ -49,18 +49,22 @@ public function testSocialPost() { method_exists($socialPost, 'getProviderUserId'), 'SocialPost does not implements getProviderUserId function/method' ); + $this->assertTrue( method_exists($socialPost, 'getPluginId'), 'SocialPost does not implements getPluginId function/method' ); + $this->assertTrue( method_exists($socialPost, 'getName'), 'SocialPost does not implements getName function/method' ); + $this->assertTrue( method_exists($socialPost, 'getId'), 'SocialPost does not implements getId function/method' ); + $this->assertTrue( method_exists($socialPost, 'getUserId'), 'SocialPost does not implements getUserId function/method' @@ -91,9 +95,11 @@ public function testSocialPostListBuilder() { $user_entity, $url_generator, ]) + ->setMethods(null) ->getMock(); $socialPostListBuilder->setProvider('providerName'); + // var_dump($socialPostListBuilder->getDefaultOperations($entity)); $this->assertTrue( method_exists($socialPostListBuilder, 'createInstance'), diff --git a/tests/src/Unit/SocialPostManagerTest.php b/tests/src/Unit/SocialPostManagerTest.php index 86b6eac..cdbea8e 100644 --- a/tests/src/Unit/SocialPostManagerTest.php +++ b/tests/src/Unit/SocialPostManagerTest.php @@ -27,16 +27,11 @@ public function testSocialPostManager() { $current_user, $data_handler, ]) + ->setMethods(['getSalt', 'getAccountsByUserId']) ->getMock(); $socialPostManager->setPluginId('drupal123'); - $socialPostManager->method('getPluginId') - ->willReturn('drupal123'); - - $socialPostManager->method('getCurrentUser') - ->willReturn(123); - $socialPostManager->method('getAccountsByUserId') ->with($plugin_id, $user_id) ->will($this->returnValue([ @@ -44,10 +39,6 @@ public function testSocialPostManager() { 'plugin_id' => 'drupal', ])); - $socialPostManager->method('addRecord') - ->with('drupaluser', 'drupal123', 'drupal', $additional_data = NULL) - ->will($this->returnValue(TRUE)); - $socialPostManager->setSessionKeysToNullify(['drupal']); $socialPostManager->method('getSalt') @@ -116,14 +107,14 @@ public function testSocialPostManager() { ); $this->assertEquals('drupal123', $socialPostManager->getPluginId()); - $this->assertEquals(123, $socialPostManager->getCurrentUser()); + $this->assertEquals([ 'user_id' => 'drupaluser', 'plugin_id' => 'drupal', ], $socialPostManager->getAccountsByUserId($plugin_id, $user_id)); + $this->assertEquals('drupal3ab9', $socialPostManager->getSalt()); - $this->assertTrue($socialPostManager->addRecord('drupaluser', 'drupal123', 'drupal', $additional_data = NULL)); } } diff --git a/tests/src/Unit/UserAccessControlHandlerTest.php b/tests/src/Unit/UserAccessControlHandlerTest.php index 4421302..ff0a29d 100644 --- a/tests/src/Unit/UserAccessControlHandlerTest.php +++ b/tests/src/Unit/UserAccessControlHandlerTest.php @@ -31,11 +31,6 @@ public function testUserAccessControlHandler() { ->setConstructorArgs(array($entity_type)) ->getMock(); - // $userAccessControlHandler->checkAccess($entity, 'view', $account); - // $reflection = new ReflectionClass(UserAccessControlHandler::class); - // $method = $reflection->getMethod('checkAccess'); - // $method->setAccessible(true); - // return $method; $this->assertTrue( method_exists($userAccessControlHandler, 'checkAccess'), 'ControllerBase does not implements checkAccess function/method' From cf96baa36609c78586a9855773cd7f6d415be1a2 Mon Sep 17 00:00:00 2001 From: neerajp99 Date: Thu, 20 Jun 2019 02:25:41 +0530 Subject: [PATCH 22/24] Edit Social Post tests --- tests/src/Unit/SocialPostManagerTest.php | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/tests/src/Unit/SocialPostManagerTest.php b/tests/src/Unit/SocialPostManagerTest.php index cdbea8e..d2785b2 100644 --- a/tests/src/Unit/SocialPostManagerTest.php +++ b/tests/src/Unit/SocialPostManagerTest.php @@ -32,13 +32,6 @@ public function testSocialPostManager() { $socialPostManager->setPluginId('drupal123'); - $socialPostManager->method('getAccountsByUserId') - ->with($plugin_id, $user_id) - ->will($this->returnValue([ - 'user_id' => 'drupaluser', - 'plugin_id' => 'drupal', - ])); - $socialPostManager->setSessionKeysToNullify(['drupal']); $socialPostManager->method('getSalt') @@ -108,12 +101,6 @@ public function testSocialPostManager() { $this->assertEquals('drupal123', $socialPostManager->getPluginId()); - $this->assertEquals([ - 'user_id' => 'drupaluser', - 'plugin_id' => 'drupal', - ], - $socialPostManager->getAccountsByUserId($plugin_id, $user_id)); - $this->assertEquals('drupal3ab9', $socialPostManager->getSalt()); } From 7900bad938ab35e739755cab2a7ba5e268d45183 Mon Sep 17 00:00:00 2001 From: neerajp99 Date: Thu, 20 Jun 2019 02:26:49 +0530 Subject: [PATCH 23/24] Edit test for class SocialPostManager --- tests/src/Unit/SocialPostManagerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/src/Unit/SocialPostManagerTest.php b/tests/src/Unit/SocialPostManagerTest.php index d2785b2..f7f8950 100644 --- a/tests/src/Unit/SocialPostManagerTest.php +++ b/tests/src/Unit/SocialPostManagerTest.php @@ -27,7 +27,7 @@ public function testSocialPostManager() { $current_user, $data_handler, ]) - ->setMethods(['getSalt', 'getAccountsByUserId']) + ->setMethods(['getSalt']) ->getMock(); $socialPostManager->setPluginId('drupal123'); From 19273c2e469a99faabb7b96414cfcd7d29f74406 Mon Sep 17 00:00:00 2001 From: neerajp99 Date: Thu, 27 Jun 2019 04:31:13 -0700 Subject: [PATCH 24/24] Edit Encryption methods in Social Post --- social_post.post_update.php | 20 +++ src/Entity/SocialPost.php | 3 +- src/SocialPostManager.php | 10 +- tests/src/Unit/ControllerTest.php | 29 ---- tests/src/Unit/EntityTest.php | 130 ------------------ tests/src/Unit/PluginTest.php | 26 ---- tests/src/Unit/SocialPostManagerTest.php | 107 -------------- .../src/Unit/UserAccessControlHandlerTest.php | 45 ------ 8 files changed, 24 insertions(+), 346 deletions(-) create mode 100644 social_post.post_update.php delete mode 100644 tests/src/Unit/ControllerTest.php delete mode 100644 tests/src/Unit/EntityTest.php delete mode 100644 tests/src/Unit/PluginTest.php delete mode 100644 tests/src/Unit/SocialPostManagerTest.php delete mode 100644 tests/src/Unit/UserAccessControlHandlerTest.php diff --git a/social_post.post_update.php b/social_post.post_update.php new file mode 100644 index 0000000..b3b7a03 --- /dev/null +++ b/social_post.post_update.php @@ -0,0 +1,20 @@ +getStorage('social_post'); + + foreach($entity as $user) { + $token = $user->get('token'); + $user->setToken($token); + $user->save(); + $result = t('Token %nid saved', [ + '%nid' => $user + ->id(), + ]); + } + +} diff --git a/src/Entity/SocialPost.php b/src/Entity/SocialPost.php index 94c7e2b..2d95b96 100755 --- a/src/Entity/SocialPost.php +++ b/src/Entity/SocialPost.php @@ -7,6 +7,7 @@ use Drupal\Core\Entity\EntityTypeInterface; use Drupal\Core\Entity\ContentEntityInterface; use Drupal\Core\Entity\EntityChangedTrait; +use Drupal\social_api\Entity\SocialApi; /** * Defines the Social Post entity. @@ -37,7 +38,7 @@ * } * ) */ -class SocialPost extends ContentEntityBase implements ContentEntityInterface { +class SocialPost extends SocialApi implements ContentEntityInterface { use EntityChangedTrait; /** diff --git a/src/SocialPostManager.php b/src/SocialPostManager.php index 0195ea7..e3a48d9 100755 --- a/src/SocialPostManager.php +++ b/src/SocialPostManager.php @@ -183,6 +183,7 @@ public function addRecord($name, $provider_user_id, $token, $additional_data = N ]; $user_info = $this->entityTypeManager->getStorage('social_post')->create($values); + $user_info->setToken($token); // Save the entity. $user_info->save(); @@ -269,14 +270,7 @@ public function getToken($provider_user_id) { ]) ); - if (!$user_data) { - return FALSE; - } - else { - // Get token and decrypt it. - return $this->decryptToken($user_data->get('token')->getValue()[0]['value']); - } - + return $this->decryptToken($user_data->get('token')->getValue()[0]['value']); } /** diff --git a/tests/src/Unit/ControllerTest.php b/tests/src/Unit/ControllerTest.php deleted file mode 100644 index 0b58442..0000000 --- a/tests/src/Unit/ControllerTest.php +++ /dev/null @@ -1,29 +0,0 @@ -getMockBuilder(ControllerBase::class) - ->getMock(); - - $listBuilder = $this->createMock(SocialPostListBuilder::class); - - $this->assertTrue( - method_exists($controllerBase, 'buildList'), - 'ControllerBase does not implements buildList function/method' - ); - } - -} diff --git a/tests/src/Unit/EntityTest.php b/tests/src/Unit/EntityTest.php deleted file mode 100644 index 77b79be..0000000 --- a/tests/src/Unit/EntityTest.php +++ /dev/null @@ -1,130 +0,0 @@ -getMockBuilder(SocialPost::class) - ->disableOriginalConstructor() - ->getMock(); - - $socialPost->expects($this->any()) - ->method('getProviderUserId') - ->willReturn('drupalUser'); - - $socialPost->expects($this->any()) - ->method('getPluginId') - ->willReturn('implementerName'); - - $socialPost->expects($this->any()) - ->method('getName') - ->willReturn('providerName'); - - $socialPost->expects($this->any()) - ->method('getId') - ->willReturn('providerId'); - - $socialPost->expects($this->any()) - ->method('getUserId') - ->willReturn(123); - - $this->assertTrue( - method_exists($socialPost, 'getProviderUserId'), - 'SocialPost does not implements getProviderUserId function/method' - ); - - $this->assertTrue( - method_exists($socialPost, 'getPluginId'), - 'SocialPost does not implements getPluginId function/method' - ); - - $this->assertTrue( - method_exists($socialPost, 'getName'), - 'SocialPost does not implements getName function/method' - ); - - $this->assertTrue( - method_exists($socialPost, 'getId'), - 'SocialPost does not implements getId function/method' - ); - - $this->assertTrue( - method_exists($socialPost, 'getUserId'), - 'SocialPost does not implements getUserId function/method' - ); - - $this->assertSame('drupalUser', $socialPost->getProviderUserId()); - $this->assertSame('implementerName', $socialPost->getPluginId()); - $this->assertSame('providerName', $socialPost->getName()); - $this->assertSame('providerId', $socialPost->getId()); - $this->assertSame(123, $socialPost->getUserId()); - } - - /** - * Tests for class SocialPostListBuilder. - */ - public function testSocialPostListBuilder() { - $entity_type = $this->createMock(EntityTypeInterface::class); - $storage = $this->createMock(EntityStorageInterface::class); - $user_entity = $this->createMock(EntityStorageInterface::class); - $url_generator = $this->createMock(UrlGeneratorInterface::class); - $entity = $this->createMock(EntityInterface::class); - $container = $this->createMock(ContainerInterface::class); - $entity_type = $this->createMock(EntityTypeInterface::class); - - $socialPostListBuilder = $this->getMockBuilder(SocialPostListBuilder::class) - ->setConstructorArgs([$entity_type, - $storage, - $user_entity, - $url_generator, - ]) - ->setMethods(null) - ->getMock(); - - $socialPostListBuilder->setProvider('providerName'); - // var_dump($socialPostListBuilder->getDefaultOperations($entity)); - - $this->assertTrue( - method_exists($socialPostListBuilder, 'createInstance'), - 'SocialPostListBuilder does not implements createInstance function/method' - ); - - $this->assertTrue( - method_exists($socialPostListBuilder, 'setProvider'), - 'SocialPostListBuilder does not implements setProvider function/method' - ); - - $this->assertTrue( - method_exists($socialPostListBuilder, 'buildHeader'), - 'SocialPostListBuilder does not implements buildHeader function/method' - ); - - $this->assertTrue( - method_exists($socialPostListBuilder, 'buildRow'), - 'SocialPostListBuilder does not implements buildRow function/method' - ); - - $this->assertTrue( - method_exists($socialPostListBuilder, 'getDefaultOperations'), - 'SocialPostListBuilder does not implements getDefaultOperations function/method' - ); - } - -} diff --git a/tests/src/Unit/PluginTest.php b/tests/src/Unit/PluginTest.php deleted file mode 100644 index 697b37a..0000000 --- a/tests/src/Unit/PluginTest.php +++ /dev/null @@ -1,26 +0,0 @@ -getMockBuilder(SocialPostNetworkInterface::class) - ->getMock(); - $this->assertTrue( - method_exists($socialPostNetworkInterface, 'post'), - 'SocialPostNetworkInterface does not implements post function/method' - ); - } - -} diff --git a/tests/src/Unit/SocialPostManagerTest.php b/tests/src/Unit/SocialPostManagerTest.php deleted file mode 100644 index f7f8950..0000000 --- a/tests/src/Unit/SocialPostManagerTest.php +++ /dev/null @@ -1,107 +0,0 @@ -createMock(EntityTypeManagerInterface::class); - $current_user = $this->createMock(AccountProxy::class); - $data_handler = $this->createMock(SocialPostDataHandler::class); - $socialPostManager = $this->getMockBuilder(SocialPostManager::class) - ->setConstructorArgs([$entity_type_manager, - $current_user, - $data_handler, - ]) - ->setMethods(['getSalt']) - ->getMock(); - - $socialPostManager->setPluginId('drupal123'); - - $socialPostManager->setSessionKeysToNullify(['drupal']); - - $socialPostManager->method('getSalt') - ->willReturn('drupal3ab9'); - - $this->assertTrue( - method_exists($socialPostManager, 'setPluginId'), - 'SocialPostManager does not implements setPluginId function/method' - ); - - $this->assertTrue( - method_exists($socialPostManager, 'getPluginId'), - 'SocialPostManager does not implements getPluginId function/method' - ); - - $this->assertTrue( - method_exists($socialPostManager, 'getAccountsByUserId'), - 'SocialPostManager does not implements getAccountsByUserId function/method' - ); - - $this->assertTrue( - method_exists($socialPostManager, 'checkIfUserExists'), - 'SocialPostManager does not implements checkIfUserExists function/method' - ); - $this->assertTrue( - method_exists($socialPostManager, 'getCurrentUser'), - 'SocialPostManager does not implements getCurrentUser function/method' - ); - - $this->assertTrue( - method_exists($socialPostManager, 'addRecord'), - 'SocialPostManager does not implements addRecord function/method' - ); - - $this->assertTrue( - method_exists($socialPostManager, 'setSessionKeysToNullify'), - 'SocialPostManager does not implements setSessionKeysToNullify function/method' - ); - - $this->assertTrue( - method_exists($socialPostManager, 'nullifySessionKeys'), - 'SocialPostManager does not implements cnullifySessionKeys function/method' - ); - - $this->assertTrue( - method_exists($socialPostManager, 'updateToken'), - 'SocialPostManager does not implements updateToken function/method' - ); - $this->assertTrue( - method_exists($socialPostManager, 'getToken'), - 'SocialPostManager does not implements getToken function/method' - ); - - $this->assertTrue( - method_exists($socialPostManager, 'encryptToken'), - 'SocialPostManager does not implements encryptToken function/method' - ); - $this->assertTrue( - method_exists($socialPostManager, 'decryptToken'), - 'SocialPostManager does not implements decryptToken function/method' - ); - - $this->assertTrue( - method_exists($socialPostManager, 'getSalt'), - 'SocialPostManager does not implements getSalt function/method' - ); - - $this->assertEquals('drupal123', $socialPostManager->getPluginId()); - - $this->assertEquals('drupal3ab9', $socialPostManager->getSalt()); - } - -} diff --git a/tests/src/Unit/UserAccessControlHandlerTest.php b/tests/src/Unit/UserAccessControlHandlerTest.php deleted file mode 100644 index ff0a29d..0000000 --- a/tests/src/Unit/UserAccessControlHandlerTest.php +++ /dev/null @@ -1,45 +0,0 @@ -createMock(EntityInterface::class); - $account = $this->createMock(AccountInterface::class); - $entity_type = $this->createMock(EntityTypeInterface::class); - - $collection = $this->getMockBuilder(EntityAccessControlHandler::class) - ->setConstructorArgs(array($entity_type)) - ->getMock(); - - $userAccessControlHandler = $this->getMockBuilder(UserAccessControlHandler::class) - ->setConstructorArgs(array($entity_type)) - ->getMock(); - - $this->assertTrue( - method_exists($userAccessControlHandler, 'checkAccess'), - 'ControllerBase does not implements checkAccess function/method' - ); - - $this->assertTrue( - method_exists($userAccessControlHandler, 'checkCreateAccess'), - 'ControllerBase does not implements checkCreateAccess function/method' - ); - } - -}