You are here

public function FormBuilderTest::testInvalidToken in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/tests/Drupal/Tests/Core/Form/FormBuilderTest.php \Drupal\Tests\Core\Form\FormBuilderTest::testInvalidToken()

@covers ::doBuildForm

@dataProvider providerTestInvalidToken

File

core/tests/Drupal/Tests/Core/Form/FormBuilderTest.php, line 776
Contains \Drupal\Tests\Core\Form\FormBuilderTest.

Class

FormBuilderTest
@coversDefaultClass \Drupal\Core\Form\FormBuilder @group Form

Namespace

Drupal\Tests\Core\Form

Code

public function testInvalidToken($expected, $valid_token, $user_is_authenticated) {
  $form_token = 'the_form_token';
  $form_id = 'test_form_id';
  if (is_bool($valid_token)) {
    $this->csrfToken
      ->expects($this
      ->any())
      ->method('get')
      ->willReturnArgument(0);
    $this->csrfToken
      ->expects($this
      ->atLeastOnce())
      ->method('validate')
      ->willReturn($valid_token);
  }
  $current_user = $this
    ->prophesize(AccountInterface::class);
  $current_user
    ->isAuthenticated()
    ->willReturn($user_is_authenticated);
  $property = new \ReflectionProperty(FormBuilder::class, 'currentUser');
  $property
    ->setAccessible(TRUE);
  $property
    ->setValue($this->formBuilder, $current_user
    ->reveal());
  $expected_form = $form_id();
  $form_arg = $this
    ->getMockForm($form_id, $expected_form);
  $form_state = new FormState();
  $input['form_id'] = $form_id;
  $input['form_token'] = $form_token;
  $form_state
    ->setUserInput($input);
  $this
    ->simulateFormSubmission($form_id, $form_arg, $form_state, FALSE);
  $this
    ->assertSame($expected, $form_state
    ->hasInvalidToken());
}