b22350c8e4c20ce95f9e16edf6881c66ac6b54e3
[yaffs-website] / web / modules / contrib / metatag / src / Tests / MetatagCustomRouteTest.php
1 <?php
2
3 namespace Drupal\metatag\Tests;
4
5 use Drupal\entity_test\Entity\EntityTest;
6 use Drupal\metatag\Entity\MetatagDefaults;
7 use Drupal\simpletest\WebTestBase;
8
9 /**
10  * Tests custom route integration.
11  *
12  * @group metatag
13  *
14  * @see hook_metatag_route_entity()
15  */
16 class MetatagCustomRouteTest extends WebTestBase {
17
18   /**
19    * {@inheritdoc}
20    */
21   public static $modules = [
22     'node',
23     // Dependencies.
24     'token',
25     // Metatag itself.
26     'metatag',
27     // This module will be used to load a static page which will inherit the
28     // global defaults, without loading values from other configs.
29     'metatag_test_custom_route',
30     'entity_test',
31   ];
32
33   /**
34    * Run tests on the custom route.
35    */
36   public function testCustomRoute() {
37     $entity_test = EntityTest::create([
38       'name' => 'test name',
39       'type' => 'entity_test',
40     ]);
41     $entity_test->save();
42
43     MetatagDefaults::create([
44       'id' => 'entity_test__entity_test',
45       'tags' => [
46         'keywords' => 'test',
47       ],
48     ])->save();
49
50     $this->drupalGet('metatag_test_custom_route/' . $entity_test->id());
51     $this->assertResponse(200);
52     $xpath = $this->xpath("//meta[@name='keywords']");
53     $this->assertEqual(count($xpath), 1);
54     $this->assertEqual((string) $xpath[0]->attributes()['content'], 'test');
55   }
56
57 }