|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Drupal\Tests\localgov_subsites\Functional; |
| 4 | + |
| 5 | +use Drupal\Tests\Traits\Core\CronRunTrait; |
| 6 | +use Drupal\node\NodeInterface; |
| 7 | +use Drupal\Tests\BrowserTestBase; |
| 8 | +use Drupal\Tests\node\Traits\NodeCreationTrait; |
| 9 | +use Drupal\Tests\system\Functional\Menu\AssertBreadcrumbTrait; |
| 10 | + |
| 11 | +/** |
| 12 | + * Tests pages working together with LocalGov: pathauto, services, search. |
| 13 | + * |
| 14 | + * @group localgov_directories |
| 15 | + */ |
| 16 | +class LocalgovIntegrationTest extends BrowserTestBase { |
| 17 | + |
| 18 | + use NodeCreationTrait; |
| 19 | + use AssertBreadcrumbTrait; |
| 20 | + use CronRunTrait; |
| 21 | + |
| 22 | + /** |
| 23 | + * Test breadcrumbs in the Standard profile. |
| 24 | + * |
| 25 | + * @var string |
| 26 | + */ |
| 27 | + protected $profile = 'standard'; |
| 28 | + |
| 29 | + /** |
| 30 | + * {@inheritdoc} |
| 31 | + */ |
| 32 | + protected $defaultTheme = 'stable'; |
| 33 | + |
| 34 | + /** |
| 35 | + * A user with permission to bypass content access checks. |
| 36 | + * |
| 37 | + * @var \Drupal\user\UserInterface |
| 38 | + */ |
| 39 | + protected $adminUser; |
| 40 | + |
| 41 | + /** |
| 42 | + * The node storage. |
| 43 | + * |
| 44 | + * @var \Drupal\node\NodeStorageInterface |
| 45 | + */ |
| 46 | + protected $nodeStorage; |
| 47 | + |
| 48 | + /** |
| 49 | + * Modules to enable. |
| 50 | + * |
| 51 | + * @var array |
| 52 | + */ |
| 53 | + protected static $modules = [ |
| 54 | + 'localgov_core', |
| 55 | + 'localgov_services_landing', |
| 56 | + 'localgov_services_sublanding', |
| 57 | + 'localgov_services_navigation', |
| 58 | + 'localgov_subsites', |
| 59 | + 'localgov_search', |
| 60 | + 'localgov_search_db', |
| 61 | + ]; |
| 62 | + |
| 63 | + /** |
| 64 | + * {@inheritdoc} |
| 65 | + */ |
| 66 | + protected function setUp(): void { |
| 67 | + parent::setUp(); |
| 68 | + $this->drupalPlaceBlock('system_breadcrumb_block'); |
| 69 | + $this->adminUser = $this->drupalCreateUser([ |
| 70 | + 'bypass node access', |
| 71 | + 'administer nodes', |
| 72 | + ]); |
| 73 | + $this->nodeStorage = $this->container->get('entity_type.manager')->getStorage('node'); |
| 74 | + } |
| 75 | + |
| 76 | + /** |
| 77 | + * LocalGov Search integration. |
| 78 | + */ |
| 79 | + public function testLocalgovSearch() { |
| 80 | + |
| 81 | + // Confirm the localgov_subsites_overview nodes work with database search. |
| 82 | + $title = 'Subsite overview 1'; |
| 83 | + $overview_summary = 'Science is the search for truth, that is the effort to understand the world: it involves the rejection of bias, of dogma, of revelation, but not the rejection of morality.'; |
| 84 | + $this->createNode([ |
| 85 | + 'title' => $title, |
| 86 | + 'type' => 'localgov_subsites_overview', |
| 87 | + 'status' => NodeInterface::PUBLISHED, |
| 88 | + 'localgov_subsites_summary' => $overview_summary, |
| 89 | + ]); |
| 90 | + $this->cronRun(); |
| 91 | + $this->drupalGet('search', ['query' => ['s' => 'bias+dogma+revelation']]); |
| 92 | + $this->assertSession()->pageTextContains($title); |
| 93 | + $this->assertSession()->responseContains('<strong>bias</strong>'); |
| 94 | + $this->assertSession()->responseContains('<strong>dogma</strong>'); |
| 95 | + $this->assertSession()->responseContains('<strong>revelation</strong>'); |
| 96 | + |
| 97 | + // Confirm the localgov_subsites_page nodes work with database search. |
| 98 | + $page_summary = "Time isn't the main thing. It's the only thing."; |
| 99 | + $this->createNode([ |
| 100 | + 'title' => 'Subsite subsite page', |
| 101 | + 'type' => 'localgov_subsites_page', |
| 102 | + 'status' => NodeInterface::PUBLISHED, |
| 103 | + 'localgov_subsites_summary' => $page_summary, |
| 104 | + ]); |
| 105 | + $this->cronRun(); |
| 106 | + $this->drupalGet('search', ['query' => ['s' => 'time+main+only']]); |
| 107 | + $this->assertSession()->pageTextContains('Subsite subsite page'); |
| 108 | + $this->assertSession()->responseContains('<strong>time</strong>'); |
| 109 | + $this->assertSession()->responseContains('<strong>main</strong>'); |
| 110 | + $this->assertSession()->responseContains('<strong>only</strong>'); |
| 111 | + } |
| 112 | + |
| 113 | +} |
0 commit comments