Chris@0: drupalCreateContentType(['type' => 'page', 'name' => 'Basic page']); Chris@17: Chris@0: // Log in with sufficient privileges. Chris@0: $user = $this->drupalCreateUser(['create page content', 'search content']); Chris@0: $this->drupalLogin($user); Chris@0: Chris@0: $settings = [ Chris@0: 'type' => 'page', Chris@0: 'title' => 'Simple Node', Chris@0: ]; Chris@0: // Create nodes with exact phrase. Chris@0: for ($i = 0; $i <= 17; $i++) { Chris@0: $settings['body'] = [['value' => 'love pizza']]; Chris@0: $this->drupalCreateNode($settings); Chris@0: } Chris@0: // Create nodes containing keywords. Chris@0: for ($i = 0; $i <= 17; $i++) { Chris@0: $settings['body'] = [['value' => 'love cheesy pizza']]; Chris@0: $this->drupalCreateNode($settings); Chris@0: } Chris@0: // Create another node and save it for later. Chris@0: $settings['body'] = [['value' => 'Druplicon']]; Chris@0: $node = $this->drupalCreateNode($settings); Chris@0: Chris@0: // Update the search index. Chris@0: $this->container->get('plugin.manager.search')->createInstance('node_search')->updateIndex(); Chris@0: search_update_totals(); Chris@0: Chris@0: // Refresh variables after the treatment. Chris@0: $this->refreshVariables(); Chris@0: Chris@0: // Test that the correct number of pager links are found for keyword search. Chris@0: $edit = ['keys' => 'love pizza']; Chris@0: $this->drupalPostForm('search/node', $edit, t('Search')); Chris@0: $this->assertLinkByHref('page=1', 0, '2nd page link is found for keyword search.'); Chris@0: $this->assertLinkByHref('page=2', 0, '3rd page link is found for keyword search.'); Chris@0: $this->assertLinkByHref('page=3', 0, '4th page link is found for keyword search.'); Chris@0: $this->assertNoLinkByHref('page=4', '5th page link is not found for keyword search.'); Chris@0: Chris@0: // Test that the correct number of pager links are found for exact phrase search. Chris@0: $edit = ['keys' => '"love pizza"']; Chris@0: $this->drupalPostForm('search/node', $edit, t('Search')); Chris@0: $this->assertLinkByHref('page=1', 0, '2nd page link is found for exact phrase search.'); Chris@0: $this->assertNoLinkByHref('page=2', '3rd page link is not found for exact phrase search.'); Chris@0: Chris@0: // Check that with post settings turned on the post information is displayed. Chris@0: $node_type_config = \Drupal::configFactory()->getEditable('node.type.page'); Chris@0: $node_type_config->set('display_submitted', TRUE); Chris@0: $node_type_config->save(); Chris@0: Chris@0: $edit = ['keys' => 'Druplicon']; Chris@0: $this->drupalPostForm('search/node', $edit, t('Search')); Chris@18: $this->assertText($user->getAccountName(), 'Basic page node displays author name when post settings are on.'); Chris@18: $this->assertText($this->container->get('date.formatter')->format($node->getChangedTime(), 'short'), 'Basic page node displays post date when post settings are on.'); Chris@0: Chris@0: // Check that with post settings turned off the user and changed date Chris@0: // information is not displayed. Chris@0: $node_type_config->set('display_submitted', FALSE); Chris@0: $node_type_config->save(); Chris@0: $edit = ['keys' => 'Druplicon']; Chris@0: $this->drupalPostForm('search/node', $edit, t('Search')); Chris@18: $this->assertNoText($user->getAccountName(), 'Basic page node does not display author name when post settings are off.'); Chris@18: $this->assertNoText($this->container->get('date.formatter')->format($node->getChangedTime(), 'short'), 'Basic page node does not display post date when post settings are off.'); Chris@0: Chris@0: } Chris@0: Chris@0: }