summaryrefslogtreecommitdiffstats
path: root/src/Tests/FacetSourceTest.php
blob: 2fd23359ec5e415b0609df58e27c9d9aab8ecf3a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php

namespace Drupal\facets\Tests;

/**
 * Tests the functionality of the facet source config entity.
 *
 * @group facets
 */
class FacetSourceTest extends WebTestBase {

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

  /**
   * Tests the facet source editing.
   */
  public function testEditFilterKey() {
    // Make sure we're logged in with a user that has sufficient permissions.
    $this->drupalLogin($this->adminUser);

    // Test the overview.
    $this->drupalGet('admin/config/search/facets');
    $this->assertLink($this->t('Configure'));
    $this->clickLink($this->t('Configure'));

    // Test the edit page.
    $edit = array(
      'filter_key' => 'fq',
    );
    $this->assertField('filter_key');
    $this->assertField('url_processor');
    $this->drupalPostForm(NULL, $edit, $this->t('Save'));
    $this->assertResponse(200);

    // Test that saving worked filter_key has the new value.
    $this->assertField('filter_key');
    $this->assertField('url_processor');
    $this->assertRaw('fq');
  }

  /**
   * Tests editing the url processor.
   */
  public function testEditUrlProcessor() {
    // Make sure we're logged in with a user that has sufficient permissions.
    $this->drupalLogin($this->adminUser);

    // Test the overview.
    $this->drupalGet('admin/config/search/facets');
    $this->assertLink($this->t('Configure'));
    $this->clickLink($this->t('Configure'));

    // Test the edit page.
    $edit = array(
      'url_processor' => 'dummy_query',
    );
    $this->assertField('filter_key');
    $this->assertField('url_processor');
    $this->drupalPostForm(NULL, $edit, $this->t('Save'));
    $this->assertResponse(200);

    // Test that saving worked and that the url processor has the new value.
    $this->assertField('filter_key');
    $this->assertField('url_processor');
    $elements = $this->xpath('//input[@id=:id]', [':id' => 'edit-url-processor-dummy-query']);
    $this->assertEqual('dummy_query', $elements[0]['value']);
  }

}