3 namespace Drupal\embed\Tests;
6 * Tests the preview controller and route.
10 class PreviewTest extends EmbedTestBase {
12 const SUCCESS = 'Success!';
15 * Tests the route used for generating preview of embedding entities.
17 public function testPreviewRoute() {
18 // Ensure the default filter can be previewed by the anonymous user.
19 $this->getRoute('plain_text');
20 $this->assertResponse(200);
21 $this->assertText(static::SUCCESS);
23 // The anonymous user should not have permission to use embed_test format.
24 $this->getRoute('embed_test');
25 $this->assertResponse(403);
27 // Now login a user that can use the embed_test format.
28 $this->drupalLogin($this->webUser);
30 $this->getRoute('plain_text');
31 $this->assertResponse(200);
32 $this->assertText(static::SUCCESS);
34 $this->getRoute('embed_test');
35 $this->assertResponse(200);
36 $this->assertText(static::SUCCESS);
38 // Test preview route with an empty request.
39 $this->getRoute('embed_test', '');
40 $this->assertResponse(404);
42 // Test preview route with an invalid text format.
43 $this->getRoute('invalid_format');
44 $this->assertResponse(404);
48 * Performs a request to the embed.preview route.
50 * @param string $filter_format_id
51 * ID of the filter format.
52 * @param string $value
53 * The query string value to include.
56 * The retrieved HTML string.
58 public function getRoute($filter_format_id, $value = NULL) {
59 $url = 'embed/preview/' . $filter_format_id;
61 $value = static::SUCCESS;
63 return $this->drupalGet($url, ['query' => ['value' => $value]]);