X-Git-Url: http://www.aleph1.co.uk/gitweb/?a=blobdiff_plain;f=web%2Fcore%2Fmodules%2Fsearch%2Fsrc%2FTests%2FSearchEmbedFormTest.php;fp=web%2Fcore%2Fmodules%2Fsearch%2Fsrc%2FTests%2FSearchEmbedFormTest.php;h=5f3fbea32b3b3094f784d6b717c69ed13ccd8989;hb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;hp=0000000000000000000000000000000000000000;hpb=57c063afa3f66b07c4bbddc2d6129a96d90f0aad;p=yaffs-website diff --git a/web/core/modules/search/src/Tests/SearchEmbedFormTest.php b/web/core/modules/search/src/Tests/SearchEmbedFormTest.php new file mode 100644 index 000000000..5f3fbea32 --- /dev/null +++ b/web/core/modules/search/src/Tests/SearchEmbedFormTest.php @@ -0,0 +1,85 @@ +drupalCreateUser(['access content', 'search content', 'administer nodes']); + $this->drupalLogin($test_user); + + $this->node = $this->drupalCreateNode(); + + $this->container->get('plugin.manager.search')->createInstance('node_search')->updateIndex(); + search_update_totals(); + + // Set up a dummy initial count of times the form has been submitted. + $this->submitCount = \Drupal::state()->get('search_embedded_form.submit_count'); + $this->refreshVariables(); + } + + /** + * Tests that the embedded form appears and can be submitted. + */ + public function testEmbeddedForm() { + // First verify we can submit the form from the module's page. + $this->drupalPostForm('search_embedded_form', + ['name' => 'John'], + t('Send away')); + $this->assertText(t('Test form was submitted'), 'Form message appears'); + $count = \Drupal::state()->get('search_embedded_form.submit_count'); + $this->assertEqual($this->submitCount + 1, $count, 'Form submission count is correct'); + $this->submitCount = $count; + + // Now verify that we can see and submit the form from the search results. + $this->drupalGet('search/node', ['query' => ['keys' => $this->node->label()]]); + $this->assertText(t('Your name'), 'Form is visible'); + $this->drupalPostForm(NULL, + ['name' => 'John'], + t('Send away')); + $this->assertText(t('Test form was submitted'), 'Form message appears'); + $count = \Drupal::state()->get('search_embedded_form.submit_count'); + $this->assertEqual($this->submitCount + 1, $count, 'Form submission count is correct'); + $this->submitCount = $count; + + // Now verify that if we submit the search form, it doesn't count as + // our form being submitted. + $this->drupalPostForm('search', + ['keys' => 'foo'], + t('Search')); + $this->assertNoText(t('Test form was submitted'), 'Form message does not appear'); + $count = \Drupal::state()->get('search_embedded_form.submit_count'); + $this->assertEqual($this->submitCount, $count, 'Form submission count is correct'); + $this->submitCount = $count; + } + +}