function ViewsModerationStateSortTest::testSortBaseTable
Same name and namespace in other branches
- 9 core/modules/content_moderation/tests/src/Kernel/ViewsModerationStateSortTest.php \Drupal\Tests\content_moderation\Kernel\ViewsModerationStateSortTest::testSortBaseTable()
- 8.9.x core/modules/content_moderation/tests/src/Kernel/ViewsModerationStateSortTest.php \Drupal\Tests\content_moderation\Kernel\ViewsModerationStateSortTest::testSortBaseTable()
- 10 core/modules/content_moderation/tests/src/Kernel/ViewsModerationStateSortTest.php \Drupal\Tests\content_moderation\Kernel\ViewsModerationStateSortTest::testSortBaseTable()
Tests sorting with a standard data base table.
File
-
core/
modules/ content_moderation/ tests/ src/ Kernel/ ViewsModerationStateSortTest.php, line 68
Class
- ViewsModerationStateSortTest
- Tests the views moderation_state field sorting integration.
Namespace
Drupal\Tests\content_moderation\KernelCode
public function testSortBaseTable() : void {
$this->enableModules([
'content_moderation_test_views',
]);
$this->installConfig([
'content_moderation_test_views',
]);
// Create two revisions. The sorted revision will be 'zz_draft' since it
// will be attached to the default revision of the entity.
$first_node = Node::create([
'type' => 'example',
'title' => 'Foo',
'moderation_state' => 'aa_draft',
]);
$first_node->save();
$first_node->moderation_state = 'zz_draft';
$first_node->save();
// Create a second published node, which falls between aa_draft and zz_draft
// for the purposes of testing.
$second_node = Node::create([
'type' => 'example',
'title' => 'Foo',
'moderation_state' => 'published',
]);
$second_node->save();
// Ascending order will see 'published' followed by 'zz_draft'.
$this->assertSortResults('test_content_moderation_state_sort_base_table', 'nid', 'ASC', [
[
'nid' => $second_node->id(),
],
[
'nid' => $first_node->id(),
],
]);
// Descending will reverse the order.
$this->assertSortResults('test_content_moderation_state_sort_base_table', 'nid', 'DESC', [
[
'nid' => $first_node->id(),
],
[
'nid' => $second_node->id(),
],
]);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.