Skip to content

Commit

Permalink
Merge pull request #4455 from neos/testSuite
Browse files Browse the repository at this point in the history
Content Repository Test Suite
  • Loading branch information
nezaniel authored Sep 1, 2023
2 parents defd5ee + ed6636d commit 63c49b3
Showing 1 changed file with 33 additions and 30 deletions.
63 changes: 33 additions & 30 deletions Tests/Behavior/Features/Bootstrap/NodeAuthorizationTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Behat\Gherkin\Node\TableNode;
use Neos\ContentRepository\Core\NodeType\NodeTypeManager;
use Neos\ContentRepository\Core\SharedModel\Exception\NodeTypeNotFoundException;
use Neos\ContentRepository\TestSuite\Behavior\Features\Bootstrap\CRTestSuiteRuntimeVariables;
use Neos\Flow\Security\Exception\AccessDeniedException;
use PHPUnit\Framework\Assert;

Expand All @@ -24,10 +25,12 @@
* * $this->nodeAuthorizationService
* * $this->nodeTypeManager
*
* Note: This trait expects the IsolatedBehatStepsTrait and the NodeOperationsTrait to be available!
* Note: This trait expects the IsolatedBehatStepsTrait to be available!
*/
trait NodeAuthorizationTrait
{
use CRTestSuiteRuntimeVariables;

/**
* @Flow\Inject
* @var \Neos\ContentRepository\Security\Service\AuthorizationService
Expand All @@ -50,11 +53,11 @@ public function iShouldGetTrueWhenAskingTheNodeAuthorizationServiceIfEditingThis
$this->callStepInSubProcess(__METHOD__, sprintf(' %s %s', 'string', escapeshellarg(trim($expectedResult))));
} else {
if ($expectedResult === 'true') {
if ($this->nodeAuthorizationService->isGrantedToEditNode($this->currentNodes[0]) !== true) {
if ($this->nodeAuthorizationService->isGrantedToEditNode($this->currentNode) !== true) {
Assert::fail('The node authorization service did not return true!');
}
} else {
if ($this->nodeAuthorizationService->isGrantedToEditNode($this->currentNodes[0]) !== false) {
if ($this->nodeAuthorizationService->isGrantedToEditNode($this->currentNode) !== false) {
Assert::fail('The node authorization service did not return false!');
}
}
Expand All @@ -81,13 +84,13 @@ public function iShouldGetTrueWhenAskingTheNodeAuthorizationServiceIfEditingTheP
);
} elseif ($expectedResult === 'true') {
if ($this->nodeAuthorizationService->isGrantedToEditNodeProperty(
$this->currentNodes[0],
$this->currentNode,
$propertyName
) !== true) {
Assert::fail('The node authorization service did not return true!');
}
} elseif ($this->nodeAuthorizationService->isGrantedToEditNodeProperty(
$this->currentNodes[0],
$this->currentNode,
$propertyName
) !== false) {
Assert::fail('The node authorization service did not return false!');
Expand All @@ -112,7 +115,7 @@ public function iShouldGetTheFollowingListOfDeniedNodePropertiesFromTheNodeAutho
} else {
$rows = $table->getHash();
$deniedPropertyNames = $this->nodeAuthorizationService->getDeniedNodePropertiesForEditing(
$this->currentNodes[0]
$this->currentNode
);

if (count($rows) !== count($deniedPropertyNames)) {
Expand Down Expand Up @@ -145,7 +148,7 @@ public function iShouldNotBeGrantedToSetAnyOfTheNodesAttributes($not = '')
$this->callStepInSubProcess(__METHOD__, sprintf(' %s %s', 'string', escapeshellarg(trim($not))));
} else {
try {
$this->currentNodes[0]->setName('some-new-name');
$this->currentNode->setName('some-new-name');
if ($not === 'not') {
Assert::fail('Name should not be settable on the current node!');
}
Expand All @@ -156,7 +159,7 @@ public function iShouldNotBeGrantedToSetAnyOfTheNodesAttributes($not = '')
}

try {
$this->currentNodes[0]->removeProperty('title');
$this->currentNode->removeProperty('title');
if ($not === 'not') {
Assert::fail('Title should not be removable on the current node!');
}
Expand All @@ -167,7 +170,7 @@ public function iShouldNotBeGrantedToSetAnyOfTheNodesAttributes($not = '')
}

try {
$this->currentNodes[0]->setContentObject($this->currentNodes[0]->getNodeData());
$this->currentNode->setContentObject($this->currentNode->getNodeData());
if ($not === 'not') {
Assert::fail('Content object should not be settable on the current node!');
}
Expand All @@ -178,7 +181,7 @@ public function iShouldNotBeGrantedToSetAnyOfTheNodesAttributes($not = '')
}

try {
$this->currentNodes[0]->unsetContentObject();
$this->currentNode->unsetContentObject();
if ($not === 'not') {
Assert::fail('Content object should not be unsettable on the current node!');
}
Expand All @@ -190,7 +193,7 @@ public function iShouldNotBeGrantedToSetAnyOfTheNodesAttributes($not = '')

try {
$nodeTypeManager = $this->getObjectManager()->get(NodeTypeManager::class);
$this->currentNodes[0]->setNodeType($nodeTypeManager->getNodeType('Neos.Neos:Node'));
$this->currentNode->setNodeType($nodeTypeManager->getNodeType('Neos.Neos:Node'));
if ($not === 'not') {
Assert::fail('NodeType should not be settable on the current node!');
}
Expand All @@ -201,7 +204,7 @@ public function iShouldNotBeGrantedToSetAnyOfTheNodesAttributes($not = '')
}

try {
$this->currentNodes[0]->setHidden(true);
$this->currentNode->setHidden(true);
if ($not === 'not') {
Assert::fail('Hidden flag should not be settable on the current node!');
}
Expand All @@ -212,7 +215,7 @@ public function iShouldNotBeGrantedToSetAnyOfTheNodesAttributes($not = '')
}

try {
$this->currentNodes[0]->setHiddenBeforeDateTime(new \DateTime());
$this->currentNode->setHiddenBeforeDateTime(new \DateTime());
if ($not === 'not') {
Assert::fail('Hidden before should not be settable on the current node!');
}
Expand All @@ -223,7 +226,7 @@ public function iShouldNotBeGrantedToSetAnyOfTheNodesAttributes($not = '')
}

try {
$this->currentNodes[0]->setHiddenAfterDateTime(new \DateTime());
$this->currentNode->setHiddenAfterDateTime(new \DateTime());
if ($not === 'not') {
Assert::fail('Hidden after should not be settable on the current node!');
}
Expand All @@ -234,7 +237,7 @@ public function iShouldNotBeGrantedToSetAnyOfTheNodesAttributes($not = '')
}

try {
$this->currentNodes[0]->setHiddenInIndex(true);
$this->currentNode->setHiddenInIndex(true);
if ($not === 'not') {
Assert::fail('Hidden in index should not be settable on the current node!');
}
Expand All @@ -245,7 +248,7 @@ public function iShouldNotBeGrantedToSetAnyOfTheNodesAttributes($not = '')
}

try {
$this->currentNodes[0]->setAccessRoles([]);
$this->currentNode->setAccessRoles([]);
if ($not === 'not') {
Assert::fail('Access roles in index should not be settable on the current node!');
}
Expand Down Expand Up @@ -284,7 +287,7 @@ public function iShouldNotBeGrantedToCreateANewChildNodeOfType($not, $nodeName,
$nodeTypeManager = $this->getObjectManager()->get(NodeTypeManager::class);

try {
$this->currentNodes[0]->createNode($nodeName, $nodeTypeManager->getNodeType($nodeType));
$this->currentNode->createNode($nodeName, $nodeTypeManager->getNodeType($nodeType));
if ($not === 'not') {
Assert::fail('Should not be able to create a child node of type "' . $nodeType . '"!');
}
Expand Down Expand Up @@ -328,14 +331,14 @@ public function iShouldGetFalseWhenAskingTheNodeAuthorizationServiceIfCreatingAC

if ($expectedResult === 'true') {
if ($this->nodeAuthorizationService->isGrantedToCreateNode(
$this->currentNodes[0],
$this->currentNode,
$nodeType
) !== true) {
Assert::fail('The node authorization service did not return true!');
}
} else {
if ($this->nodeAuthorizationService->isGrantedToCreateNode(
$this->currentNodes[0],
$this->currentNode,
$nodeType
) !== false) {
Assert::fail('The node authorization service did not return false!');
Expand All @@ -361,7 +364,7 @@ public function iShouldGetTheFollowingListOfDeniedNodeTypesForThisNodeFromTheNod
} else {
$rows = $table->getHash();
$deniedNodeTypeNames = $this->nodeAuthorizationService->getNodeTypeNamesDeniedForCreation(
$this->currentNodes[0]
$this->currentNode
);

if (count($rows) !== count($deniedNodeTypeNames)) {
Expand Down Expand Up @@ -394,7 +397,7 @@ public function iShouldGetTheListOfAllAvailableNodeTypesAsDeniedNodeTypesForThis
} else {
$availableNodeTypes = $this->nodeTypeManager->getNodeTypes();
$deniedNodeTypeNames = $this->nodeAuthorizationService->getNodeTypeNamesDeniedForCreation(
$this->currentNodes[0]
$this->currentNode
);

if (count($availableNodeTypes) !== count($deniedNodeTypeNames)) {
Expand Down Expand Up @@ -427,7 +430,7 @@ public function iShouldNotBeGrantedToRemoveTheNode($not = '')
$this->callStepInSubProcess(__METHOD__, sprintf(' %s %s', 'string', escapeshellarg(trim($not))));
} else {
try {
$this->currentNodes[0]->remove();
$this->currentNode->remove();
if ($not === 'not') {
Assert::fail('Name should not be settable on the current node!');
}
Expand All @@ -449,11 +452,11 @@ public function iShouldGetFalseWhenAskingTheNodeAuthorizationServiceIfRemovalOfT
$this->callStepInSubProcess(__METHOD__, sprintf(' %s %s', 'string', escapeshellarg(trim($expectedResult))));
} else {
if ($expectedResult === 'true') {
if ($this->nodeAuthorizationService->isGrantedToRemoveNode($this->currentNodes[0]) !== true) {
if ($this->nodeAuthorizationService->isGrantedToRemoveNode($this->currentNode) !== true) {
Assert::fail('The node authorization service did not return true!');
}
} else {
if ($this->nodeAuthorizationService->isGrantedToRemoveNode($this->currentNodes[0]) !== false) {
if ($this->nodeAuthorizationService->isGrantedToRemoveNode($this->currentNode) !== false) {
Assert::fail('The node authorization service did not return false!');
}
}
Expand All @@ -472,7 +475,7 @@ public function iShouldNotBeGrantedToGetTheProperty($not, $propertyName)
);
} else {
/** @var Node $currentNode */
$currentNode = $this->currentNodes[0];
$currentNode = $this->currentNode;
try {
switch ($propertyName) {
case 'name':
Expand Down Expand Up @@ -530,13 +533,13 @@ public function iShouldGetFalseWhenAskingTheNodeAuthorizationServiceIfGettingThe
);
} elseif ($expectedResult === 'true') {
if ($this->nodeAuthorizationService->isGrantedToReadNodeProperty(
$this->currentNodes[0],
$this->currentNode,
$propertyName
) !== true) {
Assert::fail('The node authorization service did not return true!');
}
} elseif ($this->nodeAuthorizationService->isGrantedToReadNodeProperty(
$this->currentNodes[0],
$this->currentNode,
$propertyName
) !== false) {
Assert::fail('The node authorization service did not return false!');
Expand All @@ -563,7 +566,7 @@ public function iShouldNotBeGrantedToSetThePropertyTo($not, $propertyName, $valu
);
} else {
/** @var Node $currentNode */
$currentNode = $this->currentNodes[0];
$currentNode = $this->currentNode;
try {
switch ($propertyName) {
case 'name':
Expand Down Expand Up @@ -621,13 +624,13 @@ public function iShouldGetFalseWhenAskingTheNodeAuthorizationServiceIfSettingThe
);
} elseif ($expectedResult === 'true') {
if ($this->nodeAuthorizationService->isGrantedToEditNodeProperty(
$this->currentNodes[0],
$this->currentNode,
$propertyName
) !== true) {
Assert::fail('The node authorization service did not return true!');
}
} elseif ($this->nodeAuthorizationService->isGrantedToEditNodeProperty(
$this->currentNodes[0],
$this->currentNode,
$propertyName
) !== false) {
Assert::fail('The node authorization service did not return false!');
Expand Down

0 comments on commit 63c49b3

Please sign in to comment.