-
Notifications
You must be signed in to change notification settings - Fork 6
add phpunit setup and initial tests for social api #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
+510
−0
Closed
Changes from all commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
e288cb3
add composer.json with phpunit
a8c1413
add tests for social api
441bc4e
update composer.lock and vendor/
e724605
add tests for OAuth2ManagerInterface
ed4762a
add more tests for OAuth2Manager class
21b8802
edit authmanager test and add tests for class SocialApiHandler
faa2c41
add initial test for class Settings Base
f4e2080
complete test for class SettingsBase
68e3785
removed unwanted files
f9acbd2
remove composer.lock
2a52a34
edit class Auth2Manager test and add test for clas UserManagerInterfaces
6478638
add tests for class UserManager
18293df
Add tests for class UserAuthenticator
e70b1ed
Complete tests for class UserAuthenticator
40f9733
Add tests for class NetworkInterface, NewtworkManager and edit assert…
46d3e67
Add test for class Network Base
264e8e3
Delete old tests
bd0bfee
Add tests for Annotation
8630e8c
Add tests for AuthManager
67e0267
Add tests for Controller
69745ed
Add tests for Plugin
b08e678
Add tests for Settigns
684f591
Add tests for SocialApiDataHandler
60162d3
Add tests for User
004bc7d
Clean up the unit tests
fac7e90
Fix coding standard violarions
neerajp99 adb0555
Edit tests and fix coding violations
ffc81a4
fix coding standard violations in SocialApiException class
neerajp99 eed3c79
Rename the NetworkTest and edit AuthManager
31ef5de
Edit tests for Social API
e4a8f63
Edit tests
a301344
Rename tests
008b042
Add entity for Social API
c6d87fd
Remove Entity from 8.x-2.x branch
408573e
Modified tests for class SocialApiDataHandler.php;
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| <?php | ||
|
|
||
| use Drupal\social_api\AuthManager\OAuth2Manager; | ||
| use Drupal\social_api\AuthManager\OAuth2ManagerInterface; | ||
| use Drupal\Tests\UnitTestCase; | ||
|
|
||
| /** | ||
| * Defines OAuth2Manager. | ||
| * | ||
| * @Annotation | ||
| */ | ||
| class SocialApiAuthManagerTest extends UnitTestCase { | ||
|
|
||
| /** | ||
| * Tests for class OAuth2Manager. | ||
| */ | ||
| public function testOAuth2Manager() { | ||
| $authManager = $this->getMockBuilder(OAuth2Manager::class) | ||
| ->getMockForAbstractClass(); | ||
|
|
||
| $this->assertTrue( | ||
| method_exists($authManager, 'setClient'), | ||
| 'OAuth2Manager class does not implements setClient function/method' | ||
| ); | ||
|
|
||
| $this->assertTrue( | ||
| method_exists($authManager, 'getClient'), | ||
| 'OAuth2Manager class does not implements getClient function/method' | ||
| ); | ||
|
|
||
| $this->assertTrue( | ||
| method_exists($authManager, 'setAccessToken'), | ||
| 'OAuth2Manager class does not implements setAccessToken function/method' | ||
| ); | ||
|
|
||
| $this->assertTrue( | ||
| method_exists($authManager, 'getAccessToken'), | ||
| 'OAuth2Manager class does not implements getAccessToken function/method' | ||
| ); | ||
|
|
||
| $authManager->setClient('drupal12345'); | ||
|
|
||
| $authManager->setAccessToken('drupal12345'); | ||
|
|
||
| $this->assertEquals('drupal12345', $authManager->getClient()); | ||
| $this->assertEquals('drupal12345', $authManager->getAccessToken()); | ||
| } | ||
|
|
||
| /** | ||
| * Tests for class OAuth2ManagerInterface. | ||
| */ | ||
| public function testOAuth2ManagerInterface() { | ||
| $authManagerInterface = $this->createMock(OAuth2ManagerInterface::class); | ||
|
|
||
| $this->assertTrue( | ||
| method_exists($authManagerInterface, 'setClient'), | ||
| 'OAuth2ManagerInterface does not have setClient function/method' | ||
| ); | ||
|
|
||
| $this->assertTrue( | ||
| method_exists($authManagerInterface, 'getClient'), | ||
| 'OAuth2ManagerInterface does not have getClient function/method' | ||
| ); | ||
|
|
||
| $this->assertTrue( | ||
| method_exists($authManagerInterface, 'getAccessToken'), | ||
| 'OAuth2ManagerInterface does not have getAccessToken function/method' | ||
| ); | ||
|
|
||
| $this->assertTrue( | ||
| method_exists($authManagerInterface, 'setAccessToken'), | ||
| 'OAuth2ManagerInterface does not have setAccessToken function/method' | ||
| ); | ||
|
|
||
| $this->assertTrue( | ||
| method_exists($authManagerInterface, 'getAuthorizationUrl'), | ||
| 'OAuth2ManagerInterface does not have getAuthorizationUrl function/method' | ||
| ); | ||
|
|
||
| $this->assertTrue( | ||
| method_exists($authManagerInterface, 'getState'), | ||
| 'OAuth2ManagerInterface does not have getState function/method' | ||
| ); | ||
|
|
||
| $this->assertTrue( | ||
| method_exists($authManagerInterface, 'getUserInfo'), | ||
| 'OAuth2ManagerInterface does not have getUserInfo function/method' | ||
| ); | ||
| } | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| <?php | ||
|
|
||
| use Drupal\social_api\Controller\SocialApiController; | ||
| use Symfony\Component\DependencyInjection\ContainerInterface; | ||
| use Drupal\social_api\Plugin\NetworkManager; | ||
| use Drupal\Core\Cache\CacheBackendInterface; | ||
| use Drupal\Core\Extension\ModuleHandlerInterface; | ||
| use Drupal\Tests\UnitTestCase; | ||
|
|
||
| /** | ||
| * Defines Controller. | ||
| * | ||
| * @Annotation | ||
| */ | ||
| class SocialApiControllerTest extends UnitTestCase { | ||
|
|
||
| /** | ||
| * Tests for class SocialApiController. | ||
| */ | ||
| public function testSocialApiController() { | ||
| $namespaces = $this->createMock(Traversable::class); | ||
| $cache_backend = $this->createMock(CacheBackendInterface::class); | ||
| $module_handler = $this->createMock(ModuleHandlerInterface::class); | ||
| $container = $this->createMock(ContainerInterface::class); | ||
|
|
||
| $networkManager = $this->getMockBuilder(NetworkManager::class) | ||
| ->setConstructorArgs([$namespaces, $cache_backend, $module_handler]) | ||
| ->getMock(); | ||
|
|
||
| $controller = $this->getMockBuilder(SocialApiController::class) | ||
| ->setConstructorArgs([$networkManager]) | ||
| ->setMethods(null) | ||
| ->getMock(); | ||
|
|
||
| $this->assertTrue( | ||
| method_exists($controller, 'create'), | ||
| 'SocialApiController class does not implements create function/method' | ||
| ); | ||
| $this->assertTrue( | ||
| method_exists($controller, 'integrations'), | ||
| 'SocialApiController class does not implements integrations function/method' | ||
| ); | ||
| } | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| <?php | ||
|
|
||
| use Drupal\social_api\SocialApiDataHandler; | ||
| use Symfony\Component\HttpFoundation\Session\SessionInterface; | ||
| use Drupal\Tests\UnitTestCase; | ||
|
|
||
| /** | ||
| * Defines SocialApiDataHandler class. | ||
| * | ||
| * @Annotation | ||
| */ | ||
| class SocialApiDataHandlerTest extends UnitTestCase { | ||
|
|
||
| /** | ||
| * Interface for the session. | ||
| * | ||
| * @var \Symfony\Component\HttpFoundation\Session\SessionInterface | ||
| */ | ||
| protected $session; | ||
|
|
||
| /** | ||
| * Variables are written to and read from session via this class. | ||
| * | ||
| * @var \Drupal\social_api\SocialApiDataHandler | ||
| */ | ||
| protected $socialApiDataHandler; | ||
|
|
||
| /** | ||
| * {@inheritdoc} | ||
| */ | ||
| public function setUp() { | ||
| parent::setUp(); | ||
|
|
||
| $this->session = $this->getMock(SessionInterface::class); | ||
|
|
||
| $this->socialApiDataHandler = $this->getMockBuilder(SocialApiDataHandler::class) | ||
| ->setConstructorArgs([$this->session]) | ||
| ->setMethods(NULL) | ||
| ->getMockForAbstractClass(); | ||
| } | ||
|
|
||
| /** | ||
| * Tests for class SocialApiDataHandler. | ||
| */ | ||
| public function testSocialApiDataHandler() { | ||
| $key = "drupal"; | ||
| $value = "drupal123"; | ||
|
|
||
| $this->socialApiDataHandler->set($key, $value); | ||
|
|
||
| $this->socialApiDataHandler->setSessionPrefix('1234'); | ||
|
|
||
| $this->session->expects($this->any()) | ||
| ->method('get') | ||
| ->willReturn($this->socialApiDataHandler->getSessionPrefix() . $key); | ||
|
|
||
| $this->assertEquals('1234_', $this->socialApiDataHandler->getSessionPrefix()); | ||
| $this->assertEquals('1234_drupal', $this->socialApiDataHandler->get($key)); | ||
| } | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| <?php | ||
|
|
||
| use Drupal\Tests\UnitTestCase; | ||
| use Drupal\social_api\SocialApiException; | ||
|
|
||
| /** | ||
| * Defines class for SocialApiExcetion Test. | ||
| */ | ||
| class SocialApiExceptionTest extends UnitTestCase { | ||
|
|
||
| /** | ||
| * Tests for class SocialApiException. | ||
| */ | ||
| public function testException() { | ||
| $socialApiException = new SocialApiException(); | ||
| try { | ||
| if (!$socialApiException) { | ||
| throw new Exception(); | ||
| } | ||
| } | ||
| catch (\Exception $e) { | ||
| echo 'Message: ' . $e; | ||
| } | ||
| // We need some assertion here otherwise the test will show a warning. | ||
| $this->assertTrue($socialApiException instanceof SocialApiException); | ||
| } | ||
|
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| <?php | ||
|
|
||
| use Drupal\social_api\Plugin\NetworkManager; | ||
| use Drupal\Core\Cache\CacheBackendInterface; | ||
| use Drupal\Core\Extension\ModuleHandlerInterface; | ||
| use Drupal\social_api\Plugin\NetworkInterface; | ||
| use Drupal\Core\Config\ConfigFactoryInterface; | ||
| use Drupal\Core\Entity\EntityTypeManagerInterface; | ||
| use Symfony\Component\DependencyInjection\ContainerInterface; | ||
| use Drupal\Tests\UnitTestCase; | ||
| use Drupal\social_api\Plugin\NetworkBase; | ||
|
|
||
| /** | ||
| * Defines Social Network. | ||
| * | ||
| * @Annotation | ||
| */ | ||
| class SocialApiPluginTest extends UnitTestCase { | ||
|
|
||
| /** | ||
| * Tests for class NetworkManager. | ||
| */ | ||
| public function testNetworkManager() { | ||
| $namespaces = $this->createMock(Traversable::class); | ||
| $cache_backend = $this->createMock(CacheBackendInterface::class); | ||
| $module_handler = $this->createMock(ModuleHandlerInterface::class); | ||
|
|
||
| $networkManager = $this->getMockBuilder(NetworkManager::class) | ||
| ->setConstructorArgs([$namespaces, $cache_backend, $module_handler]) | ||
| ->setMethods(null) | ||
| ->getMock(); | ||
|
|
||
| $this->assertTrue( | ||
| method_exists($networkManager, 'setCacheBackend'), | ||
| 'NetworkManager class does not implements setCacheBackend function/method' | ||
| ); | ||
|
|
||
| $this->assertTrue( | ||
| method_exists($networkManager, 'alterInfo'), | ||
| 'NetworkManager class does not implements alterInfo function/method' | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Tests for class NetworkInterface. | ||
| */ | ||
| public function testNetworkInterface() { | ||
| $networkInterface = $this->createMock(NetworkInterface::class); | ||
|
|
||
| $this->assertTrue( | ||
| method_exists($networkInterface, 'authenticate'), | ||
| 'NetworkManagerInterface class does not implements authenticate function/method' | ||
| ); | ||
|
|
||
| $this->assertTrue( | ||
| method_exists($networkInterface, 'getSdk'), | ||
| 'NetworkManagerInterface class does not implements getSdk function/method' | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Tests for class NetworkBase. | ||
| */ | ||
| public function testNetworkBase() { | ||
| $entity_type_manager = $this->createMock(EntityTypeManagerInterface::class); | ||
| $config_factory = $this->createMock(ConfigFactoryInterface::class); | ||
| $container = $this->createMock(ContainerInterface::class); | ||
| $configuration = []; | ||
| $plugin_definition = []; | ||
|
|
||
| $networkBase = $this->getMockBuilder(NetworkBase::class) | ||
| ->setConstructorArgs([$configuration, | ||
| 'drupal123', | ||
| $plugin_definition, | ||
| $entity_type_manager, | ||
| $config_factory, | ||
| ]) | ||
| ->getMockForAbstractClass(); | ||
|
|
||
| $this->assertTrue( | ||
| method_exists($networkBase, 'init'), | ||
| 'NetworkBase class does not implements init function/method' | ||
| ); | ||
|
|
||
| $this->assertTrue( | ||
| method_exists($networkBase, 'create'), | ||
| 'NetworkBase class does not implements create function/method' | ||
| ); | ||
|
|
||
| $this->assertTrue( | ||
| method_exists($networkBase, 'authenticate'), | ||
| 'NetworkBase class does not implements authenticate function/method' | ||
| ); | ||
|
|
||
| $this->assertTrue( | ||
| method_exists($networkBase, 'getSdk'), | ||
| 'NetworkBase class does not implements getSdk function/method' | ||
| ); | ||
| } | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| <?php | ||
|
|
||
| use Drupal\social_api\Settings\SettingsBase; | ||
| use Symfony\Component\EventDispatcher\EventDispatcherInterface; | ||
| use Drupal\Core\Config\StorageInterface; | ||
| use Drupal\Core\Config\TypedConfigManagerInterface; | ||
| use Drupal\Tests\UnitTestCase; | ||
|
|
||
| /** | ||
| * Defines Settings Class. | ||
| * | ||
| * @Annotation | ||
| */ | ||
| class SocialApiSettingsTest extends UnitTestCase { | ||
|
|
||
| /** | ||
| * Tests for class Settings. | ||
| */ | ||
| public function testSettingsBase() { | ||
| $config = $this->getMockBuilder('Drupal\Core\Config\Config') | ||
| ->disableOriginalConstructor() | ||
| ->getMock(); | ||
|
|
||
| $storage = $this->createMock(StorageInterface::class); | ||
| $event_dispatcher = $this->createMock(EventDispatcherInterface::class); | ||
| $typed_config = $this->createMock(TypedConfigManagerInterface::class); | ||
|
|
||
| $configs = $this->getMockBuilder('Drupal\Core\Config\ImmutableConfig') | ||
| ->setConstructorArgs([$config, | ||
| $storage, | ||
| $event_dispatcher, | ||
| $typed_config, | ||
| ]) | ||
| ->getMock(); | ||
|
|
||
| $settingsBase = $this->getMockBuilder(SettingsBase::class) | ||
| ->setConstructorArgs([$configs]) | ||
| ->setMethods(null) | ||
| ->getMockForAbstractClass(); | ||
|
|
||
| $this->assertTrue( | ||
| method_exists($settingsBase, 'getConfig'), | ||
| 'SettingsBase does not implements getConfig function/method' | ||
| ); | ||
|
|
||
| $this->assertTrue( | ||
| method_exists($settingsBase, 'factory'), | ||
| 'SettingsBase does not implements factory function/method' | ||
| ); | ||
|
|
||
| $this->assertNotNull($settingsBase->factory($configs)); | ||
|
|
||
| $this->assertEquals($configs, $settingsBase->getConfig()); | ||
| } | ||
|
|
||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test does not make sense. If you want to test this class, just test that the message is set correctly, etc.