You are here

class AuthorizeFormTest in Salesforce Suite 8.3

@coversDefaultClass \Drupal\salesforce\Form\AuthorizeForm @group salesforce

Hierarchy

Expanded class hierarchy of AuthorizeFormTest

File

tests/src/Unit/AuthorizeFormTest.php, line 23

Namespace

Drupal\Tests\salesforce\Unit
View 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

Namesort descending Modifiers Type Description Overrides
AuthorizeFormTest::setUp public function Set up for each test. Overrides UnitTestCase::setUp
AuthorizeFormTest::testSubmitForm public function @covers ::submitForm
PhpunitCompatibilityTrait::getMock Deprecated public function Returns a mock object for the specified class using the available method.
PhpunitCompatibilityTrait::setExpectedException Deprecated public function Compatibility layer for PHPUnit 6 to support PHPUnit 4 code.
UnitTestCase::$randomGenerator protected property The random generator.
UnitTestCase::$root protected property The app root. 1
UnitTestCase::assertArrayEquals protected function Asserts if two arrays are equal by sorting them first.
UnitTestCase::getBlockMockWithMachineName Deprecated protected function Mocks a block with a block plugin. 1
UnitTestCase::getClassResolverStub protected function Returns a stub class resolver.
UnitTestCase::getConfigFactoryStub public function Returns a stub config factory that behaves according to the passed array.
UnitTestCase::getConfigStorageStub public function Returns a stub config storage that returns the supplied configuration.
UnitTestCase::getContainerWithCacheTagsInvalidator protected function Sets up a container with a cache tags invalidator.
UnitTestCase::getRandomGenerator protected function Gets the random generator for the utility methods.
UnitTestCase::getStringTranslationStub public function Returns a stub translation manager that just returns the passed string.
UnitTestCase::randomMachineName public function Generates a unique random string containing letters and numbers.