You are here

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

Same name and namespace in other branches
  1. 1.0.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 89

Class

SettingsFormTest
Tests the global settings form.

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');

  // Verify form validation.
  $this
    ->drupalGet('/admin/config/media/oembed-providers');
  $page
    ->findField('external_fetch')
    ->check();
  $page
    ->findField('oembed_providers_url')
    ->setValue('');
  $page
    ->pressButton('Save configuration');
  $assert_session
    ->pageTextContains('The oEmbed Providers URL field is required.');
}