You are here

public function CaptchaAdminTest::testCaptchaPointSettingGetterAndSetter in CAPTCHA 8

Test the CAPTCHA point setting getter/setter.

File

tests/src/Functional/CaptchaAdminTest.php, line 34

Class

CaptchaAdminTest
Tests CAPTCHA admin settings.

Namespace

Drupal\Tests\captcha\Functional

Code

public function testCaptchaPointSettingGetterAndSetter() {
  $comment_form_id = self::COMMENT_FORM_ID;
  captcha_set_form_id_setting($comment_form_id, 'test');

  /* @var CaptchaPoint $result */
  $result = captcha_get_form_id_setting($comment_form_id);
  $this
    ->assertNotNull($result, 'CAPTCHA exists', 'CAPTCHA');
  $this
    ->assertEquals($result
    ->getCaptchaType(), 'test', 'CAPTCHA type: default');
  $result = captcha_get_form_id_setting($comment_form_id, TRUE);
  $this
    ->assertNotNull($result, 'CAPTCHA exists', 'CAPTCHA');
  $this
    ->assertEquals($result, 'test', 'Setting and symbolic getting CAPTCHA point: "test"');

  // Set to 'default'.
  captcha_set_form_id_setting($comment_form_id, 'default');
  $this
    ->config('captcha.settings')
    ->set('default_challenge', 'foo/bar')
    ->save();
  $result = captcha_get_form_id_setting($comment_form_id);
  $this
    ->assertNotNull($result, 'CAPTCHA exists', 'CAPTCHA');
  $this
    ->assertEquals($result
    ->getCaptchaType(), 'foo/bar', 'Setting and getting CAPTCHA point: default');
  $result = captcha_get_form_id_setting($comment_form_id, TRUE);
  $this
    ->assertNotNull($result, 'Setting and symbolic getting CAPTCHA point: "default"');
  $this
    ->assertEquals($result, 'foo/bar', 'Setting and symbolic getting CAPTCHA point: default');

  // Set to 'baz/boo'.
  captcha_set_form_id_setting($comment_form_id, 'baz/boo');
  $result = captcha_get_form_id_setting($comment_form_id);
  $this
    ->assertNotNull($result, 'CAPTCHA exists', 'CAPTCHA');
  $this
    ->assertEquals($result
    ->getCaptchaType(), 'baz/boo', 'Setting and getting CAPTCHA point: baz/boo');
  $result = captcha_get_form_id_setting($comment_form_id, TRUE);
  $this
    ->assertEquals($result, 'baz/boo', 'Setting and symbolic getting CAPTCHA point: "baz/boo"');

  // Set to NULL (which should delete the CAPTCHA point setting entry).
  captcha_set_form_id_setting($comment_form_id, NULL);
  $result = captcha_get_form_id_setting($comment_form_id);
  $this
    ->assertNotNull($result, 'CAPTCHA exists', 'CAPTCHA');
  $this
    ->assertEquals($result
    ->getCaptchaType(), 'foo/bar', 'Setting and getting CAPTCHA point: NULL');
  $result = captcha_get_form_id_setting($comment_form_id, TRUE);
  $this
    ->assertNotNull($result, 'CAPTCHA exists', 'CAPTCHA');

  // Set with object.
  $captcha_type = 'baba/fofo';
  captcha_set_form_id_setting($comment_form_id, $captcha_type);
  $result = captcha_get_form_id_setting($comment_form_id);
  $this
    ->assertNotNull($result, 'Setting and getting CAPTCHA point: baba/fofo', 'CAPTCHA');

  // $this->assertEqual($result->module, 'baba', 'Setting and getting
  // CAPTCHA point: baba/fofo', 'CAPTCHA');.
  $this
    ->assertEquals($result
    ->getCaptchaType(), 'baba/fofo', 'Setting and getting CAPTCHA point: baba/fofo');
  $result = captcha_get_form_id_setting($comment_form_id, TRUE);
  $this
    ->assertEquals($result, 'baba/fofo', 'Setting and symbolic getting CAPTCHA point: "baba/fofo"');
}