-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from sandstorm/feature/12-support-for-textual-…
…persistent-resources Feature/12 support for textual persistent resources
- Loading branch information
Showing
4 changed files
with
110 additions
and
2 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.idea | ||
vendor/ | ||
composer.lock |
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
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,61 @@ | ||
<?php | ||
|
||
namespace Sandstorm\E2ETestTools\Tests\Behavior\Bootstrap; | ||
|
||
use Behat\Gherkin\Node\PyStringNode; | ||
use Neos\Flow\Core\Bootstrap; | ||
use Neos\Flow\ObjectManagement\ObjectManagerInterface; | ||
use Neos\Flow\Persistence\PersistenceManagerInterface; | ||
use Neos\Flow\ResourceManagement\ResourceManager; | ||
use Neos\Media\Domain\Model\Document; | ||
use Neos\Media\Domain\Repository\AssetRepository; | ||
use Neos\Utility\ObjectAccess; | ||
|
||
trait PersistentResourceTrait | ||
{ | ||
/** | ||
* @var AssetRepository | ||
*/ | ||
private AssetRepository $PersistentResourceTrait_assetRepository; | ||
|
||
/** | ||
* @var ResourceManager | ||
*/ | ||
private ResourceManager $PersistentResourceTrait_resourceManager; | ||
|
||
/** | ||
* @var PersistenceManagerInterface | ||
*/ | ||
private PersistenceManagerInterface $PersistentResourceTrait_persistenceManager; | ||
|
||
/** | ||
* @var Bootstrap | ||
*/ | ||
private Bootstrap $PersistentResourceTrait_bootstrap; | ||
|
||
public function PersistentResourceTrait_setupServices(ObjectManagerInterface $objectManager): void | ||
{ | ||
$this->PersistentResourceTrait_assetRepository = $objectManager->get(AssetRepository::class); | ||
$this->PersistentResourceTrait_resourceManager = $objectManager->get(ResourceManager::class); | ||
$this->PersistentResourceTrait_persistenceManager = $objectManager->get(PersistenceManagerInterface::class); | ||
$this->PersistentResourceTrait_bootstrap = $objectManager->get(Bootstrap::class); | ||
} | ||
|
||
/** | ||
* @Given I have a textual persistent resource :uuid named :filename with the following content: | ||
* @throws Exception failure while storing the resource | ||
*/ | ||
public function iHaveATextualPersistentResourceWithTheFollowingContent(string $uuid, string $filename, PyStringNode $content): void | ||
{ | ||
$resource = $this->PersistentResourceTrait_resourceManager->importResourceFromContent( | ||
$content->getRaw(), | ||
$filename); | ||
$document = new Document($resource); | ||
ObjectAccess::setProperty($document, 'Persistence_Object_Identifier', $uuid, true); | ||
$this->PersistentResourceTrait_assetRepository->add($document); | ||
$this->PersistentResourceTrait_persistenceManager->persistAll(); | ||
|
||
$flowContext = $this->PersistentResourceTrait_bootstrap->getContext(); | ||
exec("FLOW_CONTEXT=$flowContext ./flow resource:publish", $output, $resultCode); | ||
} | ||
} |
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,30 @@ | ||
@playwright | ||
@fixtures | ||
Feature: Persistent Resources | ||
|
||
In this example we assume there is a content unit JavaScriptWidget which allows the editor to select a | ||
JavaScript file from the persistent resources. This widget is then loaded and executed. | ||
Also the JavaScriptWidget generates div-tags with given IDs as anchors for the script. | ||
|
||
Hints for the test setup: | ||
|
||
While developing this feature I had trouble loading my persistent resource. This was due to some split-brain | ||
behavior due to a duplicate flow configuration. During the execution of the steps the active FLOW_CONTEXT is | ||
"Testing/Behat". During the fetch of the page and resource it has been "Development/Behat". The persistent | ||
resource was not found since the storage settings (ie the storage- and the target-path) did not match. | ||
|
||
Scenario: JavaScript widget loads and executes | ||
Given I have a site for Site Node "website" | ||
And I have a textual persistent resource "74d819f0-0bf4-44df-ae36-0c7639c1afcc" named "my-widget.js" with the following content: | ||
""" | ||
document.getElementById('my-container-1').appendChild(document.createTextNode('Hello Container 1!')); | ||
document.getElementById('my-container-2').appendChild(document.createTextNode('Hello Container 2!')); | ||
""" | ||
And I have the following nodes: | ||
| Path | Node Type | Properties | HiddenInIndex | | ||
| /sites | unstructured | [] | false | | ||
| /sites/website | Neos.Neos:Document | {"uriPathSegment":"website","title":"Website","privacyPage":"b9d32958-9bc0-4502-bdd2-274b54f1777e"} | false | | ||
| /sites/website/main/node-2ph9cgxvafhxe | My.Cool:JavaScriptWidget | {"javaScriptSourceFile":{"__flow_object_type": "Neos\\Media\\Domain\\Model\\Document","__identifier": "74d819f0-0bf4-44df-ae36-0c7639c1afcc"},"anchorElementIds":"my-container-1,my-container-2"} | false | | ||
When I access the URI path "/" | ||
Then there should be the text "Hello Container 1!" on the page | ||
And there should be the text "Hello Container 2!" on the page |