You are here

public function ExternalFetchTest::testExternalFetch in oEmbed Providers 1.1.x

Same name and namespace in other branches
  1. 2.x tests/src/Functional/ExternalFetchTest.php \Drupal\Tests\oembed_providers\Functional\ExternalFetchTest::testExternalFetch()
  2. 1.0.x tests/src/Functional/ExternalFetchTest.php \Drupal\Tests\oembed_providers\Functional\ExternalFetchTest::testExternalFetch()

Tests external fetch enabling and disabling.

File

tests/src/Functional/ExternalFetchTest.php, line 61

Class

ExternalFetchTest
Class ExternalFetchTest.

Namespace

Drupal\Tests\oembed_providers\Functional

Code

public function testExternalFetch() {
  $this
    ->useFixtureProviders();
  $this
    ->lockHttpClientToFixtures();
  $assert_session = $this
    ->assertSession();
  $page = $this
    ->getSession()
    ->getPage();
  $this
    ->drupalLogin($this->adminUser);
  $this
    ->drupalGet('/admin/config/media/oembed-providers');
  $assert_session
    ->checkboxChecked('Enable external fetch of providers');
  $page
    ->findField('external_fetch')
    ->uncheck();
  $page
    ->pressButton('Save configuration');
  $assert_session
    ->pageTextContains('The configuration options have been saved.');
  $this
    ->assertFalse(\Drupal::config('oembed_providers.settings')
    ->get('external_fetch'));

  // Verify externally-defined providers are not returned.
  $providers = \Drupal::service('media.oembed.provider_repository')
    ->getAll();
  $provider_names = [];
  foreach ($providers as $provider) {
    $provider_names[] = $provider
      ->getName();
  }
  $this
    ->assertTrue(in_array('UNL MediaHub', $provider_names), "UNL MediaHub is found as a provider");
  $this
    ->assertTrue(in_array('Example Provider', $provider_names), "Example Provider is found as a provider");
  $this
    ->assertFalse(in_array('Vimeo', $provider_names), "Vimeo is not found as a provider");
  $this
    ->assertFalse(in_array('YouTube', $provider_names), "YouTube is not found as a provider");
}