Mercurial > hg > isophonics-drupal-site
comparison core/modules/search/src/Tests/SearchEmbedFormTest.php @ 0:4c8ae668cc8c
Initial import (non-working)
author | Chris Cannam |
---|---|
date | Wed, 29 Nov 2017 16:09:58 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4c8ae668cc8c |
---|---|
1 <?php | |
2 | |
3 namespace Drupal\search\Tests; | |
4 | |
5 /** | |
6 * Verifies that a form embedded in search results works. | |
7 * | |
8 * @group search | |
9 */ | |
10 class SearchEmbedFormTest extends SearchTestBase { | |
11 | |
12 /** | |
13 * Modules to enable. | |
14 * | |
15 * @var array | |
16 */ | |
17 public static $modules = ['search_embedded_form']; | |
18 | |
19 /** | |
20 * Node used for testing. | |
21 * | |
22 * @var \Drupal\node\NodeInterface | |
23 */ | |
24 protected $node; | |
25 | |
26 /** | |
27 * Count of how many times the form has been submitted. | |
28 * | |
29 * @var int | |
30 */ | |
31 protected $submitCount = 0; | |
32 | |
33 protected function setUp() { | |
34 parent::setUp(); | |
35 | |
36 // Create a user and a node, and update the search index. | |
37 $test_user = $this->drupalCreateUser(['access content', 'search content', 'administer nodes']); | |
38 $this->drupalLogin($test_user); | |
39 | |
40 $this->node = $this->drupalCreateNode(); | |
41 | |
42 $this->container->get('plugin.manager.search')->createInstance('node_search')->updateIndex(); | |
43 search_update_totals(); | |
44 | |
45 // Set up a dummy initial count of times the form has been submitted. | |
46 $this->submitCount = \Drupal::state()->get('search_embedded_form.submit_count'); | |
47 $this->refreshVariables(); | |
48 } | |
49 | |
50 /** | |
51 * Tests that the embedded form appears and can be submitted. | |
52 */ | |
53 public function testEmbeddedForm() { | |
54 // First verify we can submit the form from the module's page. | |
55 $this->drupalPostForm('search_embedded_form', | |
56 ['name' => 'John'], | |
57 t('Send away')); | |
58 $this->assertText(t('Test form was submitted'), 'Form message appears'); | |
59 $count = \Drupal::state()->get('search_embedded_form.submit_count'); | |
60 $this->assertEqual($this->submitCount + 1, $count, 'Form submission count is correct'); | |
61 $this->submitCount = $count; | |
62 | |
63 // Now verify that we can see and submit the form from the search results. | |
64 $this->drupalGet('search/node', ['query' => ['keys' => $this->node->label()]]); | |
65 $this->assertText(t('Your name'), 'Form is visible'); | |
66 $this->drupalPostForm(NULL, | |
67 ['name' => 'John'], | |
68 t('Send away')); | |
69 $this->assertText(t('Test form was submitted'), 'Form message appears'); | |
70 $count = \Drupal::state()->get('search_embedded_form.submit_count'); | |
71 $this->assertEqual($this->submitCount + 1, $count, 'Form submission count is correct'); | |
72 $this->submitCount = $count; | |
73 | |
74 // Now verify that if we submit the search form, it doesn't count as | |
75 // our form being submitted. | |
76 $this->drupalPostForm('search', | |
77 ['keys' => 'foo'], | |
78 t('Search')); | |
79 $this->assertNoText(t('Test form was submitted'), 'Form message does not appear'); | |
80 $count = \Drupal::state()->get('search_embedded_form.submit_count'); | |
81 $this->assertEqual($this->submitCount, $count, 'Form submission count is correct'); | |
82 $this->submitCount = $count; | |
83 } | |
84 | |
85 } |