Adjusted tests.
This commit is contained in:
+23
-10
@@ -8,9 +8,21 @@ use Doctrine\ORM\EntityManager;
|
||||
use Monolog\Logger;
|
||||
use Monolog\Handler\NullHandler;
|
||||
|
||||
use LotGD\Core\{
|
||||
Action, ActionGroup, Bootstrap, Configuration, ComposerManager, DiceBag, EventHandler, EventManager, Events\NewViewpointData, Game, GameBuilder, TimeKeeper, ModuleManager
|
||||
};
|
||||
use LotGD\Core\{Action,
|
||||
ActionGroup,
|
||||
Bootstrap,
|
||||
Configuration,
|
||||
ComposerManager,
|
||||
DiceBag,
|
||||
EventHandler,
|
||||
EventManager,
|
||||
Events\NewViewpointData,
|
||||
Game,
|
||||
GameBuilder,
|
||||
Tests\SceneTemplates\ParameterTestSceneTemplate,
|
||||
Tests\SceneTemplates\VillageSceneTemplate,
|
||||
TimeKeeper,
|
||||
ModuleManager};
|
||||
use LotGD\Core\Models\{
|
||||
Character, Viewpoint, Scene
|
||||
};
|
||||
@@ -40,7 +52,7 @@ class DefaultSceneProvider implements EventHandler
|
||||
$context->setDataField("scene", $g->getEntityManager()->getRepository(Scene::class)
|
||||
->find("30000000-0000-0000-0000-000000000001"));
|
||||
break;
|
||||
case 'h/lotgd/core/navigate-to/lotgd/tests/village':
|
||||
case "h/lotgd/core/navigate-to/".VillageSceneTemplate::getNavigationEvent();
|
||||
$v = $context->getDataField('viewpoint');
|
||||
|
||||
self::$actionGroups = [new ActionGroup('default', 'Title', 0)];
|
||||
@@ -54,7 +66,7 @@ class DefaultSceneProvider implements EventHandler
|
||||
$v->setData(self::$data);
|
||||
break;
|
||||
|
||||
case 'h/lotgd/core/navigate-to/lotgd/tests/paramaters':
|
||||
case "h/lotgd/core/navigate-to/".ParameterTestSceneTemplate::getNavigationEvent():
|
||||
/* @var Viewpoint $v //*/
|
||||
$v = $context->getDataField('viewpoint');
|
||||
/* @var array //*/
|
||||
@@ -164,8 +176,9 @@ class GameTest extends CoreModelTestCase
|
||||
|
||||
$v = $this->g->getViewpoint();
|
||||
// Run it twice to make sure no additional DB operations happen.
|
||||
/** @var Viewpoint $v */
|
||||
$v = $this->g->getViewpoint();
|
||||
$this->assertEquals('lotgd/tests/village', $v->getTemplate());
|
||||
$this->assertSame(VillageSceneTemplate::class, $v->getTemplate()->getClass());
|
||||
|
||||
// Validate the changes made by the hook.
|
||||
$this->assertSame(DefaultSceneProvider::$actionGroups, $v->getActionGroups());
|
||||
@@ -215,7 +228,7 @@ class GameTest extends CoreModelTestCase
|
||||
$this->g->setCharacter($c);
|
||||
|
||||
// subscribe event
|
||||
$this->g->getEventManager()->subscribe('#h/lotgd/core/navigate-to/lotgd/tests/paramaters#', DefaultSceneProvider::class, 'lotgd/core/tests');
|
||||
$this->g->getEventManager()->subscribe('#'.ParameterTestSceneTemplate::getNavigationEvent().'#', DefaultSceneProvider::class, 'lotgd/core/tests');
|
||||
$this->getEntityManager()->flush();
|
||||
|
||||
$action = new Action("30000000-0000-0000-0000-000000000007", null, ["foo" => "baz"]);
|
||||
@@ -235,7 +248,7 @@ class GameTest extends CoreModelTestCase
|
||||
$this->assertSame("Parameter is baz.", $v->getDescription());
|
||||
|
||||
// unsubscribe event
|
||||
$this->g->getEventManager()->unsubscribe('#h/lotgd/core/navigate-to/lotgd/tests/paramaters#', DefaultSceneProvider::class, 'lotgd/core/tests');
|
||||
$this->g->getEventManager()->unsubscribe('#'.ParameterTestSceneTemplate::getNavigationEvent().'#', DefaultSceneProvider::class, 'lotgd/core/tests');
|
||||
}
|
||||
|
||||
public function testIfActionParametersTakePriorityToOtherParameters()
|
||||
@@ -245,7 +258,7 @@ class GameTest extends CoreModelTestCase
|
||||
$this->g->setCharacter($c);
|
||||
|
||||
// subscribe event
|
||||
$this->g->getEventManager()->subscribe('#h/lotgd/core/navigate-to/lotgd/tests/paramaters#', DefaultSceneProvider::class, 'lotgd/core/tests');
|
||||
$this->g->getEventManager()->subscribe('#'.ParameterTestSceneTemplate::getNavigationEvent().'#', DefaultSceneProvider::class, 'lotgd/core/tests');
|
||||
$this->getEntityManager()->flush();
|
||||
|
||||
$action = new Action("30000000-0000-0000-0000-000000000007", null, ["foo" => "baz"]);
|
||||
@@ -265,7 +278,7 @@ class GameTest extends CoreModelTestCase
|
||||
$this->assertSame("Parameter is baz.", $v->getDescription());
|
||||
|
||||
// unsubscribe event
|
||||
$this->g->getEventManager()->unsubscribe('#h/lotgd/core/navigate-to/lotgd/tests/paramaters#', DefaultSceneProvider::class, 'lotgd/core/tests');
|
||||
$this->g->getEventManager()->unsubscribe('#'.ParameterTestSceneTemplate::getNavigationEvent().'#', DefaultSceneProvider::class, 'lotgd/core/tests');
|
||||
}
|
||||
|
||||
public function testIfActionsAreAddedAsExpected()
|
||||
|
||||
@@ -4,8 +4,9 @@ declare(strict_types=1);
|
||||
namespace LotGD\Core\Tests\Models;
|
||||
|
||||
use LotGD\Core\Exceptions\ArgumentException;
|
||||
use LotGD\Core\Models\{Scene, SceneConnection, SceneConnectionGroup};
|
||||
use LotGD\Core\Models\{Scene, SceneConnection, SceneConnectionGroup, SceneTemplate};
|
||||
use LotGD\Core\Tests\CoreModelTestCase;
|
||||
use LotGD\Core\Tests\SceneTemplates\NewSceneSceneTemplate;
|
||||
|
||||
/**
|
||||
* Tests for creating scenes and moving them around.
|
||||
@@ -38,7 +39,7 @@ class SceneModelTest extends CoreModelTestCase
|
||||
return [
|
||||
"title" => "A new scene",
|
||||
"description" => "This is a new scene",
|
||||
"template" => "lotgd/test/new-scene"
|
||||
"template" => $this->getEntityManager()->getRepository(SceneTemplate::class)->find(NewSceneSceneTemplate::class),
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -3,9 +3,13 @@ declare(strict_types=1);
|
||||
|
||||
namespace LotGD\Core\Tests\Models;
|
||||
|
||||
use Composer\Repository\RepositoryInterface;
|
||||
use Doctrine\Common\Persistence\ObjectRepository;
|
||||
use Doctrine\ORM\EntityManager;
|
||||
use LotGD\Core\Action;
|
||||
use LotGD\Core\ActionGroup;
|
||||
use LotGD\Core\Models\Scene;
|
||||
use LotGD\Core\Models\SceneTemplate;
|
||||
use LotGD\Core\Models\Viewpoint;
|
||||
use LotGD\Core\Tests\CoreModelTestCase;
|
||||
|
||||
@@ -29,10 +33,18 @@ class ViewpointRestorationTest extends CoreModelTestCase
|
||||
|
||||
protected function getViewpoint()
|
||||
{
|
||||
$sceneTemplateMock = $this->createMock(SceneTemplate::class);
|
||||
|
||||
$sceneMock = $this->createMock(Scene::class);
|
||||
$sceneMock->method("getTitle")->willReturn("Scene Mock Title");
|
||||
$sceneMock->method("getDescription")->willReturn("Scene Mock Description");
|
||||
$sceneMock->method("getTemplate")->willReturn("lotgd/scene-mock-template");
|
||||
$sceneMock->method("getTemplate")->willReturn($sceneTemplateMock);
|
||||
|
||||
$repository = $this->createMock(ObjectRepository::class);
|
||||
$repository->method("find")->willReturn($sceneTemplateMock);
|
||||
|
||||
$entityManager = $this->createMock(EntityManager::class);
|
||||
$entityManager->method("getRepository")->willReturn($repository);
|
||||
|
||||
$actionGroup = $this->getActionGroup();
|
||||
|
||||
@@ -40,31 +52,39 @@ class ViewpointRestorationTest extends CoreModelTestCase
|
||||
$viewpoint->changeFromScene($sceneMock);
|
||||
$viewpoint->setActionGroups([$actionGroup]);
|
||||
|
||||
return $viewpoint;
|
||||
return [$entityManager, $viewpoint];
|
||||
}
|
||||
|
||||
protected function getAlternativeViewpoint()
|
||||
{
|
||||
$sceneTemplateMock = $this->createMock(SceneTemplate::class);
|
||||
|
||||
$sceneMock = $this->createMock(Scene::class);
|
||||
$sceneMock->method("getTitle")->willReturn("Another Scene Mock Title");
|
||||
$sceneMock->method("getDescription")->willReturn("Another Scene Mock Description");
|
||||
$sceneMock->method("getTemplate")->willReturn("lotgd/scene-mock-template/another");
|
||||
$sceneMock->method("getTemplate")->willReturn($sceneTemplateMock);
|
||||
|
||||
$repository = $this->createMock(ObjectRepository::class);
|
||||
$repository->method("find")->willReturn($sceneTemplateMock);
|
||||
|
||||
$entityManager = $this->createMock(EntityManager::class);
|
||||
$entityManager->method("getRepository")->willReturn($repository);
|
||||
|
||||
$viewpoint = new Viewpoint();
|
||||
$viewpoint->changeFromScene($sceneMock);
|
||||
|
||||
return $viewpoint;
|
||||
return [$entityManager, $viewpoint];
|
||||
}
|
||||
|
||||
public function testIfViewpointAfterUnserializationIsEqualToBeforeItsSerialization()
|
||||
{
|
||||
$viewpoint = $this->getViewpoint();
|
||||
$viewpointRestoration = $this->getViewpoint()->getSnapshot();
|
||||
[$entityManager, $viewpoint] = $this->getViewpoint();
|
||||
$viewpointRestoration = $viewpoint->getSnapshot();
|
||||
$serialized = serialize($viewpointRestoration);
|
||||
$viewpointRestored = unserialize($serialized);
|
||||
|
||||
$newViewpoint = $this->getAlternativeViewpoint();
|
||||
$newViewpoint->changeFromSnapshot($viewpointRestored);
|
||||
[$entityManager2, $newViewpoint] = $this->getAlternativeViewpoint();
|
||||
$newViewpoint->changeFromSnapshot($entityManager, $viewpointRestored);
|
||||
|
||||
$this->assertSame($viewpoint->getTitle(), $newViewpoint->getTitle());
|
||||
$this->assertSame($viewpoint->getDescription(), $newViewpoint->getDescription());
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
|
||||
namespace LotGD\Core\Tests\SceneTemplates;
|
||||
|
||||
|
||||
use LotGD\Core\SceneTemplates\BasicSceneTemplate;
|
||||
|
||||
class NewSceneSceneTemplate extends BasicSceneTemplate
|
||||
{
|
||||
public static function getNavigationEvent(): string
|
||||
{
|
||||
return "tests/new-scene";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
|
||||
namespace LotGD\Core\Tests\SceneTemplates;
|
||||
|
||||
|
||||
use LotGD\Core\SceneTemplates\BasicSceneTemplate;
|
||||
|
||||
class ParameterTestSceneTemplate extends BasicSceneTemplate
|
||||
{
|
||||
public static function getNavigationEvent(): string
|
||||
{
|
||||
return "tests/parameter";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
|
||||
namespace LotGD\Core\Tests\SceneTemplates;
|
||||
|
||||
|
||||
use LotGD\Core\SceneTemplates\BasicSceneTemplate;
|
||||
|
||||
class VillageSceneTemplate extends BasicSceneTemplate
|
||||
{
|
||||
public static function getNavigationEvent(): string
|
||||
{
|
||||
return "tests/village";
|
||||
}
|
||||
}
|
||||
+14
-5
@@ -25,7 +25,7 @@ scenes:
|
||||
id: "30000000-0000-0000-0000-000000000001"
|
||||
title: "The Village"
|
||||
description: "This is the village."
|
||||
template: "lotgd/tests/village"
|
||||
template: "LotGD\\Core\\Tests\\SceneTemplates\\VillageSceneTemplate"
|
||||
-
|
||||
id: "30000000-0000-0000-0000-000000000002"
|
||||
title: "The Forest"
|
||||
@@ -40,22 +40,31 @@ scenes:
|
||||
id: "30000000-0000-0000-0000-000000000004"
|
||||
title: "Parent Scene"
|
||||
description: "This is a parent scene that connects to two children."
|
||||
template: "lotgd/tests/none"
|
||||
template:
|
||||
-
|
||||
id: "30000000-0000-0000-0000-000000000005"
|
||||
title: "Child Scene 1"
|
||||
description: "This is a parent scene that connects to two children."
|
||||
template: "lotgd/tests/none"
|
||||
template:
|
||||
-
|
||||
id: "30000000-0000-0000-0000-000000000006"
|
||||
title: "Child Scene 2"
|
||||
description: "This is a parent scene that connects to two children."
|
||||
template: "lotgd/tests/none"
|
||||
template:
|
||||
-
|
||||
id: "30000000-0000-0000-0000-000000000007"
|
||||
title: "Parameter test"
|
||||
description: "This is a parameter test"
|
||||
template: "lotgd/tests/paramaters"
|
||||
template: "LotGD\\Core\\Tests\\SceneTemplates\\ParameterTestSceneTemplate"
|
||||
scene_templates:
|
||||
-
|
||||
class: "LotGD\\Core\\Tests\\SceneTemplates\\VillageSceneTemplate"
|
||||
module: "lotgd/core"
|
||||
userAssignable: true
|
||||
-
|
||||
class: "LotGD\\Core\\Tests\\SceneTemplates\\ParameterTestSceneTemplate"
|
||||
module: "lotgd/core"
|
||||
userAssignable: true
|
||||
scene_connection_groups:
|
||||
-
|
||||
scene: "30000000-0000-0000-0000-000000000004"
|
||||
|
||||
@@ -50,4 +50,9 @@ scene_connections:
|
||||
incomingScene: "30000000-0000-0000-0000-000000000003"
|
||||
-
|
||||
outgoingScene: "30000000-0000-0000-0000-000000000001"
|
||||
incomingScene: "30000000-0000-0000-0000-000000000004"
|
||||
incomingScene: "30000000-0000-0000-0000-000000000004"
|
||||
scene_templates:
|
||||
-
|
||||
class: "LotGD\\Core\\Tests\\SceneTemplates\\NewSceneSceneTemplate"
|
||||
module: "lotgd/core"
|
||||
userAssignable: true
|
||||
Reference in New Issue
Block a user