Skip to content
Closed
Show file tree
Hide file tree
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
Jun 1, 2019
a8c1413
add tests for social api
Jun 1, 2019
441bc4e
update composer.lock and vendor/
Jun 1, 2019
e724605
add tests for OAuth2ManagerInterface
Jun 2, 2019
ed4762a
add more tests for OAuth2Manager class
Jun 2, 2019
21b8802
edit authmanager test and add tests for class SocialApiHandler
Jun 2, 2019
faa2c41
add initial test for class Settings Base
Jun 2, 2019
f4e2080
complete test for class SettingsBase
Jun 4, 2019
68e3785
removed unwanted files
Jun 4, 2019
f9acbd2
remove composer.lock
Jun 4, 2019
2a52a34
edit class Auth2Manager test and add test for clas UserManagerInterfaces
Jun 4, 2019
6478638
add tests for class UserManager
Jun 4, 2019
18293df
Add tests for class UserAuthenticator
Jun 4, 2019
e70b1ed
Complete tests for class UserAuthenticator
Jun 4, 2019
40f9733
Add tests for class NetworkInterface, NewtworkManager and edit assert…
Jun 5, 2019
46d3e67
Add test for class Network Base
Jun 5, 2019
264e8e3
Delete old tests
Jun 10, 2019
bd0bfee
Add tests for Annotation
Jun 10, 2019
8630e8c
Add tests for AuthManager
Jun 10, 2019
67e0267
Add tests for Controller
Jun 10, 2019
69745ed
Add tests for Plugin
Jun 10, 2019
b08e678
Add tests for Settigns
Jun 10, 2019
684f591
Add tests for SocialApiDataHandler
Jun 10, 2019
60162d3
Add tests for User
Jun 10, 2019
004bc7d
Clean up the unit tests
Jun 16, 2019
fac7e90
Fix coding standard violarions
neerajp99 Jun 16, 2019
adb0555
Edit tests and fix coding violations
Jun 16, 2019
ffc81a4
fix coding standard violations in SocialApiException class
neerajp99 Jun 16, 2019
eed3c79
Rename the NetworkTest and edit AuthManager
Jun 16, 2019
31ef5de
Edit tests for Social API
Jun 18, 2019
e4a8f63
Edit tests
Jun 21, 2019
a301344
Rename tests
Jun 21, 2019
008b042
Add entity for Social API
Jun 25, 2019
c6d87fd
Remove Entity from 8.x-2.x branch
Jun 26, 2019
408573e
Modified tests for class SocialApiDataHandler.php;
Jul 1, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 91 additions & 0 deletions tests/src/Unit/SocialApiAuthManagerTest.php
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'
);
}

}
45 changes: 45 additions & 0 deletions tests/src/Unit/SocialApiControllerTest.php
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'
);
}

}
61 changes: 61 additions & 0 deletions tests/src/Unit/SocialApiDataHandlerTest.php
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));
}

}
28 changes: 28 additions & 0 deletions tests/src/Unit/SocialApiExceptionTest.php
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();
Copy link
Contributor

@gvso gvso Jun 20, 2019

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.

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);
}

}
101 changes: 101 additions & 0 deletions tests/src/Unit/SocialApiPluginTest.php
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'
);
}

}
56 changes: 56 additions & 0 deletions tests/src/Unit/SocialApiSettingsTest.php
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());
}

}
Loading