Adds tests to check scene properties.

This commit is contained in:
Vassyli
2021-01-14 20:34:35 +01:00
committed by Basilius Sauter
parent 96feb12fb5
commit 1a0b6dbe3e
2 changed files with 96 additions and 0 deletions
+85
View File
@@ -0,0 +1,85 @@
<?php
declare(strict_types=1);
namespace LotGD\Core\Tests\Models;
use LotGD\Core\Models\Scene;
use LotGD\Core\Models\SceneProperty;
use LotGD\Core\Tests\CoreModelTestCase;
class ScenePropertyTest extends CoreModelTestCase
{
/** @var string default data set */
protected $dataset = "scene-property";
public function testIfScenePropertyCanBeRetrieved()
{
$em = $this->getEntityManager();
# Retrieve scene
$scene = $em->getRepository(Scene::class)->find("30000000-0000-0000-0000-000000000001");
# Fetch property, with default "false".
# Must return true, as this is whats in our dataset
$value = $scene->getProperty("lotgd/core/tests/property/dataset", false);
# Assert the value
$this->assertTrue($value);
}
public function testIfPropertyCanBeSaved()
{
$em = $this->getEntityManager();
# Retrieve scene
$scene = $em->getRepository(Scene::class)->find("30000000-0000-0000-0000-000000000001");
# Set a property
$scene->setProperty("lotgd/core/tests/newProperty", "test-value");
# Get the property value back
$value = $scene->getProperty("lotgd/core/tests/newProperty", null);
# Assert the value
$this->assertSame("test-value", $value);
# Save and clear entity manager, the fetch again.
# Persisting the property should not be necessary
unset($value);
$em->flush();
$em->clear();
# Retrieve scene (again)
$scene = $em->getRepository(Scene::class)->find("30000000-0000-0000-0000-000000000001");
# Get a property
$value = $scene->getProperty("lotgd/core/tests/newProperty", null);
# Assert the value
$this->assertSame("test-value", $value);
}
public function testIfSceneRemovalRemovesPropertyToo()
{
$em = $this->getEntityManager();
# Retrieve scene
$scene = $em->getRepository(Scene::class)->find("30000000-0000-0000-0000-000000000001");
# Delete scene
$em->remove($scene);
$em->flush();
$em->clear();
# Retrieve properties
$sceneProperties = $em->getRepository(SceneProperty::class)->findAll();
# Get all property names
$listOfPropertyNames = [];
foreach ($sceneProperties as $property) {
$listOfPropertyNames[$property->getName()] = $property->getValue();
}
$this->assertArrayNotHasKey("lotgd/core/tests/property/dataset", $listOfPropertyNames);
}
}
+11
View File
@@ -0,0 +1,11 @@
scenes:
-
id: "30000000-0000-0000-0000-000000000001"
title: "A scene"
description: "This is the village."
template: "lotgd/tests/village"
scene_properties:
-
owner: "30000000-0000-0000-0000-000000000001"
propertyName: "lotgd/core/tests/property/dataset"
propertyValue: "b:1;"