Backup of db before drupal security update
[yaffs-website] / web / core / modules / taxonomy / tests / src / Functional / Views / TaxonomyDefaultArgumentTest.php
1 <?php
2
3 namespace Drupal\Tests\taxonomy\Functional\Views;
4
5 use Drupal\field\Entity\FieldConfig;
6 use Drupal\views\Views;
7 use Symfony\Component\HttpFoundation\Request;
8 use Symfony\Component\HttpKernel\HttpKernelInterface;
9
10 /**
11  * Tests the representative node relationship for terms.
12  *
13  * @group taxonomy
14  */
15 class TaxonomyDefaultArgumentTest extends TaxonomyTestBase {
16
17   /**
18    * Views used by this test.
19    *
20    * @var array
21    */
22   public static $testViews = ['taxonomy_default_argument_test'];
23
24   /**
25    * Tests the relationship.
26    */
27   public function testNodePath() {
28     $view = Views::getView('taxonomy_default_argument_test');
29
30     $request = Request::create($this->nodes[0]->url());
31     $request->server->set('SCRIPT_NAME', $GLOBALS['base_path'] . 'index.php');
32     $request->server->set('SCRIPT_FILENAME', 'index.php');
33
34     $response = $this->container->get('http_kernel')
35       ->handle($request, HttpKernelInterface::SUB_REQUEST);
36     $view->setRequest($request);
37     $view->setResponse($response);
38
39     $view->initHandlers();
40     $expected = implode(',', [$this->term1->id(), $this->term2->id()]);
41     $this->assertEqual($expected, $view->argument['tid']->getDefaultArgument());
42     $view->destroy();
43   }
44
45   public function testNodePathWithViewSelection() {
46     // Change the term entity reference field to use a view as selection plugin.
47     \Drupal::service('module_installer')->install(['entity_reference_test']);
48
49     $field_name = 'field_' . $this->vocabulary->id();
50     $field = FieldConfig::loadByName('node', 'article', $field_name);
51     $field->setSetting('handler', 'views');
52     $field->setSetting('handler_settings', [
53       'view' => [
54         'view_name' => 'test_entity_reference',
55         'display_name' => 'entity_reference_1',
56       ],
57     ]);
58     $field->save();
59
60     $view = Views::getView('taxonomy_default_argument_test');
61
62     $request = Request::create($this->nodes[0]->url());
63     $request->server->set('SCRIPT_NAME', $GLOBALS['base_path'] . 'index.php');
64     $request->server->set('SCRIPT_FILENAME', 'index.php');
65
66     $response = $this->container->get('http_kernel')->handle($request, HttpKernelInterface::SUB_REQUEST);
67     $view->setRequest($request);
68     $view->setResponse($response);
69
70     $view->initHandlers();
71     $expected = implode(',', [$this->term1->id(), $this->term2->id()]);
72     $this->assertEqual($expected, $view->argument['tid']->getDefaultArgument());
73   }
74
75   public function testTermPath() {
76     $view = Views::getView('taxonomy_default_argument_test');
77
78     $request = Request::create($this->term1->url());
79     $request->server->set('SCRIPT_NAME', $GLOBALS['base_path'] . 'index.php');
80     $request->server->set('SCRIPT_FILENAME', 'index.php');
81
82     $response = $this->container->get('http_kernel')->handle($request, HttpKernelInterface::SUB_REQUEST);
83     $view->setRequest($request);
84     $view->setResponse($response);
85     $view->initHandlers();
86
87     $expected = $this->term1->id();
88     $this->assertEqual($expected, $view->argument['tid']->getDefaultArgument());
89   }
90
91   /**
92    * Tests escaping of page title when the taxonomy plugin provides it.
93    */
94   public function testTermTitleEscaping() {
95     $this->term1->setName('<em>Markup</em>')->save();
96     $this->drupalGet('taxonomy_default_argument_test/' . $this->term1->id());
97     $this->assertEscaped($this->term1->label());
98   }
99
100 }