diff --git a/src/Tests/ExampleContentTrait.php b/src/Tests/ExampleContentTrait.php index 2d2dac7..8143b40 100644 --- a/src/Tests/ExampleContentTrait.php +++ b/src/Tests/ExampleContentTrait.php @@ -123,21 +123,25 @@ trait ExampleContentTrait { } /** - * Asserts that a string is before another string. + * Asserts that a string is found before another string in the source. + * + * This uses the simpletest's getRawContent method to search in the source of + * the page for the position of 2 strings and that the first argument is + * before the second argument's position. * * @param string $x * A string. * @param string $y * Another string. */ - protected function assertXBeforeY($x, $y) { + protected function assertStringPosition($x, $y) { $this->assertText($x); $this->assertText($y); $x_position = strpos($this->getRawContent(), $x); $y_position = strpos($this->getRawContent(), $y); - $message = new FormattableMarkup('Assert that %x is before %y in the HTML', ['%x' => $x, '%y' => $y]); + $message = new FormattableMarkup('Assert that %x is before %y in the source', ['%x' => $x, '%y' => $y]); $this->assertTrue($x_position < $y_position, $message); } diff --git a/src/Tests/ProcessorIntegrationTest.php b/src/Tests/ProcessorIntegrationTest.php index a1c38bb..aa07f7f 100644 --- a/src/Tests/ProcessorIntegrationTest.php +++ b/src/Tests/ProcessorIntegrationTest.php @@ -7,7 +7,6 @@ namespace Drupal\facets\Tests; -use Drupal\Core\Url; use Drupal\facets\Tests\WebTestBase as FacetWebTestBase; /** @@ -18,13 +17,6 @@ use Drupal\facets\Tests\WebTestBase as FacetWebTestBase; class ProcessorIntegrationTest extends FacetWebTestBase { /** - * The block entities used by this test. - * - * @var \Drupal\block\BlockInterface[] - */ - protected $blocks; - - /** * The url of the edit form. * * @var string @@ -39,19 +31,16 @@ class ProcessorIntegrationTest extends FacetWebTestBase { $this->drupalLogin($this->adminUser); + // Set up example content types and insert 10 new content items. $this->setUpExampleStructure(); $this->insertExampleContent(); $this->assertEqual($this->indexItems($this->indexId), 5, '5 items were indexed.'); $this->insertExampleContent(); $this->assertEqual($this->indexItems($this->indexId), 5, '5 items were indexed.'); - - // Make absolutely sure the ::$blocks variable doesn't pass information - // along between tests. - $this->blocks = NULL; } /** - * Tests for admin processors.. + * Tests for the processors behavior in the backend. */ public function testProcessorAdmin() { $facet_name = "Guanaco"; @@ -69,8 +58,8 @@ class ProcessorIntegrationTest extends FacetWebTestBase { $this->assertResponse(200); $this->assertFieldChecked('edit-facet-settings-count-limit-status'); - // Enable the sort processor and change sort direction. - // Test that the sort settings change persisted. + // Enable the sort processor and change sort direction, check that the + // change is persisted. $form = [ 'facet_sorting[active_widget_order][status]' => TRUE, 'facet_sorting[active_widget_order][settings][sort]' => 'DESC', @@ -86,7 +75,6 @@ class ProcessorIntegrationTest extends FacetWebTestBase { 'facet_settings[count_limit][status]' => TRUE, ]; $this->drupalPostForm(NULL, $form, $this->t('Save')); - $this->assertResponse(200); $this->assertFieldChecked('edit-facet-settings-count-limit-status'); $this->assertFieldChecked('edit-facet-settings-hide-non-narrowing-result-processor-status'); @@ -108,7 +96,7 @@ class ProcessorIntegrationTest extends FacetWebTestBase { } /** - * Tests for processor integration. + * Tests the for processors in the frontend with a 'keywords' facet. */ public function testProcessorIntegration() { $facet_name = "Vicuña"; @@ -132,7 +120,7 @@ class ProcessorIntegrationTest extends FacetWebTestBase { } /** - * Tests for processor integration. + * Tests the for sorting processors in the frontend with a 'keywords' facet. */ public function testSortingWidgets() { $facet_name = "Huacaya alpaca"; @@ -145,6 +133,7 @@ class ProcessorIntegrationTest extends FacetWebTestBase { $this->checkSortByActive(); $this->checkSortByCount(); $this->checkSortByDisplay(); + $this->checkSortByRaw(); } /** @@ -278,7 +267,7 @@ class ProcessorIntegrationTest extends FacetWebTestBase { $this->drupalGet('search-api-test-fulltext'); $this->clickLink('strawberry'); - $this->assertXBeforeY('(-) strawberry', 'grape'); + $this->assertStringPosition('(-) strawberry', 'grape'); $form = [ 'facet_sorting[active_widget_order][status]' => TRUE, @@ -288,7 +277,7 @@ class ProcessorIntegrationTest extends FacetWebTestBase { $this->drupalGet('search-api-test-fulltext'); $this->clickLink('strawberry'); - $this->assertXBeforeY('grape', '(-) strawberry'); + $this->assertStringPosition('grape', '(-) strawberry'); $form = [ 'facet_sorting[active_widget_order][status]' => FALSE, @@ -307,9 +296,9 @@ class ProcessorIntegrationTest extends FacetWebTestBase { $this->drupalPostForm($this->editForm, $form, $this->t('Save')); $this->drupalGet('search-api-test-fulltext'); - $this->assertXBeforeY('banana', 'apple'); - $this->assertXBeforeY('banana', 'strawberry'); - $this->assertXBeforeY('apple', 'orange'); + $this->assertStringPosition('banana', 'apple'); + $this->assertStringPosition('banana', 'strawberry'); + $this->assertStringPosition('apple', 'orange'); $form = [ 'facet_sorting[count_widget_order][status]' => TRUE, @@ -318,9 +307,9 @@ class ProcessorIntegrationTest extends FacetWebTestBase { $this->drupalPostForm($this->editForm, $form, $this->t('Save')); $this->drupalGet('search-api-test-fulltext'); - $this->assertXBeforeY('apple', 'banana'); - $this->assertXBeforeY('strawberry', 'banana'); - $this->assertXBeforeY('orange', 'apple'); + $this->assertStringPosition('apple', 'banana'); + $this->assertStringPosition('strawberry', 'banana'); + $this->assertStringPosition('orange', 'apple'); $form = [ 'widget_configs[show_numbers]' => FALSE, @@ -339,8 +328,8 @@ class ProcessorIntegrationTest extends FacetWebTestBase { $this->drupalPostForm($this->editForm, $form, $this->t('Save')); $this->drupalGet('search-api-test-fulltext'); - $this->assertXBeforeY('grape', 'strawberry'); - $this->assertXBeforeY('apple', 'banana'); + $this->assertStringPosition('grape', 'strawberry'); + $this->assertStringPosition('apple', 'banana'); $form = [ 'facet_sorting[display_value_widget_order][status]' => TRUE, @@ -349,8 +338,8 @@ class ProcessorIntegrationTest extends FacetWebTestBase { $this->drupalPostForm($this->editForm, $form, $this->t('Save')); $this->drupalGet('search-api-test-fulltext'); - $this->assertXBeforeY('strawberry', 'grape'); - $this->assertXBeforeY('banana', 'apple'); + $this->assertStringPosition('strawberry', 'grape'); + $this->assertStringPosition('banana', 'apple'); $form = [ 'facet_sorting[display_value_widget_order][status]' => FALSE, @@ -359,6 +348,35 @@ class ProcessorIntegrationTest extends FacetWebTestBase { } /** + * Tests the display order. + */ + public function checkSortByRaw() { + $form = [ + 'facet_sorting[raw_value_widget_order][status]' => TRUE, + ]; + $this->drupalPostForm($this->editForm, $form, $this->t('Save')); + + $this->drupalGet('search-api-test-fulltext'); + $this->assertStringPosition('grape', 'strawberry'); + $this->assertStringPosition('apple', 'banana'); + + $form = [ + 'facet_sorting[raw_value_widget_order][status]' => TRUE, + 'facet_sorting[raw_value_widget_order][settings][sort]' => 'DESC', + ]; + $this->drupalPostForm($this->editForm, $form, $this->t('Save')); + + $this->drupalGet('search-api-test-fulltext'); + $this->assertStringPosition('strawberry', 'grape'); + $this->assertStringPosition('banana', 'apple'); + + $form = [ + 'facet_sorting[raw_value_widget_order][status]' => FALSE, + ]; + $this->drupalPostForm($this->editForm, $form, $this->t('Save')); + } + + /** * Creates a facet block by id. * * @param string $id