Skip to content

Commit

Permalink
Adjust tests to beta15
Browse files Browse the repository at this point in the history
  • Loading branch information
Bernhard Schmitt committed Nov 11, 2024
1 parent 67abdde commit 773f5cb
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 36 deletions.
50 changes: 28 additions & 22 deletions Tests/Functional/AbstractNodeTemplateTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@
use Neos\ContentRepository\Core\Projection\ContentGraph\ContentSubgraphInterface;
use Neos\ContentRepository\Core\Projection\ContentGraph\Filter\FindSubtreeFilter;
use Neos\ContentRepository\Core\Projection\ContentGraph\Node;
use Neos\ContentRepository\Core\Projection\ContentGraph\Subtree;
use Neos\ContentRepository\Core\Projection\ContentGraph\VisibilityConstraints;
use Neos\ContentRepository\Core\SharedModel\ContentRepository\ContentRepositoryId;
use Neos\ContentRepository\Core\SharedModel\Node\NodeAddress;
use Neos\ContentRepository\Core\SharedModel\Node\NodeAggregateId;
use Neos\ContentRepository\Core\SharedModel\Node\NodeName;
use Neos\ContentRepository\Core\SharedModel\User\UserId;
Expand Down Expand Up @@ -82,7 +84,7 @@ public function setUp(): void
$this->objectManager->setInstance(TemplateConfigurationProcessor::class, $templateFactoryMock);

$ref = new \ReflectionClass($this);
$this->fixturesDir = dirname($ref->getFileName()) . '/Snapshots';
$this->fixturesDir = dirname($ref->getFileName() ?: '') . '/Snapshots';
}

public function tearDown(): void
Expand Down Expand Up @@ -112,8 +114,6 @@ private function setupContentRepository(): void

$liveWorkspaceCommand = CreateRootWorkspace::create(
$workspaceName = WorkspaceName::fromString('live'),
new WorkspaceTitle('Live'),
new WorkspaceDescription('The live workspace'),
ContentStreamId::fromString('cs-identifier')
);

Expand All @@ -137,19 +137,22 @@ private function setupContentRepository(): void
$dimensionSpacePoint = DimensionSpacePoint::fromArray([])
),
$sitesId,
nodeName: NodeName::fromString('test-site')
);
)->withNodeName(NodeName::fromString('test-site'));

$this->contentRepository->handle($siteNodeCommand);

$this->subgraph = $this->contentRepository->getContentGraph($workspaceName)->getSubgraph($dimensionSpacePoint, VisibilityConstraints::withoutRestrictions());

$this->homePageNode = $this->subgraph->findNodeById($testSiteId);
$homePage = $this->subgraph->findNodeById($testSiteId);
assert($homePage instanceof Node);
$this->homePageNode = $homePage;

