EmbedButtonEditorAccessCheckTest.php in Embed 8
File
tests/src/Functional/EmbedButtonEditorAccessCheckTest.php
View source
<?php
namespace Drupal\Tests\embed\Functional;
use Drupal\editor\Entity\Editor;
use Drupal\Tests\system\Functional\Cache\AssertPageCacheContextsAndTagsTrait;
class EmbedButtonEditorAccessCheckTest extends EmbedTestBase {
use AssertPageCacheContextsAndTagsTrait;
const SUCCESS = 'Success!';
protected $defaultTheme = 'stark';
public function testEmbedButtonEditorAccessCheck() {
$this
->getRoute('plain_text', 'embed_test_default');
$this
->assertResponse(404);
$this
->assertCacheContext('route');
$this
->assertNoCacheTag('config:editor.editor.embed_test');
$this
->assertNoCacheTag('config:embed.button.embed_test_default');
$this
->getRoute('embed_test', 'embed_test_default');
$this
->assertResponse(403);
$this
->assertCacheContext('route');
$this
->assertNoCacheTag('config:editor.editor.embed_test');
$this
->assertNoCacheTag('config:embed.button.embed_test_default');
$this
->drupalLogin($this->webUser);
$this
->getRoute('plain_text', 'embed_test_default');
$this
->assertResponse(404);
$this
->assertCacheContext('route');
$this
->assertNoCacheTag('config:editor.editor.plain_text');
$this
->assertNoCacheTag('config:embed.button.embed_test_default');
$editor = Editor::create([
'format' => 'plain_text',
'editor' => 'ckeditor',
]);
$editor
->save();
$this
->getRoute('plain_text', 'embed_test_default');
$this
->assertResponse(403);
$this
->assertCacheContext('route');
$this
->assertCacheTag('config:editor.editor.plain_text');
$this
->assertCacheTag('config:embed.button.embed_test_default');
$this
->getRoute('embed_test', 'embed_test_default');
$this
->assertResponse(200);
$this
->assertCacheContext('route');
$this
->assertCacheTag('config:editor.editor.embed_test');
$this
->assertCacheTag('config:embed.button.embed_test_default');
$this
->assertText(static::SUCCESS);
$this
->getRoute('embed_test', 'embed_test_default', '');
$this
->assertResponse(404);
$this
->assertCacheContext('route');
$this
->assertCacheTag('config:editor.editor.embed_test');
$this
->assertCacheTag('config:embed.button.embed_test_default');
$this
->getRoute('invalid_editor', 'embed_test_default');
$this
->assertResponse(404);
$this
->assertCacheContext('route');
$this
->assertNoCacheTag('config:editor.editor.invalid_editor');
$this
->assertNoCacheTag('config:embed.button.embed_test_default');
$this
->getRoute('embed_test', 'invalid_button');
$this
->assertResponse(404);
$this
->assertCacheContext('route');
$this
->assertNoCacheTag('config:editor.editor.embed_test');
$this
->assertNoCacheTag('config:embed.button.invalid_button');
}
public function getRoute($editor_id, $embed_button_id, $value = NULL) {
$url = 'embed-test/access/' . $editor_id . '/' . $embed_button_id;
if (!isset($value)) {
$value = static::SUCCESS;
}
return $this
->drupalGet($url, [
'query' => [
'value' => $value,
],
]);
}
}