UrlIntegrationTest.php 4.22 KB
Newer Older
1
2
<?php

3
namespace Drupal\Tests\facets\Functional;
4

5
use Drupal\Core\Url;
6
use Drupal\facets\FacetInterface;
7
8
use Drupal\facets\Entity\Facet;
use Drupal\facets\FacetSourceInterface;
9
10
11
12
13
14

/**
 * Tests the overall functionality of the Facets admin UI.
 *
 * @group facets
 */
15
class UrlIntegrationTest extends FacetsTestBase {
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37

  /**
   * {@inheritdoc}
   */
  public static $modules = [
    'views',
    'node',
    'search_api',
    'facets',
    'block',
    'facets_search_api_dependency',
    'facets_query_processor',
  ];

  /**
   * {@inheritdoc}
   */
  public function setUp() {
    parent::setUp();

    $this->drupalLogin($this->adminUser);

38
    $this->setUpExampleStructure();
39
40
41
42
43
44
45
46
47
48
    $this->insertExampleContent();
    $this->assertEqual($this->indexItems($this->indexId), 5, '5 items were indexed.');
  }

  /**
   * Tests various url integration things.
   */
  public function testUrlIntegration() {
    $id = 'facet';
    $name = '&^Facet@#1';
49
    $this->createFacet($name, $id);
50
51
52
53
54
55

    $url = Url::fromUserInput('/search-api-test-fulltext', ['query' => ['f[0]' => 'facet:item']]);
    $this->checkClickedFacetUrl($url);

    /** @var \Drupal\facets\FacetInterface $facet */
    $facet = Facet::load($id);
56
    $this->assertTrue($facet instanceof FacetInterface);
57
58
    $config = $facet->getFacetSourceConfig();
    $this->assertTrue($config instanceof FacetSourceInterface);
59
    $this->assertEqual('f', $config->getFilterKey());
60
61
62
63
64

    $facet = NULL;
    $config = NULL;

    // Go to the only enabled facet source's config and change the filter key.
65
    $this->drupalGet('admin/config/search/facets');
66
    $this->clickLink('Configure', 1);
67
68

    $edit = [
69
70
      'filter_key' => 'y',
      'url_processor' => 'query_string',
71
    ];
72
    $this->drupalPostForm(NULL, $edit, 'Save');
73

74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
    /** @var \Drupal\facets\FacetInterface $facet */
    $facet = Facet::load($id);
    $config = $facet->getFacetSourceConfig();
    $this->assertTrue($config instanceof FacetSourceInterface);
    $this->assertEqual('y', $config->getFilterKey());

    $facet = NULL;
    $config = NULL;

    $url_2 = Url::fromUserInput('/search-api-test-fulltext', ['query' => ['y[0]' => 'facet:item']]);
    $this->checkClickedFacetUrl($url_2);

    // Go to the only enabled facet source's config and change the url
    // processor.
    $this->drupalGet('admin/config/search/facets');
89
    $this->clickLink('Configure', 1);
90
91

    $edit = [
92
93
      'filter_key' => 'y',
      'url_processor' => 'dummy_query',
94
    ];
95
    $this->drupalPostForm(NULL, $edit, 'Save');
96
97
98
99
100
101
102
103
104

    /** @var \Drupal\facets\FacetInterface $facet */
    $facet = Facet::load($id);
    $config = $facet->getFacetSourceConfig();
    $this->assertTrue($config instanceof FacetSourceInterface);
    $this->assertEqual('y', $config->getFilterKey());

    $facet = NULL;
    $config = NULL;
105

106
107
108
109
    $url_3 = Url::fromUserInput('/search-api-test-fulltext', ['query' => ['y[0]' => 'facet||item']]);
    $this->checkClickedFacetUrl($url_3);
  }

110
111
112
113
114
115
  /**
   * Tests the url when a colon is used in the value.
   */
  public function testColonValue() {
    $id = 'water_bear';
    $name = 'Water bear';
116
    $this->createFacet($name, $id, 'keywords');
117
118
119

    // Add a new entity that has a colon in one of it's keywords.
    $entity_test_storage = \Drupal::entityTypeManager()
120
      ->getStorage('entity_test_mulrev_changed');
121
122
123
124
125
126
127
128
129
130
131
132
    $entity_test_storage->create([
      'name' => 'Entity with colon',
      'body' => 'test test',
      'type' => 'item',
      'keywords' => ['orange', 'test:colon'],
      'category' => 'item_category',
    ])->save();
    // Make sure the new item is indexed.
    $this->assertEqual(1, $this->indexItems($this->indexId));

    // Go to the overview and test that we have the expected links.
    $this->drupalGet('search-api-test-fulltext');
133
134
135
    $this->assertFacetLabel('test:colon');
    $this->assertFacetLabel('orange');
    $this->assertFacetLabel('banana');
136
137
138
139
140
141

    // Click the link with the colon.
    $this->clickLink('test:colon');
    $this->assertResponse(200);

    // Make sure 'test:colon' is active.
142
    $url = Url::fromUserInput('/search-api-test-fulltext', ['query' => ['f[0]' => 'water_bear:test:colon']]);
143
    $this->assertUrl($url);
144
145
146
    $this->checkFacetIsActive('test:colon');
    $this->assertFacetLabel('orange');
    $this->assertFacetLabel('banana');
147
148
  }

149
}