function NodeAdminTest::testContentAdminSort in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/node/src/Tests/NodeAdminTest.php \Drupal\node\Tests\NodeAdminTest::testContentAdminSort()
Tests that the table sorting works on the content admin pages.
File
- core/
modules/ node/ src/ Tests/ NodeAdminTest.php, line 70 - Contains \Drupal\node\Tests\NodeAdminTest.
Class
- NodeAdminTest
- Tests node administration page functionality.
Namespace
Drupal\node\TestsCode
function testContentAdminSort() {
$this
->drupalLogin($this->adminUser);
$changed = REQUEST_TIME;
foreach (array(
'dd',
'aa',
'DD',
'bb',
'cc',
'CC',
'AA',
'BB',
) as $prefix) {
$changed += 1000;
$node = $this
->drupalCreateNode(array(
'title' => $prefix . $this
->randomMachineName(6),
));
db_update('node_field_data')
->fields(array(
'changed' => $changed,
))
->condition('nid', $node
->id())
->execute();
}
// Test that the default sort by node.changed DESC actually fires properly.
$nodes_query = db_select('node_field_data', 'n')
->fields('n', array(
'title',
))
->orderBy('changed', 'DESC')
->execute()
->fetchCol();
$this
->drupalGet('admin/content');
foreach ($nodes_query as $delta => $string) {
$elements = $this
->xpath('//table[contains(@class, :class)]/tbody/tr[' . ($delta + 1) . ']/td[2]/a[normalize-space(text())=:label]', array(
':class' => 'views-table',
':label' => $string,
));
$this
->assertTrue(!empty($elements), 'The node was found in the correct order.');
}
// Compare the rendered HTML node list to a query for the nodes ordered by
// title to account for possible database-dependent sort order.
$nodes_query = db_select('node_field_data', 'n')
->fields('n', array(
'title',
))
->orderBy('title')
->execute()
->fetchCol();
$this
->drupalGet('admin/content', array(
'query' => array(
'sort' => 'asc',
'order' => 'title',
),
));
foreach ($nodes_query as $delta => $string) {
$elements = $this
->xpath('//table[contains(@class, :class)]/tbody/tr[' . ($delta + 1) . ']/td[2]/a[normalize-space(text())=:label]', array(
':class' => 'views-table',
':label' => $string,
));
$this
->assertTrue(!empty($elements), 'The node was found in the correct order.');
}
}