Same name and namespace in other branches
  1. 8.x-1.x tests/src/FunctionalJavascript/EntityReferenceAjaxFormatterTest.php \Drupal\Tests\entity_reference_ajax_formatter\FunctionalJavascript\EntityReferenceAjaxFormatterTest::testFormatter() 1 comment

Tests the behavior of the 'entity_reference_ajax_entity_view' formatter.

File

tests/src/FunctionalJavascript/EntityReferenceAjaxFormatterTest.php, line 51

Class

EntityReferenceAjaxFormatterTest
Test the Entity Reference Ajax Formatter.

Namespace

Drupal\Tests\entity_reference_ajax_formatter\FunctionalJavascript

Code

public function testFormatter() : void {
    $this->drupalGet("node/{$this->node->id()}");
    $session = $this->assertSession();
    $session->pageTextContains('Node #1');
    $session->pageTextNotContains('Node #2');
    $session->pageTextNotContains('Load More');
    // Test random sort.
    $this->display
        ->setComponent('field_ref', [
        'type' => 'entity_reference_ajax_entity_view',
        'settings' => [
            'number' => 3,
            'sort' => 1,
            'load_more' => TRUE,
            'max' => 8,
        ],
    ])
        ->save();
    $this->drupalGet("node/{$this->node->id()}");
    $page = $this->getSession()
        ->getPage();
    $this->assertSame(count($page->findAll('css', '.layout-content [role="article"] [role="article"]')), 3);
    $session->pageTextMatches('/Node #(\\d\\d|[^123])/');
    $session->pageTextContains('Load More');
    $page->clickLink('Load More');
    $session->assertWaitOnAjaxRequest();
    $this->assertSame(count($page->findAll('css', '.layout-content [role="article"] [role="article"]')), 6);
    $session->pageTextContains('Load More');
    $page->clickLink('Load More');
    $session->assertWaitOnAjaxRequest();
    $this->assertSame(count($page->findAll('css', '.layout-content [role="article"] [role="article"]')), 8);
    $session->pageTextNotContains('Load More');
}