class SalesforceControllerTest in Salesforce Suite 8.3
@coversDefaultClass \Drupal\salesforce\Controller\SalesforceController @group salesforce
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\salesforce\Unit\SalesforceControllerTest
Expanded class hierarchy of SalesforceControllerTest
File
- tests/
src/ Unit/ SalesforceControllerTest.php, line 22
Namespace
Drupal\Tests\salesforce\UnitView source
class SalesforceControllerTest extends UnitTestCase {
/**
* Set up for each test.
*/
public function setUp() {
parent::setUp();
$this->example_url = 'https://example.com';
$this->httpClient = $this
->getMock('\\GuzzleHttp\\Client', [
'post',
]);
$this->httpClient
->expects($this
->once())
->method('post')
->willReturn(new Response());
$this->configFactory = $this
->getMockBuilder('\\Drupal\\Core\\Config\\ConfigFactory')
->disableOriginalConstructor()
->getMock();
$this->state = $this
->getMockBuilder('\\Drupal\\Core\\State\\State')
->disableOriginalConstructor()
->getMock();
$this->cache = $this
->getMock('\\Drupal\\Core\\Cache\\CacheBackendInterface');
$this->json = $this
->getMock(Json::CLASS);
$this->time = $this
->getMock(TimeInterface::CLASS);
$args = [
$this->httpClient,
$this->configFactory,
$this->state,
$this->cache,
$this->json,
$this->time,
];
$this->client = $this
->getMock(RestClient::class, [
'getConsumerKey',
'getConsumerSecret',
'getAuthCallbackUrl',
'getAuthTokenUrl',
'handleAuthResponse',
], $args);
$this->client
->expects($this
->once())
->method('getConsumerKey')
->willReturn($this
->randomMachineName());
$this->client
->expects($this
->once())
->method('getConsumerSecret')
->willReturn($this
->randomMachineName());
$this->client
->expects($this
->once())
->method('getAuthCallbackUrl')
->willReturn($this->example_url);
$this->client
->expects($this
->once())
->method('getAuthTokenUrl')
->willReturn($this->example_url);
$this->client
->expects($this
->once())
->method('handleAuthResponse')
->willReturn($this->client);
$this->request = new Request([
'code' => $this
->randomMachineName(),
]);
$this->request_stack = $this
->getMock(RequestStack::class);
$this->request_stack
->expects($this
->exactly(2))
->method('getCurrentRequest')
->willReturn($this->request);
$this->url_generator = $this
->prophesize(MetadataBubblingUrlGenerator::class);
$this->url_generator
->generateFromRoute('salesforce.authorize', [], [
"absolute" => TRUE,
], FALSE)
->willReturn('foo/bar');
$container = new ContainerBuilder();
$container
->set('salesforce.client', $this->client);
$container
->set('http_client', $this->httpClient);
$container
->set('request_stack', $this->request_stack);
$container
->set('url.generator', $this->url_generator
->reveal());
$container
->set('datetime.time', $this->time);
\Drupal::setContainer($container);
}
/**
* @covers ::oauthCallback
*/
public function testOauthCallback() {
$this->controller = $this
->getMock(SalesforceController::class, [
'successMessage',
], [
$this->client,
$this->httpClient,
$this->url_generator
->reveal(),
]);
$this->controller
->expects($this
->once())
->method('successMessage')
->willReturn(NULL);
$expected = new RedirectResponse('foo/bar');
$actual = $this->controller
->oauthCallback();
$this
->assertEquals($expected
->getTargetUrl(), $actual
->getTargetUrl());
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
PhpunitCompatibilityTrait:: |
public | function | Returns a mock object for the specified class using the available method. | |
PhpunitCompatibilityTrait:: |
public | function | Compatibility layer for PHPUnit 6 to support PHPUnit 4 code. | |
SalesforceControllerTest:: |
public | function |
Set up for each test. Overrides UnitTestCase:: |
|
SalesforceControllerTest:: |
public | function | @covers ::oauthCallback | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | 1 |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Mocks a block with a block plugin. | 1 |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
protected | function | Gets the random generator for the utility methods. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public | function | Generates a unique random string containing letters and numbers. |