You are here

public function SettingsFormTest::testSettingsForm in oEmbed Providers 1.0.x

Same name and namespace in other branches
  1. 2.x tests/src/Functional/SettingsFormTest.php \Drupal\Tests\oembed_providers\Functional\SettingsFormTest::testSettingsForm()
  2. 1.1.x tests/src/Functional/SettingsFormTest.php \Drupal\Tests\oembed_providers\Functional\SettingsFormTest::testSettingsForm()

Tests settings form.

File

tests/src/Functional/SettingsFormTest.php, line 87

Class

SettingsFormTest
Class SettingsFormTest.

Namespace

Drupal\Tests\oembed_providers\Functional

Code

public function testSettingsForm() {
  $assert_session = $this
    ->assertSession();
  $page = $this
    ->getSession()
    ->getPage();

  // Set dummy value in cache, so it can be deleted on form submission.
  \Drupal::cache()
    ->set('oembed_providers:oembed_providers', 'test value', REQUEST_TIME + 86400);
  $this
    ->drupalLogin($this->adminUser);
  $this
    ->drupalGet('/admin/config/media/oembed-providers');
  $assert_session
    ->checkboxChecked('Enable external fetch of providers');
  $this
    ->assertSame('https://oembed.com/providers.json', $page
    ->findField('oembed_providers_url')
    ->getValue());
  $page
    ->findField('oembed_providers_url')
    ->setValue('https://example.com/providers.json');
  $page
    ->pressButton('Save configuration');
  $assert_session
    ->pageTextContains('The configuration options have been saved.');
  $this
    ->assertSame('https://example.com/providers.json', $this
    ->config('media.settings')
    ->get('oembed_providers_url'));

  // Verify cached providers are cleared.
  $this
    ->AssertFalse(\Drupal::cache()
    ->get('oembed_providers:oembed_providers'));
  $this
    ->drupalGet('/admin/config/media/oembed-providers');
  $assert_session
    ->checkboxChecked('Enable external fetch of providers');
  $this
    ->assertSame('https://example.com/providers.json', $page
    ->findField('oembed_providers_url')
    ->getValue());
  $page
    ->findField('external_fetch')
    ->uncheck();
  $page
    ->pressButton('Save configuration');
  $assert_session
    ->pageTextContains('The configuration options have been saved.');
  $this
    ->assertSame(FALSE, $this
    ->config('oembed_providers.settings')
    ->get('external_fetch'));
  $this
    ->drupalGet('/admin/config/media/oembed-providers');
  $assert_session
    ->checkboxNotChecked('Enable external fetch of providers');
}