Chris@0: drupalCreateContentType(); Chris@0: Chris@0: // Add three nodes, one containing the word "pizza", one containing Chris@0: // "sandwich", and one containing "cola is good with pizza". Make the Chris@0: // second node link to the first. Chris@0: $node['title'] = 'pizza'; Chris@0: $node['body'] = [['value' => 'pizza']]; Chris@0: $node['type'] = $type->id(); Chris@0: $this->drupalCreateNode($node); Chris@0: Chris@0: $this->drupalGet('node/1'); Chris@0: $node_url = $this->getUrl(); Chris@0: Chris@0: $node['title'] = 'sandwich'; Chris@0: $node['body'] = [['value' => 'sandwich with a link to first node']]; Chris@0: $this->drupalCreateNode($node); Chris@0: Chris@0: $node['title'] = 'cola'; Chris@0: $node['body'] = [['value' => 'cola is good with pizza']]; Chris@0: $node['type'] = $type->id(); Chris@0: $this->drupalCreateNode($node); Chris@0: Chris@0: // Run cron so that the search index tables are updated. Chris@0: $this->cronRun(); Chris@0: Chris@0: // Test the various views filters by visiting their pages. Chris@0: // These are in the test view 'test_search', and they just display the Chris@0: // titles of the nodes in the result, as links. Chris@0: Chris@0: // Page with a keyword filter of 'pizza'. Chris@0: $this->drupalGet('test-filter'); Chris@0: $this->assertLink('pizza'); Chris@0: $this->assertNoLink('sandwich'); Chris@0: $this->assertLink('cola'); Chris@0: Chris@0: // Page with a keyword argument, various argument values. Chris@0: // Verify that the correct nodes are shown, and only once. Chris@0: $this->drupalGet('test-arg/pizza'); Chris@0: $this->assertOneLink('pizza'); Chris@0: $this->assertNoLink('sandwich'); Chris@0: $this->assertOneLink('cola'); Chris@0: Chris@0: $this->drupalGet('test-arg/sandwich'); Chris@0: $this->assertNoLink('pizza'); Chris@0: $this->assertOneLink('sandwich'); Chris@0: $this->assertNoLink('cola'); Chris@0: Chris@0: $this->drupalGet('test-arg/pizza OR sandwich'); Chris@0: $this->assertOneLink('pizza'); Chris@0: $this->assertOneLink('sandwich'); Chris@0: $this->assertOneLink('cola'); Chris@0: Chris@0: $this->drupalGet('test-arg/pizza sandwich OR cola'); Chris@0: $this->assertNoLink('pizza'); Chris@0: $this->assertNoLink('sandwich'); Chris@0: $this->assertOneLink('cola'); Chris@0: Chris@0: $this->drupalGet('test-arg/cola pizza'); Chris@0: $this->assertNoLink('pizza'); Chris@0: $this->assertNoLink('sandwich'); Chris@0: $this->assertOneLink('cola'); Chris@0: Chris@0: $this->drupalGet('test-arg/"cola is good"'); Chris@0: $this->assertNoLink('pizza'); Chris@0: $this->assertNoLink('sandwich'); Chris@0: $this->assertOneLink('cola'); Chris@0: Chris@0: // Test sorting. Chris@0: $node = [ Chris@0: 'title' => "Drupal's search rocks.", Chris@0: 'type' => $type->id(), Chris@0: ]; Chris@0: $this->drupalCreateNode($node); Chris@0: $node['title'] = "Drupal's search rocks really rocks!"; Chris@0: $this->drupalCreateNode($node); Chris@0: $this->cronRun(); Chris@0: $this->drupalGet('test-arg/rocks'); Chris@0: $xpath = '//div[@class="views-row"]//a'; Chris@0: /** @var \Behat\Mink\Element\NodeElement[] $results */ Chris@0: $results = $this->xpath($xpath); Chris@0: $this->assertEqual($results[0]->getText(), "Drupal's search rocks really rocks!"); Chris@0: $this->assertEqual($results[1]->getText(), "Drupal's search rocks."); Chris@0: $this->assertEscaped("Drupal's search rocks really rocks!"); Chris@0: Chris@0: // Test sorting with another set of titles. Chris@0: $node = [ Chris@0: 'title' => "Testing one two two two", Chris@0: 'type' => $type->id(), Chris@0: ]; Chris@0: $this->drupalCreateNode($node); Chris@0: $node['title'] = "Testing one one one"; Chris@0: $this->drupalCreateNode($node); Chris@0: $this->cronRun(); Chris@0: $this->drupalGet('test-arg/one'); Chris@0: $xpath = '//div[@class="views-row"]//a'; Chris@0: /** @var \SimpleXMLElement[] $results */ Chris@0: $results = $this->xpath($xpath); Chris@0: $this->assertEqual($results[0]->getText(), "Testing one one one"); Chris@0: $this->assertEqual($results[1]->getText(), "Testing one two two two"); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Asserts that exactly one link exists with the given text. Chris@0: * Chris@0: * @param string $label Chris@0: * Link label to assert. Chris@0: * Chris@0: * @return bool Chris@0: * TRUE if the assertion succeeded, FALSE otherwise. Chris@0: */ Chris@0: protected function assertOneLink($label) { Chris@0: $links = $this->xpath('//a[normalize-space(text())=:label]', [':label' => $label]); Chris@17: $message = new FormattableMarkup('Link with label %label found once.', ['%label' => $label]); Chris@0: return $this->assert(isset($links[0]) && !isset($links[1]), $message); Chris@0: } Chris@0: Chris@0: }