Commit 99bfbf9d authored by Nejc Koporec's avatar Nejc Koporec Committed by Markus Kalkbrenner
Browse files

Issue #3320629: Fix broken tests in 3.0.x

parent 0105e388
Loading
Loading
Loading
Loading
+13 −0
Original line number Diff line number Diff line
@@ -2,10 +2,13 @@

namespace Drupal\Tests\facets_range_widget\Unit\Plugin\widget;

use Drupal\Core\Entity\EntityTypeManager;
use Drupal\Core\Routing\UrlGeneratorInterface;
use Drupal\Core\Url;
use Drupal\facets\Entity\Facet;
use Drupal\facets\FacetSource\FacetSourcePluginManager;
use Drupal\facets\Result\Result;
use Drupal\facets\UrlProcessor\UrlProcessorInterface;
use Drupal\facets\Widget\WidgetPluginManager;
use Drupal\facets_range_widget\Plugin\facets\widget\SliderWidget;
use Drupal\Tests\facets\Unit\Plugin\widget\WidgetTestBase;
@@ -65,6 +68,8 @@ class SliderWidgetTest extends WidgetTestBase {
   * Tests building of the widget.
   */
  public function testBuild() {
    $facet = new Facet(['id' => 'barn_owl'], 'facets_facet');

    $widget = $this->prophesize(SliderWidget::class);
    $widget->getConfiguration()->willReturn(['show_numbers' => FALSE]);
    $pluginManager = $this->prophesize(WidgetPluginManager::class);
@@ -73,8 +78,16 @@ class SliderWidgetTest extends WidgetTestBase {

    $url_generator = $this->prophesize(UrlGeneratorInterface::class);

    $entity_type_manager = $this->prophesize(EntityTypeManager::class);

    $url_processor = $this->prophesize(UrlProcessorInterface::class);
    $manager = $this->createMock(FacetSourcePluginManager::class);
    $manager->method('createInstance')->willReturn($url_processor->reveal());

    $container = new ContainerBuilder();
    $container->set('plugin.manager.facets.widget', $pluginManager->reveal());
    $container->set('plugin.manager.facets.url_processor', $manager);
    $container->set('entity_type.manager', $entity_type_manager->reveal());
    $container->set('url_generator', $url_generator->reveal());
    \Drupal::setContainer($container);

+1 −0
Original line number Diff line number Diff line
@@ -125,6 +125,7 @@ abstract class FacetResourceTestBase extends EntityResourceTestBase {
  protected function getExpectedCacheContexts() {
    return array_merge(parent::getExpectedCacheContexts(), [
      'url.query_args',
      'facets_filter:f',
    ]);
  }

+16 −11
Original line number Diff line number Diff line
@@ -47,8 +47,9 @@ class AjaxBehaviorTest extends JsBase {
    $links = $this->xpath('//a//span[normalize-space(text())=:label]', [':label' => 'article']);
    $this->assertNotEmpty($links);

    // Click the item facet.
    $this->clickLink('item');
    // Click the item facets.
    $owl_link = $this->assertSession()->elementExists("xpath", "//label[@for='owl-item']/span[1]");
    $owl_link->click();

    $this->assertSession()->assertWaitOnAjaxRequest();
    $this->assertSession()->pageTextContains('Displaying 3 search results');
@@ -58,7 +59,7 @@ class AjaxBehaviorTest extends JsBase {
    $this->assertEmpty($links);

    // Click the item facet again, and check that the article facet is back.
    $this->clickLink('item');
    $owl_link->click();
    $this->assertSession()->assertWaitOnAjaxRequest();
    $this->assertSession()->pageTextContains('Displaying 5 search results');
    $links = $this->xpath('//a//span[normalize-space(text())=:label]', [':label' => 'article']);
@@ -67,7 +68,8 @@ class AjaxBehaviorTest extends JsBase {
    // Check that the strawberry link disappears when filtering on items.
    $links = $this->xpath('//a//span[normalize-space(text())=:label]', [':label' => 'strawberry']);
    $this->assertNotEmpty($links);
    $this->clickLink('item');

    $owl_link->click();
    $this->assertSession()->assertWaitOnAjaxRequest();
    $links = $this->xpath('//a//span[normalize-space(text())=:label]', [':label' => 'strawberry']);
    $this->assertEmpty($links);
@@ -95,13 +97,14 @@ class AjaxBehaviorTest extends JsBase {
    // Check that the article_category option disappears when filtering on item.
    $dropdown_entry = $this->xpath('//*[@id="block-duck-block"]/div/select/option[normalize-space(text())=:label]', [':label' => 'article_category']);
    $this->assertNotEmpty($dropdown_entry);
    $block_owl->clickLink('item');
    $owl_link = $this->assertSession()->elementExists("xpath", "//label[@for='owl-item']/span[1]");
    $owl_link->click();
    $this->assertSession()->assertWaitOnAjaxRequest();
    $dropdown_entry = $this->xpath('//*[@id="block-duck-block"]/div/select/option[normalize-space(text())=:label]', [':label' => 'article_category']);
    $this->assertEmpty($dropdown_entry);

    // Click the item facet again.
    $block_owl->clickLink('item');
    $owl_link->click();
    $this->assertSession()->assertWaitOnAjaxRequest();

    // Select the article_category in the dropdown.
@@ -143,7 +146,8 @@ class AjaxBehaviorTest extends JsBase {
    $this->assertNotEmpty($links);

    // Click the item facet.
    $this->clickLink('item');
    $owl_link = $this->assertSession()->elementExists("xpath", "//label[@for='owl-item']/span[1]");
    $owl_link->click();

    $this->assertSession()->assertWaitOnAjaxRequest();
    $this->assertSession()->pageTextContains('Displaying 3 search results');
@@ -153,7 +157,7 @@ class AjaxBehaviorTest extends JsBase {
    $this->assertEmpty($links);

    // Click the item facet again, and check that the article facet is back.
    $this->clickLink('item');
    $owl_link->click();
    $this->assertSession()->assertWaitOnAjaxRequest();
    $this->assertSession()->pageTextContains('Displaying 5 search results');
    $links = $this->xpath('//a//span[normalize-space(text())=:label]', [':label' => 'article']);
@@ -162,11 +166,11 @@ class AjaxBehaviorTest extends JsBase {
    // Check that the strawberry link disappears when filtering on items.
    $links = $this->xpath('//a//span[normalize-space(text())=:label]', [':label' => 'strawberry']);
    $this->assertNotEmpty($links);
    $this->clickLink('item');
    $owl_link->click();
    $this->assertSession()->assertWaitOnAjaxRequest();
    $links = $this->xpath('//a//span[normalize-space(text())=:label]', [':label' => 'strawberry']);
    $this->assertEmpty($links);
    $this->clickLink('item');
    $owl_link->click();

    $this->getSession()->getPage()->checkField('strawberry');
    // Check that the article link exists (and is formatted like a facet) link.
@@ -198,7 +202,8 @@ class AjaxBehaviorTest extends JsBase {
    $this->assertSession()->assertWaitOnAjaxRequest();
    $this->assertSession()->pageTextContains('Displaying 3 search results');

    $this->clickLink('item');
    $owl_link = $this->assertSession()->elementExists("xpath", "//label[@for='owl-item']/span[1]");
    $owl_link->click();
    $this->assertSession()->assertWaitOnAjaxRequest();
    $this->assertSession()->pageTextContains('Displaying 1 search results');
  }
+5 −12
Original line number Diff line number Diff line
@@ -353,21 +353,18 @@ class WidgetJSTest extends JsBase {
        '',
        TRUE,
      ],
      // The second option should have the expected option text, have the URI
      // that points to the updated search result as the value, and is not
      // selected.
      [
        'item (3)',
        base_path() . 'search-api-test-fulltext?f%5B0%5D=llama%3Aitem',
        'llama:item',
        FALSE,
      ],
      // The third option is similar.
      [
        'article (2)',
        base_path() . 'search-api-test-fulltext?f%5B0%5D=llama%3Aarticle',
        'llama:article',
        FALSE,
      ],
    ];

    $this->assertSelectOptions($expected, $options);

    // Selecting one of the options should cause a redirect to a page with
@@ -391,18 +388,14 @@ class WidgetJSTest extends JsBase {
        base_path() . 'search-api-test-fulltext',
        FALSE,
      ],
      // The second option should now be selected, and since clicking it again
      // would negate it, it should also link to the search page without any
      // chosen facets.
      [
        'item (3)',
        base_path() . 'search-api-test-fulltext',
        'llama:item',
        TRUE,
      ],
      // The third option remains unchanged.
      [
        'article (2)',
        base_path() . 'search-api-test-fulltext?f%5B0%5D=llama%3Aarticle',
        'llama:article',
        FALSE,
      ],
    ];
+2 −0
Original line number Diff line number Diff line
@@ -171,6 +171,7 @@ class DefaultFacetManagerTest extends EntityKernelTestBase {
      $query->getCacheContexts(),
      $facet_mars->getFacetSource()->getCacheContexts(),
      [
        'facets_filter:f',
        'fpc_query_type_plugin',
        'dummy_query_pre_query',
      ]
@@ -334,6 +335,7 @@ class DefaultFacetManagerTest extends EntityKernelTestBase {
        // Added by views view source plugin.
        'url',
        'languages:language_interface',
        'facets_filter:f',
      ],
      'tags' => [
        // Facet controls query and look & feel of the facet results, so it's
Loading