Yaffs site version 1.1
[yaffs-website] / web / modules / contrib / embed / src / Tests / PreviewTest.php
1 <?php
2
3 namespace Drupal\embed\Tests;
4
5 /**
6  * Tests the preview controller and route.
7  *
8  * @group embed
9  */
10 class PreviewTest extends EmbedTestBase {
11
12   const SUCCESS = 'Success!';
13
14   /**
15    * Tests the route used for generating preview of embedding entities.
16    */
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);
22
23     // The anonymous user should not have permission to use embed_test format.
24     $this->getRoute('embed_test');
25     $this->assertResponse(403);
26
27     // Now login a user that can use the embed_test format.
28     $this->drupalLogin($this->webUser);
29
30     $this->getRoute('plain_text');
31     $this->assertResponse(200);
32     $this->assertText(static::SUCCESS);
33
34     $this->getRoute('embed_test');
35     $this->assertResponse(200);
36     $this->assertText(static::SUCCESS);
37
38     // Test preview route with an empty request.
39     $this->getRoute('embed_test', '');
40     $this->assertResponse(404);
41
42     // Test preview route with an invalid text format.
43     $this->getRoute('invalid_format');
44     $this->assertResponse(404);
45   }
46
47   /**
48    * Performs a request to the embed.preview route.
49    *
50    * @param string $filter_format_id
51    *   ID of the filter format.
52    * @param string $value
53    *   The query string value to include.
54    *
55    * @return string
56    *   The retrieved HTML string.
57    */
58   public function getRoute($filter_format_id, $value = NULL) {
59     $url = 'embed/preview/' . $filter_format_id;
60     if (!isset($value)) {
61       $value = static::SUCCESS;
62     }
63     return $this->drupalGet($url, ['query' => ['value' => $value]]);
64   }
65
66 }