summaryrefslogtreecommitdiffstats
path: root/core_search_facets/src/Tests/HooksTest.php
blob: bc9572db7e934f1b8e41ccc78aa1c521769e2e86 (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
<?php

namespace Drupal\core_search_facets\Tests;

use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;

/**
 * Tests integration of hooks.
 *
 * @group facets
 */
class HooksTest extends WebTestBase {

  /**
   * {@inheritdoc}
   */
  public static $modules = [
    'node',
    'search',
    'core_search_facets_test_hooks',
    'field',
  ];

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

    // Create a field of type float.
    FieldStorageConfig::create(
      [
        'field_name' => 'float',
        'entity_type' => 'node',
        'type' => 'float',
      ]
    )->save();

    // Create an instance of the float field on the "page" content type.
    FieldConfig::create(
      [
        'field_name' => 'float',
        'entity_type' => 'node',
        'bundle' => 'page',
        'label' => 'Float Field Label',
      ]
    )->save();

    // Log in, so we can test all the things.
    $this->drupalLogin($this->adminUser);
  }

  /**
   * Tests various that all hooks fire correctly.
   */
  public function testHooks() {
    // Verify that hook_facets_core_allowed_field_types was triggered.
    $facet_add_page = 'admin/config/search/facets/add-facet';
    $this->drupalGet($facet_add_page);
    $this->assertResponse(200);

    // Select the node_search facet source.
    $this->drupalGet($facet_add_page);
    $this->drupalPostForm(
      NULL,
      ['facet_source_id' => 'core_node_search:node_search'],
      $this->t('Configure facet source')
    );

    // The field appears as expected.
    $this->assertText('Float Field Label', 'Float Field appears as expected');
  }

}