ProviderBucketTest.php in oEmbed Providers 2.x
File
tests/src/Functional/ProviderBucketTest.php
View source
<?php
namespace Drupal\Tests\oembed_providers\Functional;
use Drupal\Tests\BrowserTestBase;
use Drupal\Tests\media\Traits\OEmbedTestTrait;
class ProviderBucketTest extends BrowserTestBase {
use OEmbedTestTrait;
protected $defaultTheme = 'stark';
protected $adminUser;
protected $nonAdminUser;
protected static $modules = [
'media',
'oembed_providers',
'oembed_providers_test',
];
protected function setUp() : void {
parent::setUp();
$this->adminUser = $this
->drupalCreateUser([
'access administration pages',
'administer oembed providers',
]);
$this->nonAdminUser = $this
->drupalCreateUser([
'access administration pages',
]);
}
public function testRoutePermissions() {
$assert_session = $this
->assertSession();
$this
->drupalLogin($this->nonAdminUser);
$this
->drupalGet('/admin/config/media/oembed-providers/buckets');
$assert_session
->statusCodeEquals(403);
$this
->drupalGet('/admin/config/media/oembed-providers/buckets/add');
$assert_session
->statusCodeEquals(403);
$this
->drupalGet('/admin/config/media/oembed-providers/buckets/test_bucket/edit');
$assert_session
->statusCodeEquals(403);
$this
->drupalGet('/admin/config/media/oembed-providers/buckets/test_bucket/delete');
$assert_session
->statusCodeEquals(403);
$this
->drupalLogin($this->adminUser);
$this
->drupalGet('/admin/config/media/oembed-providers/buckets');
$assert_session
->statusCodeEquals(200);
$this
->drupalGet('/admin/config/media/oembed-providers/buckets/add');
$assert_session
->statusCodeEquals(200);
$this
->drupalGet('/admin/config/media/oembed-providers/buckets/test_bucket/edit');
$assert_session
->statusCodeEquals(200);
$this
->drupalGet('/admin/config/media/oembed-providers/buckets/test_bucket/delete');
$assert_session
->statusCodeEquals(200);
}
public function testProviderBucketForm() {
$this
->useFixtureProviders();
$this
->lockHttpClientToFixtures();
$assert_session = $this
->assertSession();
$page = $this
->getSession()
->getPage();
$this
->drupalLogin($this->adminUser);
$this
->drupalGet('/admin/config/media/oembed-providers/buckets/add');
$page
->findField('label')
->setValue('My Test Bucket');
$page
->findField('id')
->setValue('my_test_bucket');
$page
->findField('description')
->setValue('A Description of My Test Bucket');
$page
->findField('providers[Vimeo]')
->check();
$page
->pressButton('Save');
$assert_session
->pageTextContains('The My Test Bucket oEmbed provider bucket was created.');
$this
->drupalGet('/admin/config/media/oembed-providers/buckets/my_test_bucket/edit');
$value = $page
->findField('label')
->getValue();
$this
->AssertSame($value, 'My Test Bucket');
$value = $page
->findField('id')
->getValue();
$this
->AssertSame($value, 'my_test_bucket');
$value = $page
->findField('description')
->getValue();
$this
->AssertSame($value, 'A Description of My Test Bucket');
$assert_session
->checkboxChecked('Vimeo');
$assert_session
->checkboxNotChecked('YouTube');
$media_sources = \Drupal::service('plugin.manager.media.source')
->getDefinitions();
$this
->assertArrayHasKey('oembed:my_test_bucket', $media_sources);
$this
->assertEquals($media_sources['oembed:my_test_bucket']['label'], 'My Test Bucket');
$this
->assertEquals($media_sources['oembed:my_test_bucket']['id'], 'my_test_bucket');
$this
->assertEquals($media_sources['oembed:my_test_bucket']['description'], 'A Description of My Test Bucket');
$providers = $media_sources['oembed:my_test_bucket']['providers'];
$this
->AssertTrue(in_array('Vimeo', $providers));
$this
->AssertFalse(in_array('YouTube', $providers));
}
}