ItemsPerPageTest.php in Zircon Profile 8.0
File
core/modules/views/src/Tests/Wizard/ItemsPerPageTest.php
View source
<?php
namespace Drupal\views\Tests\Wizard;
class ItemsPerPageTest extends WizardTestBase {
protected function setUp() {
parent::setUp();
$this
->drupalPlaceBlock('page_title_block');
}
function testItemsPerPage() {
$this
->drupalCreateContentType(array(
'type' => 'article',
));
$node1 = $this
->drupalCreateNode(array(
'type' => 'article',
'created' => REQUEST_TIME,
));
$node2 = $this
->drupalCreateNode(array(
'type' => 'article',
'created' => REQUEST_TIME + 1,
));
$node3 = $this
->drupalCreateNode(array(
'type' => 'article',
'created' => REQUEST_TIME + 2,
));
$node4 = $this
->drupalCreateNode(array(
'type' => 'article',
'created' => REQUEST_TIME + 3,
));
$node5 = $this
->drupalCreateNode(array(
'type' => 'article',
'created' => REQUEST_TIME + 4,
));
$page_node = $this
->drupalCreateNode(array(
'type' => 'page',
'created' => REQUEST_TIME + 2,
));
$view = array();
$view['label'] = $this
->randomMachineName(16);
$view['id'] = strtolower($this
->randomMachineName(16));
$view['description'] = $this
->randomMachineName(16);
$view['show[wizard_key]'] = 'node';
$view['show[type]'] = 'article';
$view['show[sort]'] = 'node_field_data-created:DESC';
$view['page[create]'] = 1;
$view['page[title]'] = $this
->randomMachineName(16);
$view['page[path]'] = $this
->randomMachineName(16);
$view['page[items_per_page]'] = 4;
$view['block[create]'] = 1;
$view['block[title]'] = $this
->randomMachineName(16);
$view['block[items_per_page]'] = 3;
$this
->drupalPostForm('admin/structure/views/add', $view, t('Save and edit'));
$this
->drupalGet($view['page[path]']);
$this
->assertResponse(200);
$this
->assertUrl($view['page[path]']);
$this
->assertText($view['page[title]']);
$content = $this
->getRawContent();
$this
->assertText($node5
->label());
$this
->assertText($node4
->label());
$this
->assertText($node3
->label());
$this
->assertText($node2
->label());
$this
->assertNoText($node1
->label());
$this
->assertNoText($page_node
->label());
$pos5 = strpos($content, $node5
->label());
$pos4 = strpos($content, $node4
->label());
$pos3 = strpos($content, $node3
->label());
$pos2 = strpos($content, $node2
->label());
$this
->assertTrue($pos5 < $pos4 && $pos4 < $pos3 && $pos3 < $pos2, 'The nodes appear in the expected order in the page display.');
$this
->drupalGet('admin/structure/block/list/' . $this
->config('system.theme')
->get('default'));
$this
->clickLinkPartialName('Place block');
$this
->assertText($view['label']);
$this
->drupalPlaceBlock("views_block:{$view['id']}-block_1");
$this
->drupalGet('user');
$content = $this
->getRawContent();
$this
->assertText($node5
->label());
$this
->assertText($node4
->label());
$this
->assertText($node3
->label());
$this
->assertNoText($node2
->label());
$this
->assertNoText($node1
->label());
$this
->assertNoText($page_node
->label());
$pos5 = strpos($content, $node5
->label());
$pos4 = strpos($content, $node4
->label());
$pos3 = strpos($content, $node3
->label());
$this
->assertTrue($pos5 < $pos4 && $pos4 < $pos3, 'The nodes appear in the expected order in the block display.');
}
}
Classes
Name |
Description |
ItemsPerPageTest |
Tests the ability of the views wizard to specify the number of items per
page. |