diff --git a/src/Plugin/search_api/display/SearchApiPage.php b/src/Plugin/search_api/display/SearchApiPage.php index ee536be..a575146 100644 --- a/src/Plugin/search_api/display/SearchApiPage.php +++ b/src/Plugin/search_api/display/SearchApiPage.php @@ -5,7 +5,7 @@ namespace Drupal\search_api_page\Plugin\search_api\display; use Drupal\search_api\Display\DisplayPluginBase; /** - * Represents a search api page entity. + * Represents a Search API Pages search display. * * @SearchApiDisplay( * id = "search_api_page", diff --git a/src/Plugin/search_api/display/SearchApiPageDeriver.php b/src/Plugin/search_api/display/SearchApiPageDeriver.php index 4fc825f..90b099a 100644 --- a/src/Plugin/search_api/display/SearchApiPageDeriver.php +++ b/src/Plugin/search_api/display/SearchApiPageDeriver.php @@ -15,7 +15,7 @@ class SearchApiPageDeriver extends DisplayDeriverBase { */ public function getDerivativeDefinitions($base_plugin_definition) { if (isset($this->derivatives)) { - $this->derivatives; + return $this->derivatives; } $this->derivatives = array(); @@ -44,10 +44,11 @@ class SearchApiPageDeriver extends DisplayDeriverBase { $plugin_derivatives = []; foreach ($pages as $page) { + $label = $page->label(); + $description = $this->t('The %label search page.', ['%label' => $label]); $plugin_derivatives[$page->id()] = [ - 'display_id' => $page->id, - 'label' => $page->label(), - 'description' => $page->label(), + 'label' => $label, + 'description' => $description, 'index' => $page->getIndex(), 'path' => '/' . $page->getPath(), ] + $base_plugin_definition; diff --git a/tests/src/Functional/FacetsIntegration.php b/tests/src/Functional/FacetsIntegration.php index 29e26da..619c088 100644 --- a/tests/src/Functional/FacetsIntegration.php +++ b/tests/src/Functional/FacetsIntegration.php @@ -89,10 +89,10 @@ class FacetsIntegration extends FunctionalTestBase { $this->assertFacetBlocksAppear(); $this->assertFacetLabel('page'); $this->assertFacetLabel('article'); - $this->assertText('60 results found'); + $this->assertSession()->pageTextContains('60 results found'); $this->clickPartialLink('page'); - $this->assertText('11 results found'); + $this->assertSession()->pageTextContains('11 results found'); } } diff --git a/tests/src/Functional/SearchApiPage.php b/tests/src/Functional/SearchApiPage.php index eeeccef..87c8dbf 100644 --- a/tests/src/Functional/SearchApiPage.php +++ b/tests/src/Functional/SearchApiPage.php @@ -10,16 +10,17 @@ namespace Drupal\Tests\search_api_page\Functional; class SearchApiPage extends FunctionalTestBase { /** - * Test search api pages. + * Tests Search API Pages. */ public function testSearchApiPage() { $this->drupalLogin($this->adminUser); + $assert_session = $this->assertSession(); // Setup search api server and index. $this->setupSearchAPI(); $this->drupalGet('admin/config/search/search-api-pages'); - $this->assertResponse(200); + $assert_session->statusCodeEquals(200); $step1 = array( 'label' => 'Search', @@ -34,49 +35,49 @@ class SearchApiPage extends FunctionalTestBase { $this->drupalPostForm(NULL, $step2, 'Save'); $this->drupalGet('search'); - $this->assertRaw('Enter the terms you wish to search for.'); - $this->assertNoRaw('Your search yielded no results.'); - $this->assertResponse(200); + $assert_session->pageTextContains('Enter the terms you wish to search for.'); + $assert_session->pageTextNotContains('Your search yielded no results.'); + $assert_session->statusCodeEquals(200); $this->drupalLogout(); $this->drupalLogin($this->unauthorizedUser); $this->drupalGet('search'); - $this->assertResponse(403); + $assert_session->statusCodeEquals(403); $this->drupalLogout(); $this->drupalLogin($this->anonymousUser); $this->drupalGet('search'); - $this->assertResponse(200); + $assert_session->statusCodeEquals(200); $this->drupalLogout(); $this->drupalLogin($this->adminUser); $this->drupalGet('search/nothing-found'); - $this->assertRaw('Enter the terms you wish to search for.'); - $this->assertRaw('Your search yielded no results.'); + $assert_session->pageTextContains('Enter the terms you wish to search for.'); + $assert_session->pageTextContains('Your search yielded no results.'); $this->drupalGet('search'); - $this->drupalGet('search'); - $this->assertNoRaw('Your search yielded no results.'); + $assert_session->pageTextNotContains('Your search yielded no results.'); $this->drupalPostForm('admin/config/search/search-api-pages/search', array('show_all_when_no_keys' => TRUE, 'show_search_form' => FALSE), 'Save'); $this->drupalGet('search'); - $this->assertNoRaw('Your search yielded no results.'); - $this->assertNoRaw('Enter the terms you wish to search for.'); - $this->assertText('49 results found'); + $assert_session->pageTextNotContains('Your search yielded no results.'); + $assert_session->pageTextNotContains('Enter the terms you wish to search for.'); + $assert_session->pageTextContains('49 results found'); $this->drupalGet('search/number10'); - $this->assertText('1 result found'); + $assert_session->pageTextContains('1 result found'); $this->drupalPostForm('admin/config/search/search-api-pages/search', array('show_search_form' => TRUE), 'Save'); $this->drupalGet('search/number11'); - $this->assertText('1 result found'); - $this->assertRaw('name="keys" value="number11"'); + $assert_session->pageTextContains('1 result found'); + $assert_session->responseContains('name="keys" value="number11"'); // Cache should be cleared after the save. + // @todo Make this work. //$this->drupalGet('search/number10'); - //$this->assertText('1 result found'); - //$this->assertRaw('name="keys" value="number10"'); + //$assert_session->pageTextContains('1 result found'); + //$assert_session->responseContains('name="keys" value="number10"'); } }