-
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
Closed
Changes from 8 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,35 @@ | ||
| <?php | ||
|
|
||
| use Drupal\social_api\Annotation\Network; | ||
| use Drupal\Tests\UnitTestCase; | ||
|
|
||
| /** | ||
| * Defines a Social Network item annotation object. | ||
| * | ||
| * @Annotation | ||
| */ | ||
| class AnnotationTest extends UnitTestCase { | ||
|
|
||
| /** | ||
| * Define __construct function. | ||
| */ | ||
| public function __construct() { | ||
| parent::__construct(); | ||
| } | ||
|
|
||
| /** | ||
| * {@inheritdoc} | ||
| */ | ||
| public function setUp() { | ||
| parent::setUp(); | ||
| } | ||
|
|
||
| /** | ||
| * Tests for class Network. | ||
| */ | ||
| public function testNetwork() { | ||
| $network = $this->createMock(Network::class); | ||
| $this->assertInternalType('array', $network->handlers); | ||
| } | ||
|
|
||
| } | ||
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 AuthManagerTest extends UnitTestCase { | ||
|
|
||
| /** | ||
| * Define __construct function. | ||
| */ | ||
| public function __construct() { | ||
| parent::__construct(); | ||
| } | ||
|
|
||
| /** | ||
| * {@inheritdoc} | ||
| */ | ||
| public function setUp() { | ||
| parent::setUp(); | ||
| } | ||
|
|
||
| /** | ||
| * Tests for class Network. | ||
| */ | ||
| public function testOAuth2Manager() { | ||
neerajp99 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| $authManager = $this->getMockBuilder(OAuth2Manager::class) | ||
| ->getMockForAbstractClass(); | ||
| $this->assertTrue( | ||
| method_exists($authManager, 'setClient'), | ||
| 'OAuth2Manager does not implements setClient function/method' | ||
| ); | ||
| $this->assertTrue( | ||
| method_exists($authManager, 'getClient'), | ||
| 'OAuth2Manager does not implements getClient function/method' | ||
| ); | ||
| $this->assertTrue( | ||
| method_exists($authManager, 'setAccessToken'), | ||
| 'OAuth2Manager does not implements setAccessToken function/method' | ||
| ); | ||
| $this->assertTrue( | ||
| method_exists($authManager, 'getAccessToken'), | ||
| 'OAuth2Manager does not implements getAccessToken function/method' | ||
| ); | ||
| $authManager->setClient('drupal12345'); | ||
| $this->assertEquals('drupal12345', $authManager->getClient()); | ||
| $authManager->setAccessToken('drupal12345'); | ||
| $this->assertEquals('drupal12345', $authManager->getAccessToken()); | ||
| } | ||
|
|
||
| /** | ||
| * Tests for class Network. | ||
| */ | ||
| 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,55 @@ | ||
| <?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 ControllerTest extends UnitTestCase { | ||
|
||
|
|
||
| /** | ||
| * Define __construct function. | ||
| */ | ||
| public function __construct() { | ||
| parent::__construct(); | ||
| } | ||
|
|
||
| /** | ||
| * {@inheritdoc} | ||
| */ | ||
| public function setUp() { | ||
| parent::setUp(); | ||
| } | ||
|
|
||
| /** | ||
| * 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(array($namespaces, $cache_backend, $module_handler)) | ||
| ->getMock(); | ||
| $controller = $this->getMockBuilder(SocialApiController::class) | ||
| ->setConstructorArgs(array($networkManager)) | ||
| ->getMock(); | ||
| $this->assertTrue( | ||
| method_exists($controller, 'create'), | ||
| 'SocialApiController does not implements create function/method' | ||
| ); | ||
| $this->assertTrue( | ||
| method_exists($controller, 'integrations'), | ||
| 'SocialApiController 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,107 @@ | ||
| <?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; | ||
|
|
||
| /** | ||
| * Defines Social Network. | ||
| * | ||
| * @Annotation | ||
| */ | ||
| class PluginTest extends UnitTestCase { | ||
|
|
||
| /** | ||
| * Define __construct function. | ||
| */ | ||
| public function __construct() { | ||
| parent::__construct(); | ||
| } | ||
|
|
||
| /** | ||
| * {@inheritdoc} | ||
| */ | ||
| public function setUp() { | ||
| parent::setUp(); | ||
| } | ||
|
|
||
| /** | ||
| * 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(array($namespaces, $cache_backend, $module_handler)) | ||
| ->getMock(); | ||
| parent::__construct(); | ||
neerajp99 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| $this->assertTrue($networkManager instanceof NetworkManager); | ||
| $this->assertTrue( | ||
| method_exists($networkManager, 'setCacheBackend'), | ||
| 'NetworkManager does not implements setCacheBackend function/method' | ||
| ); | ||
| $this->assertTrue( | ||
| method_exists($networkManager, 'alterInfo'), | ||
| 'NetworkManager does not implements alterInfo function/method' | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Tests for class NetworkInterface. | ||
| */ | ||
| public function testNetworkInterface() { | ||
| $networkInterface = $this->createMock(NetworkInterface::class); | ||
| $this->assertTrue( | ||
| method_exists($networkInterface, 'authenticate'), | ||
| 'NetworkManager does not implements authenticate function/method' | ||
| ); | ||
| $this->assertTrue( | ||
| method_exists($networkInterface, 'getSdk'), | ||
| 'NetworkManager 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 = array(); | ||
| $plugin_definition = array(); | ||
|
|
||
| $networkBase = $this->getMockBuilder('Drupal\social_api\Plugin\NetworkBase') | ||
| ->setConstructorArgs(array($configuration, | ||
| 'drupal123', | ||
| $plugin_definition, | ||
| $entity_type_manager, | ||
| $config_factory, | ||
| )) | ||
| ->setMethods(['getSdk', 'create']) | ||
| ->getMockForAbstractClass(); | ||
| $this->assertTrue( | ||
| method_exists($networkBase, 'init'), | ||
| 'NetworkBase does not implements init function/method' | ||
| ); | ||
| $this->assertTrue( | ||
| method_exists($networkBase, 'create'), | ||
| 'NetworkBase does not implements create function/method' | ||
| ); | ||
| $this->assertTrue( | ||
| method_exists($networkBase, 'authenticate'), | ||
| 'NetworkBase does not implements authenticate function/method' | ||
| ); | ||
| $this->assertTrue( | ||
| method_exists($networkBase, 'getSdk'), | ||
| 'NetworkBase 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,64 @@ | ||
| <?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 SettingsTest extends UnitTestCase { | ||
|
|
||
| /** | ||
| * Define __construct function. | ||
| */ | ||
| public function __construct() { | ||
| parent::__construct(); | ||
| } | ||
|
|
||
| /** | ||
| * {@inheritdoc} | ||
| */ | ||
| public function setUp() { | ||
| parent::setUp(); | ||
| } | ||
|
|
||
| /** | ||
| * 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(array($config, | ||
| $storage, | ||
| $event_dispatcher, | ||
| $typed_config, | ||
| )) | ||
| ->getMock(); | ||
|
|
||
| $settingsBase = $this->getMockBuilder(SettingsBase::class) | ||
| ->setConstructorArgs(array($configs)) | ||
| ->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' | ||
| ); | ||
| $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.