55namespace Flowpack \NodeTemplates \Tests \Functional \Features \StandaloneValidationCommand ;
66
77use Flowpack \NodeTemplates \Application \Command \NodeTemplateCommandController ;
8- use Flowpack \NodeTemplates \Domain \NodeTemplateDumper \NodeTemplateDumper ;
9- use Flowpack \NodeTemplates \Domain \Template \RootTemplate ;
8+ use Flowpack \NodeTemplates \Tests \Functional \ContentRepositoryTestTrait ;
109use Flowpack \NodeTemplates \Tests \Functional \FakeNodeTypeManagerTrait ;
1110use Flowpack \NodeTemplates \Tests \Functional \SnapshotTrait ;
12- use Neos \ContentRepository \Domain \Model \NodeInterface ;
13- use Neos \ContentRepository \Domain \Model \Workspace ;
14- use Neos \ContentRepository \Domain \Repository \ContentDimensionRepository ;
15- use Neos \ContentRepository \Domain \Repository \WorkspaceRepository ;
16- use Neos \ContentRepository \Domain \Service \ContextFactoryInterface ;
17- use Neos \ContentRepository \Domain \Service \NodeTypeManager ;
11+ use Neos \ContentRepository \Core \DimensionSpace \DimensionSpacePoint ;
12+ use Neos \ContentRepository \Core \DimensionSpace \OriginDimensionSpacePoint ;
13+ use Neos \ContentRepository \Core \Feature \NodeCreation \Command \CreateNodeAggregateWithNode ;
14+ use Neos \ContentRepository \Core \Feature \RootNodeCreation \Command \CreateRootNodeAggregateWithNode ;
15+ use Neos \ContentRepository \Core \Feature \WorkspaceCreation \Command \CreateRootWorkspace ;
16+ use Neos \ContentRepository \Core \NodeType \NodeTypeManager ;
17+ use Neos \ContentRepository \Core \NodeType \NodeTypeName ;
18+ use Neos \ContentRepository \Core \SharedModel \ContentRepository \ContentRepositoryId ;
19+ use Neos \ContentRepository \Core \SharedModel \Node \NodeAggregateId ;
20+ use Neos \ContentRepository \Core \SharedModel \Node \NodeName ;
21+ use Neos \ContentRepository \Core \SharedModel \User \UserId ;
22+ use Neos \ContentRepository \Core \SharedModel \Workspace \ContentStreamId ;
23+ use Neos \ContentRepository \Core \SharedModel \Workspace \WorkspaceDescription ;
24+ use Neos \ContentRepository \Core \SharedModel \Workspace \WorkspaceName ;
25+ use Neos \ContentRepository \Core \SharedModel \Workspace \WorkspaceTitle ;
26+ use Neos \ContentRepository \TestSuite \Behavior \Features \Bootstrap \Helpers \FakeUserIdProvider ;
1827use Neos \Flow \Cli \Exception \StopCommandException ;
1928use Neos \Flow \Cli \Response ;
20- use Neos \Flow \Tests \FunctionalTestCase ;
29+ use Neos \Flow \Core \Bootstrap ;
30+ use Neos \Flow \ObjectManagement \ObjectManagerInterface ;
2131use Neos \Neos \Domain \Model \Site ;
2232use Neos \Neos \Domain \Repository \SiteRepository ;
2333use Neos \Neos \Ui \Domain \Model \FeedbackCollection ;
2434use Neos \Utility \ObjectAccess ;
35+ use PHPUnit \Framework \TestCase ;
2536use Symfony \Component \Console \Output \BufferedOutput ;
2637
27- final class StandaloneValidationCommandTest extends FunctionalTestCase
38+ final class StandaloneValidationCommandTest extends TestCase // we don't use Flows functional test case as it would reset the database afterwards
2839{
2940 use SnapshotTrait;
41+ use ContentRepositoryTestTrait;
3042 use FakeNodeTypeManagerTrait;
3143
32- protected static $ testablePersistenceEnabled = true ;
33-
34- private ContextFactoryInterface $ contextFactory ;
35-
36- protected NodeInterface $ homePageNode ;
37-
38- protected NodeInterface $ homePageMainContentCollectionNode ;
39-
40- private NodeTemplateDumper $ nodeTemplateDumper ;
41-
42- private RootTemplate $ lastCreatedRootTemplate ;
44+ /**
45+ * Matching configuration in Neos.Neos.sites.node-templates-site
46+ */
47+ private const TEST_SITE_NAME = 'node-templates-site ' ;
4348
4449 private NodeTypeManager $ nodeTypeManager ;
4550
4651 private string $ fixturesDir ;
4752
53+ protected ObjectManagerInterface $ objectManager ;
54+
4855 public function setUp (): void
4956 {
50- parent ::setUp ();
51-
52- $ this ->nodeTypeManager = $ this ->objectManager ->get (NodeTypeManager::class);
53-
54- $ this ->loadFakeNodeTypes ();
57+ $ this ->objectManager = Bootstrap::$ staticObjectManager ;
5558
5659 $ this ->setupContentRepository ();
5760
@@ -61,51 +64,72 @@ public function setUp(): void
6164
6265 public function tearDown (): void
6366 {
64- parent ::tearDown ();
65- $ this ->inject ($ this ->contextFactory , 'contextInstances ' , []);
6667 $ this ->objectManager ->get (FeedbackCollection::class)->reset ();
67- $ this ->objectManager ->forgetInstance (ContentDimensionRepository::class);
68- $ this ->objectManager ->forgetInstance (NodeTypeManager::class);
6968 }
7069
7170 private function setupContentRepository (): void
7271 {
73- // Create an environment to create nodes.
74- $ this ->objectManager ->get (ContentDimensionRepository::class)->setDimensionsConfiguration ([]);
72+ $ this ->initCleanContentRepository (ContentRepositoryId::fromString ('node_templates ' ));
73+
74+ $ this ->nodeTypeManager = $ this ->contentRepository ->getNodeTypeManager ();
75+ $ this ->loadFakeNodeTypes ();
7576
76- $ liveWorkspace = new Workspace ('live ' );
77- $ workspaceRepository = $ this ->objectManager ->get (WorkspaceRepository::class);
78- $ workspaceRepository ->add ($ liveWorkspace );
77+ $ liveWorkspaceCommand = CreateRootWorkspace::create (
78+ $ workspaceName = WorkspaceName::fromString ('live ' ),
79+ new WorkspaceTitle ('Live ' ),
80+ new WorkspaceDescription ('The live workspace ' ),
81+ ContentStreamId::fromString ('cs-identifier ' )
82+ );
7983
80- $ testSite = new Site ('test-site ' );
81- $ testSite ->setSiteResourcesPackageKey ('Test.Site ' );
82- $ siteRepository = $ this ->objectManager ->get (SiteRepository::class);
83- $ siteRepository ->add ($ testSite );
84+ $ this ->contentRepository ->handle ($ liveWorkspaceCommand );
8485
85- $ this ->persistenceManager ->persistAll ();
86- $ this ->contextFactory = $ this ->objectManager ->get (ContextFactoryInterface::class);
87- $ subgraph = $ this ->contextFactory ->create (['workspaceName ' => 'live ' ]);
86+ FakeUserIdProvider::setUserId (UserId::fromString ('initiating-user-identifier ' ));
8887
89- $ rootNode = $ subgraph ->getRootNode ();
88+ $ rootNodeCommand = CreateRootNodeAggregateWithNode::create (
89+ $ workspaceName ,
90+ $ sitesId = NodeAggregateId::fromString ('sites ' ),
91+ NodeTypeName::fromString ('Neos.Neos:Sites ' )
92+ );
9093
91- $ sitesRootNode = $ rootNode ->createNode ('sites ' );
92- $ testSiteNode = $ sitesRootNode ->createNode ('test-site ' );
93- $ this ->homePageNode = $ testSiteNode ->createNode (
94- 'homepage ' ,
95- $ this ->nodeTypeManager ->getNodeType ('Flowpack.NodeTemplates:Document.HomePage ' )
94+ $ this ->contentRepository ->handle ($ rootNodeCommand );
95+
96+ $ siteNodeCommand = CreateNodeAggregateWithNode::create (
97+ $ workspaceName ,
98+ NodeAggregateId::fromString ('test-site ' ),
99+ NodeTypeName::fromString ('Flowpack.NodeTemplates:Document.HomePage ' ),
100+ OriginDimensionSpacePoint::fromDimensionSpacePoint (
101+ DimensionSpacePoint::fromArray ([])
102+ ),
103+ $ sitesId ,
104+ nodeName: NodeName::fromString (self ::TEST_SITE_NAME )
96105 );
106+
107+ $ this ->contentRepository ->handle ($ siteNodeCommand );
97108 }
98109
99110 /** @test */
100111 public function itMatchesSnapshot ()
101112 {
102113 $ commandController = $ this ->objectManager ->get (NodeTemplateCommandController::class);
103114
115+ $ testSite = new Site (self ::TEST_SITE_NAME );
116+ $ testSite ->setSiteResourcesPackageKey ('Test.Site ' );
117+
118+ $ siteRepositoryMock = $ this ->getMockBuilder (SiteRepository::class)->disableOriginalConstructor ()->getMock ();
119+ $ siteRepositoryMock ->expects (self ::once ())->method ('findOneByNodeName ' )->willReturnCallback (function (string $ nodeName ) use ($ testSite ) {
120+ return $ nodeName === $ testSite ->getNodeName ()->value
121+ ? $ testSite
122+ : null ;
123+ });
124+
125+ ObjectAccess::setProperty ($ commandController , 'siteRepository ' , $ siteRepositoryMock , true );
126+
127+
104128 ObjectAccess::setProperty ($ commandController , 'response ' , $ cliResponse = new Response (), true );
105129 ObjectAccess::getProperty ($ commandController , 'output ' , true )->setOutput ($ bufferedOutput = new BufferedOutput ());
106130
107131 try {
108- $ commandController ->validateCommand ();
132+ $ commandController ->validateCommand (self :: TEST_SITE_NAME );
109133 } catch (StopCommandException $ e ) {
110134 }
111135
0 commit comments