public function StyleSerializerTest::testRestViewExposedFilter in Zircon Profile 8.0
Same name and namespace in other branches
- 8 core/modules/rest/src/Tests/Views/StyleSerializerTest.php \Drupal\rest\Tests\Views\StyleSerializerTest::testRestViewExposedFilter()
Tests the exposed filter works.
There is an exposed filter on the title field which takes a title query parameter. This is set to filter nodes by those whose title starts with the value provided.
File
- core/
modules/ rest/ src/ Tests/ Views/ StyleSerializerTest.php, line 620 - Contains \Drupal\rest\Tests\Views\StyleSerializerTest.
Class
- StyleSerializerTest
- Tests the serializer style plugin.
Namespace
Drupal\rest\Tests\ViewsCode
public function testRestViewExposedFilter() {
$this
->drupalCreateContentType(array(
'type' => 'page',
));
$node0 = $this
->drupalCreateNode(array(
'title' => 'Node 1',
));
$node1 = $this
->drupalCreateNode(array(
'title' => 'Node 11',
));
$node2 = $this
->drupalCreateNode(array(
'title' => 'Node 111',
));
// Test that no filter brings back all three nodes.
$result = $this
->drupalGetJSON('test/serialize/node-exposed-filter');
$expected = array(
0 => array(
'nid' => $node0
->id(),
'body' => $node0->body->processed,
),
1 => array(
'nid' => $node1
->id(),
'body' => $node1->body->processed,
),
2 => array(
'nid' => $node2
->id(),
'body' => $node2->body->processed,
),
);
$this
->assertEqual($result, $expected, 'Querying a view with no exposed filter returns all nodes.');
// Test that title starts with 'Node 11' query finds 2 of the 3 nodes.
$result = $this
->drupalGetJSON('test/serialize/node-exposed-filter', [
'query' => [
'title' => 'Node 11',
],
]);
$expected = array(
0 => array(
'nid' => $node1
->id(),
'body' => $node1->body->processed,
),
1 => array(
'nid' => $node2
->id(),
'body' => $node2->body->processed,
),
);
$cache_contexts = [
'languages:language_content',
'languages:language_interface',
'theme',
'request_format',
'user.node_grants:view',
'url',
];
$this
->assertEqual($result, $expected, 'Querying a view with a starts with exposed filter on the title returns nodes whose title starts with value provided.');
$this
->assertCacheContexts($cache_contexts);
}