$this->homePageMainContentCollectionNode = $this->subgraph->findNodeByPath(
$homePageMainCollection = $this->subgraph->findNodeByPath(
NodeName::fromString('main'),
$testSiteId
);
assert($homePageMainCollection instanceof Node);
$this->homePageMainContentCollectionNode = $homePageMainCollection;

// For the case you the Neos Site is expected to return the correct site node you can use:

Expand All @@ -175,8 +178,8 @@ private function setupContentRepository(): void
*/
protected function createNodeInto(Node $targetNode, string $nodeTypeName, array $nodeCreationDialogValues): Node
{
$targetNodeAddress = NodeAddressFactory::create($this->contentRepository)->createFromNode($targetNode);
$serializedTargetNodeAddress = $targetNodeAddress->serializeForUri();
$targetNodeAddress = NodeAddress::fromNode($targetNode);
$serializedTargetNodeAddress = $targetNodeAddress->toJson();

$changeCollectionSerialized = [[
'type' => 'Neos.Neos.Ui:CreateInto',
Expand All @@ -198,10 +201,12 @@ protected function createNodeInto(Node $targetNode, string $nodeTypeName, array
assert($changeCollection instanceof ChangeCollection);
$changeCollection->apply();

return $this->subgraph->findNodeByPath(
$node = $this->subgraph->findNodeByPath(
NodeName::fromString('new-node'),
$targetNode->aggregateId
);
assert($node instanceof Node);
return $node;
}

protected function createFakeNode(string $nodeAggregateId): Node
Expand All @@ -213,24 +218,25 @@ protected function createFakeNode(string $nodeAggregateId): Node
NodeTypeName::fromString('unstructured'),
$this->homePageNode->originDimensionSpacePoint,
$this->homePageNode->aggregateId,
nodeName: NodeName::fromString(uniqid('node-'))
)
)->withNodeName(NodeName::fromString(uniqid('node-')))
);

return $this->subgraph->findNodeById($someNodeId);
$node = $this->subgraph->findNodeById($someNodeId);
assert($node instanceof Node);
return $node;
}

protected function assertLastCreatedTemplateMatchesSnapshot(string $snapShotName): void
{
$lastCreatedTemplate = $this->serializeValuesInArray(
$this->lastCreatedRootTemplate->jsonSerialize()
);
$this->assertJsonStringEqualsJsonFileOrCreateSnapshot($this->fixturesDir . '/' . $snapShotName . '.template.json', json_encode($lastCreatedTemplate, JSON_PRETTY_PRINT));
$this->assertJsonStringEqualsJsonFileOrCreateSnapshot($this->fixturesDir . '/' . $snapShotName . '.template.json', json_encode($lastCreatedTemplate, JSON_PRETTY_PRINT | JSON_THROW_ON_ERROR));
}

protected function assertCaughtExceptionsMatchesSnapshot(string $snapShotName): void
{
$this->assertJsonStringEqualsJsonFileOrCreateSnapshot($this->fixturesDir . '/' . $snapShotName . '.messages.json', json_encode($this->getMessagesOfFeedbackCollection(), JSON_PRETTY_PRINT));
$this->assertJsonStringEqualsJsonFileOrCreateSnapshot($this->fixturesDir . '/' . $snapShotName . '.messages.json', json_encode($this->getMessagesOfFeedbackCollection(), JSON_PRETTY_PRINT | JSON_THROW_ON_ERROR));
}

protected function assertNoExceptionsWereCaught(): void
Expand All @@ -240,16 +246,16 @@ protected function assertNoExceptionsWereCaught(): void

protected function assertNodeDumpAndTemplateDumpMatchSnapshot(string $snapShotName, Node $node): void
{
$serializedNodes = $this->jsonSerializeNodeAndDescendents(
$this->subgraph->findSubtree(
$node->aggregateId,
FindSubtreeFilter::create(
nodeTypes: 'Neos.Neos:Node'
)
$subtree = $this->subgraph->findSubtree(
$node->aggregateId,
FindSubtreeFilter::create(
nodeTypes: 'Neos.Neos:Node'
)
);
assert($subtree instanceof Subtree);
$serializedNodes = $this->jsonSerializeNodeAndDescendents($subtree);
unset($serializedNodes['nodeTypeName']);
$this->assertJsonStringEqualsJsonFileOrCreateSnapshot($this->fixturesDir . '/' . $snapShotName . '.nodes.json', json_encode($serializedNodes, JSON_PRETTY_PRINT));
$this->assertJsonStringEqualsJsonFileOrCreateSnapshot($this->fixturesDir . '/' . $snapShotName . '.nodes.json', json_encode($serializedNodes, JSON_PRETTY_PRINT | JSON_THROW_ON_ERROR));

$dumpedYamlTemplate = $this->nodeTemplateDumper->createNodeTemplateYamlDumpFromSubtree($node, $this->contentRepository);

Expand Down
4 changes: 3 additions & 1 deletion Tests/Functional/ContentRepositoryTestTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Neos\ContentRepository\Core\ContentRepository;
use Neos\ContentRepository\Core\SharedModel\ContentRepository\ContentRepositoryId;
use Neos\ContentRepositoryRegistry\ContentRepositoryRegistry;
use Neos\ContentRepositoryRegistry\SubgraphCachingInMemory\SubgraphCachePool;
use Neos\Flow\Configuration\ConfigurationManager;
use Neos\Flow\ObjectManagement\ObjectManagerInterface;

Expand Down Expand Up @@ -37,7 +38,8 @@ private function initCleanContentRepository(ContentRepositoryId $contentReposito

$contentRepositoryRegistry = new ContentRepositoryRegistry(
$registrySettings,
$this->getObject(ObjectManagerInterface::class)
$this->getObject(ObjectManagerInterface::class),
new SubgraphCachePool(),
);

$this->contentRepository = $contentRepositoryRegistry->get($this->contentRepositoryId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@
use Neos\ContentRepository\Core\SharedModel\Node\NodeName;
use Neos\ContentRepository\Core\SharedModel\User\UserId;
use Neos\ContentRepository\Core\SharedModel\Workspace\ContentStreamId;
use Neos\ContentRepository\Core\SharedModel\Workspace\WorkspaceDescription;
use Neos\ContentRepository\Core\SharedModel\Workspace\WorkspaceName;
use Neos\ContentRepository\Core\SharedModel\Workspace\WorkspaceTitle;
use Neos\ContentRepository\TestSuite\Behavior\Features\Bootstrap\Helpers\FakeUserIdProvider;
use Neos\Flow\Cli\Exception\StopCommandException;
use Neos\Flow\Cli\Response;
Expand Down Expand Up @@ -61,7 +59,7 @@ public function setUp(): void
$this->setupContentRepository();

$ref = new \ReflectionClass($this);
$this->fixturesDir = dirname($ref->getFileName()) . '/Snapshots';
$this->fixturesDir = dirname($ref->getFileName() ?: '') . '/Snapshots';
}

public function tearDown(): void
Expand Down Expand Up @@ -90,8 +88,6 @@ private function setupContentRepository(): void

$liveWorkspaceCommand = CreateRootWorkspace::create(
$workspaceName = WorkspaceName::fromString('live'),
new WorkspaceTitle('Live'),
new WorkspaceDescription('The live workspace'),
ContentStreamId::fromString('cs-identifier')
);

Expand All @@ -115,14 +111,13 @@ private function setupContentRepository(): void
DimensionSpacePoint::fromArray([])
),
$sitesId,
nodeName: NodeName::fromString(self::TEST_SITE_NAME)
);
)->withNodeName(NodeName::fromString(self::TEST_SITE_NAME));

$this->contentRepository->handle($siteNodeCommand);
}

/** @test */
public function itMatchesSnapshot()
public function itMatchesSnapshot(): void
{
$commandController = $this->getObject(NodeTemplateCommandController::class);

Expand Down
3 changes: 3 additions & 0 deletions Tests/Functional/FeedbackCollectionMessagesTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ trait FeedbackCollectionMessagesTrait
*/
abstract protected function getObject(string $className): object;

/**
* @return array<int,mixed>
*/
private function getMessagesOfFeedbackCollection(): array
{
/** @var FeedbackInterface[] $allFeedbacks */
Expand Down
7 changes: 7 additions & 0 deletions Tests/Functional/JsonSerializeNodeTreeTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ trait JsonSerializeNodeTreeTrait
{
private readonly ContentRepository $contentRepository;

/**
* @return array<string,mixed>
*/
private function jsonSerializeNodeAndDescendents(Subtree $subtree): array
{
$node = $subtree->node;
Expand Down Expand Up @@ -48,6 +51,10 @@ private function jsonSerializeNodeAndDescendents(Subtree $subtree): array
]);
}

/**
* @param array<mixed> $array
* @return array<mixed>
*/
private function serializeValuesInArray(array $array): array
{
foreach ($array as $key => $value) {
Expand Down
2 changes: 1 addition & 1 deletion Tests/Functional/WithConfigurationTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ trait WithConfigurationTrait
* WARNING: If you activate Singletons during this transaction they will later still have a reference to the mocked object manger, so you might need to call
* {@see ObjectManagerInterface::forgetInstance()}. An alternative would be also to hack the protected $this->settings of the manager.
*
* @param array $additionalSettings settings that are merged onto the the current testing configuration
* @param array<string,mixed> $additionalSettings settings that are merged onto the the current testing configuration
* @param callable $fn test code that is executed in the modified context
*/
private function withMockedConfigurationSettings(array $additionalSettings, callable $fn): void
Expand Down
11 changes: 10 additions & 1 deletion Tests/Unit/Domain/NodeCreation/PropertyTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ class PropertyTypeTest extends TestCase
{
/**
* @dataProvider declarationAndValueProvider
* @param array<mixed> $declarationsByType,
* @param array<mixed> $validValues,
* @param array<mixed> $invalidValues,
*/
public function testIsMatchedBy(array $declarationsByType, array $validValues, array $invalidValues): void
{
Expand Down Expand Up @@ -64,6 +67,9 @@ public function testIsMatchedBy(array $declarationsByType, array $validValues, a
}
}

/**
* @return array<int,array<mixed>>
*/
public function declarationAndValueProvider(): array
{
$bool = true;
Expand Down Expand Up @@ -148,7 +154,7 @@ public function declarationAndValueProvider(): array

/**
* @dataProvider declarationTypeProvider
* @param array $declaredTypes
* @param array<mixed> $declaredTypes
* @param string $expectedSerializationType
*/
public function testGetValue(array $declaredTypes, string $expectedSerializationType): void
Expand Down Expand Up @@ -178,6 +184,9 @@ public function testGetValue(array $declaredTypes, string $expectedSerialization
}
}

/**
* @return array<int,array<mixed>>
*/
public function declarationTypeProvider(): array
{
return [
Expand Down
5 changes: 5 additions & 0 deletions Tests/Unit/Domain/NodeCreation/ReferenceTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ class ReferenceTypeTest extends TestCase

/**
* @dataProvider declarationAndValueProvider
* @param array<mixed> $validValues,
* @param array<mixed> $invalidValues
*/
public function testIsMatchedBy(string $declarationType, array $validValues, array $invalidValues): void
{
Expand Down Expand Up @@ -57,6 +59,9 @@ public function testIsMatchedBy(string $declarationType, array $validValues, arr
}
}

/**
* @return array<int,array<mixed>>
*/
public function declarationAndValueProvider(): array
{
$int = 13;
Expand Down
12 changes: 9 additions & 3 deletions Tests/Unit/Domain/NodeCreation/TransientNodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,12 @@ public function forRegularChildNodeDisallowedChildNode(): void
/** @test */
public function splitPropertiesAndReferencesByTypeDeclaration(): void
{
$nodeType = $this->getNodeType('A:ContentWithProperties');
$node = TransientNode::forRegular(
NodeAggregateId::fromString('na'),
WorkspaceName::fromString('ws'),
OriginDimensionSpacePoint::fromArray([]),
$this->getNodeType('A:ContentWithProperties'),
$nodeType,
NodeAggregateIdsByNodePaths::createEmpty(),
new NodeTypeManager(fn () => []),
$this->getMockBuilder(ContentSubgraphInterface::class)->disableOriginalConstructor()->getMock(),
Expand Down Expand Up @@ -213,8 +214,13 @@ private function createFakeRegularTransientNode(string $nodeTypeName): Transient
/**
* Return a nodetype built from the nodeTypesFixture
*/
private function getNodeType(string $nodeTypeName): ?NodeType
private function getNodeType(string $nodeTypeName): NodeType
{
return $this->nodeTypeManager->getNodeType($nodeTypeName);
$nodeType = $this->nodeTypeManager->getNodeType($nodeTypeName);
if (!$nodeType) {
throw new \Exception('Unknown node type ' . $nodeTypeName);
}

return $nodeType;
}
}

0 comments on commit 773f5cb

Please sign in to comment.