Skip to content

Commit

Permalink
Merge pull request #4798 from neos/bugfix/constraints-in-node-references
Browse files Browse the repository at this point in the history
BUGFIX: Fixup #4679 constraints in node references
  • Loading branch information
mhsdesign committed Jan 14, 2024
2 parents ebe1e7e + 0e3ad31 commit bdbca39
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ Feature: Constraint checks on SetNodeReferences
| language | de, gsw, en | gsw->de, en |
And using the following node types:
"""yaml
'Neos.ContentRepository.Testing:ReferencedNode': []
'Neos.ContentRepository.Testing:NodeWithReferences':
properties:
referenceProperty:
Expand All @@ -21,7 +23,7 @@ Feature: Constraint checks on SetNodeReferences
type: reference
constraints:
nodeTypes:
'Neos.ContentRepository.Testing:NodeWithReferences': false
'Neos.ContentRepository.Testing:ReferencedNode': false
referencePropertyWithProperties:
type: reference
properties:
Expand Down Expand Up @@ -49,8 +51,8 @@ Feature: Constraint checks on SetNodeReferences
And the following CreateNodeAggregateWithNode commands are executed:
| nodeAggregateId | nodeTypeName | parentNodeAggregateId |
| source-nodandaise | Neos.ContentRepository.Testing:NodeWithReferences | lady-eleonode-rootford |
| anthony-destinode | Neos.ContentRepository.Testing:NodeWithReferences | lady-eleonode-rootford |
| berta-destinode | Neos.ContentRepository.Testing:NodeWithReferences | lady-eleonode-rootford |
| anthony-destinode | Neos.ContentRepository.Testing:ReferencedNode | lady-eleonode-rootford |
| berta-destinode | Neos.ContentRepository.Testing:ReferencedNode | lady-eleonode-rootford |

# checks for contentStreamId
Scenario: Try to reference nodes in a non-existent content stream
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ Feature: Node References without Dimensions
Given using no content dimensions
And using the following node types:
"""yaml
'Neos.ContentRepository.Testing:ReferencedNode': []
'Neos.ContentRepository.Testing:NodeWithReferences':
properties:
referenceProperty:
Expand All @@ -18,7 +20,7 @@ Feature: Node References without Dimensions
constraints:
nodeTypes:
'*': false
'Neos.ContentRepository.Testing:NodeWithReferences': true
'Neos.ContentRepository.Testing:ReferencedNode': true
referencePropertyWithProperty:
type: reference
properties:
Expand Down Expand Up @@ -57,9 +59,10 @@ Feature: Node References without Dimensions
And the following CreateNodeAggregateWithNode commands are executed:
| nodeAggregateId | parentNodeAggregateId | nodeTypeName |
| source-nodandaise | lady-eleonode-rootford | Neos.ContentRepository.Testing:NodeWithReferences |
| anthony-destinode | lady-eleonode-rootford | Neos.ContentRepository.Testing:NodeWithReferences |
| berta-destinode | lady-eleonode-rootford | Neos.ContentRepository.Testing:NodeWithReferences |
| carl-destinode | lady-eleonode-rootford | Neos.ContentRepository.Testing:NodeWithReferences |
| node-wan-kenodi | lady-eleonode-rootford | Neos.ContentRepository.Testing:NodeWithReferences |
| anthony-destinode | lady-eleonode-rootford | Neos.ContentRepository.Testing:ReferencedNode |
| berta-destinode | lady-eleonode-rootford | Neos.ContentRepository.Testing:ReferencedNode |
| carl-destinode | lady-eleonode-rootford | Neos.ContentRepository.Testing:ReferencedNode |

Scenario: Ensure that a single reference between nodes can be set and read
When the command SetNodeReferences is executed with payload:
Expand Down Expand Up @@ -235,15 +238,15 @@ Feature: Node References without Dimensions

And the command SetNodeReferences is executed with payload:
| Key | Value |
| sourceNodeAggregateId | "berta-destinode" |
| sourceNodeAggregateId | "node-wan-kenodi" |
| references | [{"target": "anthony-destinode"}] |
| referenceName | "referenceProperty" |
And the graph projection is fully up to date

Then I expect node aggregate identifier "anthony-destinode" to lead to node cs-identifier;anthony-destinode;{}
And I expect this node to be referenced by:
| Name | Node | Properties |
| referenceProperty | cs-identifier;berta-destinode;{} | null |
| referenceProperty | cs-identifier;node-wan-kenodi;{} | null |
| referenceProperty | cs-identifier;source-nodandaise;{} | null |

Scenario: Ensure that a reference between nodes can be set and read when matching constraints
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ protected function requireNodeTypeToAllowNodesOfTypeInReference(

$constraints = $propertyDeclaration['constraints']['nodeTypes'] ?? [];

if (!ConstraintCheck::create($constraints)->isNodeTypeAllowed($nodeType)) {
if (!ConstraintCheck::create($constraints)->isNodeTypeAllowed($this->getNodeTypeManager()->getNodeType($nodeTypeNameInQuestion))) {
throw ReferenceCannotBeSet::becauseTheConstraintsAreNotMatched(
$referenceName,
$nodeTypeName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@
private function __construct(
private array $constraints
) {
foreach ($this->constraints as $constraint => $value) {
/** @phpstan-ignore-next-line */
if (!(is_string($constraint) && is_bool($value))) {
throw new \RuntimeException(
sprintf('Constraints must be declared as an array of NodeType names with boolean as values. Got %s.', json_encode([$constraint => $value])),
1702374249
);
}
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function getNodes(): Nodes
*/
public function getIterator(): \Traversable
{
return yield from $this->references;
yield from $this->references;
}

public function offsetExists(mixed $offset): bool
Expand Down

0 comments on commit bdbca39

Please sign in to comment.