-
-
Notifications
You must be signed in to change notification settings - Fork 135
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BUGFIX: Neos Ui JSON serializable property values #3723
Draft
mhsdesign
wants to merge
2
commits into
9.0
Choose a base branch
from
bugfix/valueObjectSupportInNodePropertyConverterService
base: 9.0
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+281
−4
Draft
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
253 changes: 253 additions & 0 deletions
253
Tests/Functional/Domain/Service/NodePropertyConverterServiceTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,253 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Neos\Neos\Ui\Tests\Functional\Domain\Service; | ||
|
||
use GuzzleHttp\Psr7\Uri; | ||
use Neos\ContentRepository\Core\NodeType\NodeType; | ||
use Neos\ContentRepository\Core\Projection\ContentGraph\Node; | ||
use Neos\Flow\Tests\FunctionalTestCase; | ||
use Neos\Media\Domain\Model\ImageInterface; | ||
use Neos\Neos\Domain\Model\Domain; | ||
use Neos\Neos\Ui\Domain\Service\NodePropertyConverterService; | ||
|
||
/** | ||
* Functional test case which tests the node property converter | ||
*/ | ||
class NodePropertyConverterServiceTest extends FunctionalTestCase | ||
{ | ||
/** | ||
* @test | ||
*/ | ||
public function anArrayOfArrayIsReturnedAsIs() | ||
{ | ||
$this->markTestSkipped('Has to be converted into behat test.'); | ||
|
||
$expected = $propertyValue = [[]]; | ||
|
||
$nodeType = $this | ||
->getMockBuilder(NodeType::class) | ||
->setMethods(['getPropertyType']) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
$nodeType | ||
->expects(self::once()) | ||
->method('getPropertyType') | ||
->willReturn('array'); | ||
|
||
$node = $this | ||
->getMockBuilder(Node::class) | ||
->setMethods(['getProperty', 'getNodeType']) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
$node | ||
->expects(self::once()) | ||
->method('getProperty') | ||
->willReturn($propertyValue); | ||
$node | ||
->expects(self::once()) | ||
->method('getNodeType') | ||
->willReturn($nodeType); | ||
|
||
$nodePropertyConverterService = new NodePropertyConverterService(); | ||
|
||
$actual = $nodePropertyConverterService->getProperty($node, 'dontcare'); | ||
|
||
self::assertEquals($expected, $actual); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function arrayOfObjectsWithToStringMethodIsReturnedAsIsUnlessTypeConverterIsProvided() | ||
{ | ||
$this->markTestSkipped('Has to be converted into behat test.'); | ||
|
||
|
||
$objectWithToStringMethod = new Domain(); | ||
$objectWithToStringMethod->setScheme('http'); | ||
$objectWithToStringMethod->setHostname('neos.io'); | ||
$objectWithToStringMethod->setPort(80); | ||
|
||
$expected = $propertyValue = [$objectWithToStringMethod]; | ||
|
||
$nodeType = $this | ||
->getMockBuilder(NodeType::class) | ||
->setMethods(['getPropertyType']) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
$nodeType | ||
->expects(self::once()) | ||
->method('getPropertyType') | ||
->willReturn('array'); | ||
|
||
$node = $this | ||
->getMockBuilder(Node::class) | ||
->setMethods(['getProperty', 'getNodeType']) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
$node | ||
->expects(self::once()) | ||
->method('getProperty') | ||
->willReturn($propertyValue); | ||
$node | ||
->expects(self::once()) | ||
->method('getNodeType') | ||
->willReturn($nodeType); | ||
|
||
$nodePropertyConverterService = new NodePropertyConverterService(); | ||
|
||
$actual = $nodePropertyConverterService->getProperty($node, 'dontcare'); | ||
|
||
self::assertEquals($expected, $actual); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function arrayOfStringsHasToProvideTypeConverterToBeConvertedToArrayOfStrings() | ||
{ | ||
$this->markTestSkipped('Has to be converted into behat test.'); | ||
|
||
$expected = $propertyValue = ['Hello']; | ||
|
||
$nodeType = $this | ||
->getMockBuilder(NodeType::class) | ||
->setMethods(['getPropertyType']) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
$nodeType | ||
->expects(self::once()) | ||
->method('getPropertyType') | ||
->willReturn('array<string>'); | ||
|
||
$node = $this | ||
->getMockBuilder(Node::class) | ||
->setMethods(['getProperty', 'getNodeType']) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
$node | ||
->expects(self::once()) | ||
->method('getProperty') | ||
->willReturn($propertyValue); | ||
$node | ||
->expects(self::once()) | ||
->method('getNodeType') | ||
->willReturn($nodeType); | ||
|
||
$nodePropertyConverterService = new NodePropertyConverterService(); | ||
|
||
$actual = $nodePropertyConverterService->getProperty($node, 'dontcare'); | ||
|
||
self::assertEquals($expected, $actual); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function complexTypesWithGivenTypeConverterAreConvertedByTypeConverter() | ||
{ | ||
$this->markTestSkipped('Has to be converted into behat test.'); | ||
|
||
$propertyValue = $this->getMockForAbstractClass(ImageInterface::class); | ||
$expected = [ | ||
'__identity' => null, | ||
'__type' => get_class($propertyValue) | ||
]; | ||
|
||
$nodeType = $this | ||
->getMockBuilder(NodeType::class) | ||
->setMethods(['getPropertyType']) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
$nodeType | ||
->expects(self::any()) | ||
->method('getPropertyType') | ||
->willReturn(ImageInterface::class); | ||
|
||
$node = $this | ||
->getMockBuilder(Node::class) | ||
->setMethods(['getProperty', 'getNodeType']) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
$node | ||
->expects(self::any()) | ||
->method('getProperty') | ||
->willReturn($propertyValue); | ||
$node | ||
->expects(self::any()) | ||
->method('getNodeType') | ||
->willReturn($nodeType); | ||
|
||
$nodePropertyConverterService = new NodePropertyConverterService(); | ||
|
||
$actual = $nodePropertyConverterService->getProperty($node, 'dontcare'); | ||
|
||
self::assertEquals($expected, $actual); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function jsonSerializedAbleTypesAreDirectlySerialized() | ||
{ | ||
$this->markTestSkipped('Has to be converted into behat test.'); | ||
|
||
$voClassName = 'Value' . md5(uniqid(mt_rand(), true)); | ||
eval('class ' . $voClassName . ' implements \JsonSerializable' . <<<'PHP' | ||
{ | ||
public function __construct( | ||
public \Psr\Http\Message\UriInterface $uri | ||
) { | ||
} | ||
public static function fromArray(array $array): self | ||
{ | ||
return new self( | ||
new \GuzzleHttp\Psr7\Uri($array['uri']) | ||
); | ||
} | ||
public function jsonSerialize(): array | ||
{ | ||
return [ | ||
'uri' => $this->uri->__toString() | ||
]; | ||
} | ||
} | ||
PHP); | ||
|
||
$propertyValue = new $voClassName(new Uri('localhost://foo.html')); | ||
$expected = '{"uri":"localhost:\\/\\/foo.html"}'; | ||
|
||
$nodeType = $this | ||
->getMockBuilder(NodeType::class) | ||
->setMethods(['getPropertyType']) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
$nodeType | ||
->expects(self::any()) | ||
->method('getPropertyType') | ||
->willReturn(ImageInterface::class); | ||
|
||
$node = $this | ||
->getMockBuilder(Node::class) | ||
->setMethods(['getProperty', 'getNodeType']) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
$node | ||
->expects(self::any()) | ||
->method('getProperty') | ||
->willReturn($propertyValue); | ||
$node | ||
->expects(self::any()) | ||
->method('getNodeType') | ||
->willReturn($nodeType); | ||
|
||
$nodePropertyConverterService = new NodePropertyConverterService(); | ||
|
||
$actual = $nodePropertyConverterService->getProperty($node, 'dontcare'); | ||
|
||
self::assertEquals($expected, json_encode($actual)); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and neos/flow-development-collection#2766 seems to be missing as a feature for the new cr...