From b06bfe3512a69628057dadd2fe4aede2e927957e Mon Sep 17 00:00:00 2001 From: Pieter Frenssen Date: Tue, 8 Oct 2019 14:13:16 +0300 Subject: [PATCH] Test that a default graph is set when an entity is created. --- tests/src/Kernel/EntityCreationTest.php | 29 +++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/tests/src/Kernel/EntityCreationTest.php b/tests/src/Kernel/EntityCreationTest.php index 61a6494..2655836 100644 --- a/tests/src/Kernel/EntityCreationTest.php +++ b/tests/src/Kernel/EntityCreationTest.php @@ -4,6 +4,8 @@ namespace Drupal\Tests\sparql_entity_storage\Kernel; +use Drupal\rdf_entity\RdfInterface; +use Drupal\sparql_entity_storage\Entity\SparqlGraph; use Drupal\sparql_entity_storage\Exception\DuplicatedIdException; use Drupal\sparql_test\Entity\SparqlTest; @@ -49,4 +51,31 @@ public function testOverlappingIds(): void { ])->save(); } + /** + * Tests that the default graph is set on entity creation. + * + * @covers ::create + */ + public function testDefaultGraphSetOnCreate(): void { + // Check that the default graph is set when no graph is specified. + $entity = SparqlTest::create([ + 'type' => 'waffle', + 'id' => 'http://example.com/kempense-galet', + 'title' => 'Kempense galet', + ]); + + $this->assertEquals(SparqlGraph::DEFAULT, $entity->get('graph')->target_id); + + // Check that it is possible to specify a custom graph. + /** @var \Drupal\rdf_entity\RdfInterface $entity */ + $entity = SparqlTest::create([ + 'type' => 'waffle', + 'id' => 'http://example.com/liege-waffle', + 'title' => 'Liège waffle', + 'graph' => 'custom_graph', + ]); + + $this->assertEquals('custom_graph', $entity->get('graph')->target_id); + } + }