View source
<?php
namespace Drupal\Tests\entity_browser\FunctionalJavascript;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
class PagerElementTest extends EntityBrowserWebDriverTestBase {
public static $modules = [
'entity_browser_test',
'node',
'field_ui',
'views_ui',
'system',
];
protected function setUp() {
parent::setUp();
$this
->drupalCreateContentType([
'type' => 'foo',
'name' => 'Foo',
]);
FieldStorageConfig::create([
'field_name' => 'field_reference_pager',
'type' => 'entity_reference',
'entity_type' => 'node',
'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED,
'settings' => [
'target_type' => 'node',
],
])
->save();
FieldConfig::create([
'field_name' => 'field_reference_pager',
'entity_type' => 'node',
'bundle' => 'foo',
'label' => 'Reference',
'settings' => [],
])
->save();
$form_display = $this->container
->get('entity_type.manager')
->getStorage('entity_form_display')
->load('node.foo.default');
$form_display
->setComponent('field_reference_pager', [
'type' => 'entity_browser_entity_reference',
'settings' => [
'entity_browser' => 'pager',
'field_widget_display' => 'label',
'open' => TRUE,
],
])
->save();
$account = $this
->drupalCreateUser([
'access pager entity browser pages',
'create foo content',
'access content',
]);
$this
->drupalLogin($account);
}
public function testPagerElement() {
$this
->drupalGet('/entity-browser/iframe/pager');
$this
->assertSession()
->pageTextContains('Current page reported by the element is: 1.');
$this
->assertSession()
->buttonExists('‹ Previous')
->hasAttribute('disabled');
$this
->assertSession()
->pageTextContains('Page 1');
$this
->assertSession()
->buttonExists('Next ›');
$this
->getSession()
->getPage()
->pressButton('Next ›');
$this
->assertSession()
->pageTextContains('Current page reported by the element is: 2.');
$this
->assertSession()
->pageTextContains('Page 2');
$this
->getSession()
->getPage()
->pressButton('Next ›');
$this
->assertSession()
->pageTextContains('Current page reported by the element is: 3.');
$this
->assertSession()
->pageTextContains('Page 3');
$this
->getSession()
->getPage()
->pressButton('Next ›');
$this
->assertSession()
->pageTextContains('Current page reported by the element is: 4.');
$this
->assertSession()
->pageTextContains('Page 4');
$this
->assertSession()
->buttonExists('Next ›')
->hasAttribute('disabled');
$this
->getSession()
->getPage()
->pressButton('‹ Previous');
$this
->assertSession()
->pageTextContains('Current page reported by the element is: 3.');
$this
->assertSession()
->pageTextContains('Page 3');
$this
->getSession()
->getPage()
->pressButton('‹ Previous');
$this
->assertSession()
->pageTextContains('Current page reported by the element is: 2.');
$this
->assertSession()
->pageTextContains('Page 2');
$this
->getSession()
->getPage()
->pressButton('‹ Previous');
$this
->assertSession()
->pageTextContains('Current page reported by the element is: 1.');
$this
->assertSession()
->pageTextContains('Page 1');
$this
->assertSession()
->buttonExists('‹ Previous')
->hasAttribute('disabled');
$this
->getSession()
->getPage()
->pressButton('Last page');
$this
->assertSession()
->pageTextContains('Current page reported by the element is: 4.');
$this
->assertSession()
->pageTextContains('Page 4');
$this
->getSession()
->getPage()
->pressButton('First page');
$this
->assertSession()
->pageTextContains('Current page reported by the element is: 1.');
$this
->assertSession()
->pageTextContains('Page 1');
}
}