class AuthorizeFormTest in Salesforce Suite 8.3
@coversDefaultClass \Drupal\salesforce\Form\AuthorizeForm @group salesforce
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\salesforce\Unit\AuthorizeFormTest
Expanded class hierarchy of AuthorizeFormTest
File
- tests/
src/ Unit/ AuthorizeFormTest.php, line 23
Namespace
Drupal\Tests\salesforce\UnitView source
class AuthorizeFormTest extends UnitTestCase {
/**
* Set up for each test.
*/
public function setUp() {
parent::setUp();
$this->example_url = 'https://example.com';
$this->consumer_key = $this
->randomMachineName();
$this->config_factory = $this
->prophesize(ConfigFactoryInterface::class);
$this->state = $this
->prophesize(StateInterface::class);
$this->client = $this
->prophesize(RestClient::class);
$this->request_stack = $this
->prophesize(RequestStack::class);
$this->obpath = $this
->prophesize(OutboundPathProcessorInterface::class);
$this->logger = $this
->prophesize(LoggerChannelFactory::class);
$this->unrouted_url_assembler = new UnroutedUrlAssembler($this->request_stack
->reveal(), $this->obpath
->reveal());
$this->event_dispatcher = $this
->getMock('\\Symfony\\Component\\EventDispatcher\\EventDispatcherInterface');
$this->client
->getAuthCallbackUrl()
->willReturn($this->example_url);
$this->client
->getAuthEndpointUrl()
->willReturn($this->example_url);
$this->client
->getConsumerKey()
->willReturn($this->consumer_key);
$this->client
->setConsumerKey(Argument::any())
->willReturn(NULL);
$this->client
->setConsumerSecret(Argument::any())
->willReturn(NULL);
$this->client
->setLoginUrl(Argument::any())
->willReturn(NULL);
$container = new ContainerBuilder();
$container
->set('config.factory', $this->config_factory
->reveal());
$container
->set('salesforce.client', $this->client
->reveal());
$container
->set('state', $this->state
->reveal());
$container
->set('unrouted_url_assembler', $this->unrouted_url_assembler);
$container
->set('logger.factory', $this->logger
->reveal());
$container
->set('event_dispatcher', $this->event_dispatcher);
\Drupal::setContainer($container);
}
/**
* @covers ::submitForm
*/
public function testSubmitForm() {
$form_state = new FormState();
$form_state
->setValues([
'consumer_key' => $this->consumer_key,
'consumer_secret' => $this
->randomMachineName(),
'login_url' => $this->example_url,
]);
$form = AuthorizeForm::create(\Drupal::getContainer());
$form_array = [];
$form
->submitForm($form_array, $form_state);
/** @var \Drupal\Core\Routing\TrustedRedirectResponse $response */
$response = $form_state
->getResponse();
$this
->assertTrue($response instanceof TrustedRedirectResponse);
$this
->assertEquals($this->example_url . '?redirect_uri=' . urlencode($this->example_url) . '&response_type=code&client_id=' . $form_state
->getValue('consumer_key'), $response
->getTargetUrl());
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
AuthorizeFormTest:: |
public | function |
Set up for each test. Overrides UnitTestCase:: |
|
AuthorizeFormTest:: |
public | function | @covers ::submitForm | |
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. | |
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. |