function RelationshipNodeFileDataTest::testViewsHandlerRelationshipNodeToFile
Same name in other branches
- 11.x core/modules/file/tests/src/Kernel/Views/RelationshipNodeFileDataTest.php \Drupal\Tests\file\Kernel\Views\RelationshipNodeFileDataTest::testViewsHandlerRelationshipNodeToFile()
Tests using the views node_to_file relationship.
File
-
core/
modules/ file/ tests/ src/ Kernel/ Views/ RelationshipNodeFileDataTest.php, line 132
Class
- RelationshipNodeFileDataTest
- Tests file on node relationship handler.
Namespace
Drupal\Tests\file\Kernel\ViewsCode
public function testViewsHandlerRelationshipNodeToFile() : void {
$file1 = File::create([
'filename' => 'image-test.jpg',
'uri' => "public://image-test.jpg",
'filemime' => 'image/jpeg',
'created' => 1,
'changed' => 1,
'status' => FileInterface::STATUS_PERMANENT,
]);
$file1->enforceIsNew();
file_put_contents($file1->getFileUri(), file_get_contents('core/tests/fixtures/files/image-1.png'));
$file1->save();
$file2 = File::create([
'filename' => 'image-test-2.jpg',
'uri' => "public://image-test-2.jpg",
'filemime' => 'image/jpeg',
'created' => 1,
'changed' => 1,
'status' => FileInterface::STATUS_PERMANENT,
]);
$file2->enforceIsNew();
file_put_contents($file2->getFileUri(), file_get_contents('core/tests/fixtures/files/image-1.png'));
$file2->save();
$node1 = Node::create([
'type' => 'file_test',
'title' => $this->randomMachineName(8),
'created' => 1,
'changed' => 1,
'status' => NodeInterface::PUBLISHED,
]);
$node1->save();
$node2 = Node::create([
'type' => 'file_test',
'title' => $this->randomMachineName(8),
'created' => 1,
'changed' => 1,
'status' => NodeInterface::PUBLISHED,
'node_file' => [
'target_id' => $file2->id(),
],
]);
$node2->save();
$view = Views::getView('test_node_to_file');
$this->executeView($view);
// We should only see a single file, the one on the user account. The other
// account's UUID, nor the other unlinked file, should appear in the
// results.
$expected_result = [
[
'fid' => $file2->id(),
'nid' => $node2->id(),
],
];
$column_map = [
'fid' => 'fid',
'nid' => 'nid',
];
$this->assertIdenticalResultset($view, $expected_result, $column_map);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.