-
-
Notifications
You must be signed in to change notification settings - Fork 222
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 #5305 from mhsdesign/task/addBehatTestForFrontendN…
…odeController TASK: Introduce full behat test for FrontendNodeController
- Loading branch information
Showing
12 changed files
with
334 additions
and
13 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
15 changes: 15 additions & 0 deletions
15
Neos.Neos/Classes/Domain/Service/FusionAutoIncludeHandler.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,15 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Neos\Neos\Domain\Service; | ||
|
||
use Neos\Fusion\Core\FusionSourceCodeCollection; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
interface FusionAutoIncludeHandler | ||
{ | ||
public function loadFusionFromPackage(string $packageKey, FusionSourceCodeCollection $sourceCodeCollection): FusionSourceCodeCollection; | ||
} |
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
22 changes: 22 additions & 0 deletions
22
Neos.Neos/Classes/Domain/Service/ResourceFusionAutoIncludeHandler.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,22 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Neos\Neos\Domain\Service; | ||
|
||
use Neos\Flow\Annotations as Flow; | ||
use Neos\Fusion\Core\FusionSourceCodeCollection; | ||
|
||
/** | ||
* @internal | ||
* @Flow\Scope("singleton") | ||
*/ | ||
class ResourceFusionAutoIncludeHandler implements FusionAutoIncludeHandler | ||
{ | ||
public function loadFusionFromPackage(string $packageKey, FusionSourceCodeCollection $sourceCodeCollection): FusionSourceCodeCollection | ||
{ | ||
return $sourceCodeCollection->union( | ||
FusionSourceCodeCollection::tryFromFilePath(sprintf('resource://%s/Private/Fusion/Root.fusion', $packageKey)) | ||
); | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
Neos.Neos/Classes/Testing/TestingFusionAutoIncludeHandler.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,60 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Neos\Neos\Testing; | ||
|
||
use Neos\Flow\Annotations as Flow; | ||
use Neos\Fusion\Core\FusionSourceCodeCollection; | ||
use Neos\Neos\Domain\Service\FusionAutoIncludeHandler; | ||
use Neos\Neos\Domain\Service\ResourceFusionAutoIncludeHandler; | ||
|
||
/** | ||
* @internal only for testing purposes of the Neos.Neos package | ||
* @Flow\Scope("singleton") | ||
*/ | ||
class TestingFusionAutoIncludeHandler implements FusionAutoIncludeHandler | ||
{ | ||
/** | ||
* @Flow\Inject | ||
*/ | ||
protected ResourceFusionAutoIncludeHandler $defaultHandler; | ||
|
||
/** | ||
* @var array<string,FusionSourceCodeCollection|true> | ||
*/ | ||
private array $overriddenIncludes = []; | ||
|
||
public function setIncludeFusionPackage(string $packageKey): void | ||
{ | ||
$this->overriddenIncludes[$packageKey] = true; | ||
} | ||
|
||
public function setFusionForPackage(string $packageKey, FusionSourceCodeCollection $packageFusionSource): void | ||
{ | ||
$this->overriddenIncludes[$packageKey] = $packageFusionSource; | ||
} | ||
|
||
public function reset(): void | ||
{ | ||
$this->overriddenIncludes = []; | ||
} | ||
|
||
/** | ||
* If no override is set via {@see setIncludeFusionPackage} or {@see setFusionForPackage} we load all the fusion via the default implementation | ||
*/ | ||
public function loadFusionFromPackage(string $packageKey, FusionSourceCodeCollection $sourceCodeCollection): FusionSourceCodeCollection | ||
{ | ||
if ($this->overriddenIncludes === []) { | ||
return $this->defaultHandler->loadFusionFromPackage($packageKey, $sourceCodeCollection); | ||
} | ||
$override = $this->overriddenIncludes[$packageKey] ?? null; | ||
if ($override === null) { | ||
return $sourceCodeCollection; | ||
} | ||
if ($override === true) { | ||
return $this->defaultHandler->loadFusionFromPackage($packageKey, $sourceCodeCollection); | ||
} | ||
return $sourceCodeCollection->union($override); | ||
} | ||
} |
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,2 @@ | ||
Neos\Neos\Domain\Service\FusionAutoIncludeHandler: | ||
className: Neos\Neos\Testing\TestingFusionAutoIncludeHandler |
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
92 changes: 92 additions & 0 deletions
92
Neos.Neos/Tests/Behavior/Features/Bootstrap/FrontendNodeControllerTrait.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,92 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the Neos.ContentRepository package. | ||
* | ||
* (c) Contributors of the Neos Project - www.neos.io | ||
* | ||
* This package is Open Source Software. For the full copyright and license | ||
* information, please view the LICENSE file which was distributed with this | ||
* source code. | ||
*/ | ||
|
||
use Behat\Gherkin\Node\PyStringNode; | ||
use GuzzleHttp\Psr7\Message; | ||
use Neos\ContentRepository\TestSuite\Behavior\Features\Bootstrap\CRTestSuiteRuntimeVariables; | ||
use Neos\Fusion\Core\Cache\ContentCache; | ||
use PHPUnit\Framework\Assert; | ||
use Psr\Http\Message\ResponseInterface; | ||
use Psr\Http\Message\ServerRequestFactoryInterface; | ||
|
||
/** | ||
* @internal only for behat tests within the Neos.Neos package | ||
*/ | ||
trait FrontendNodeControllerTrait | ||
{ | ||
use CRTestSuiteRuntimeVariables; | ||
|
||
private ResponseInterface|null $frontendNodeControllerResponse = null; | ||
|
||
/** | ||
* @template T of object | ||
* @param class-string<T> $className | ||
* | ||
* @return T | ||
*/ | ||
abstract private function getObject(string $className): object; | ||
|
||
/** | ||
* @BeforeScenario | ||
*/ | ||
public function setupFrontendNodeControllerTrait(): void | ||
{ | ||
$this->getObject(ContentCache::class)->flush(); | ||
$this->getObject(\Neos\Neos\Testing\TestingFusionAutoIncludeHandler::class)->reset(); | ||
$this->frontendNodeControllerResponse = null; | ||
} | ||
|
||
/** | ||
* @When the Fusion code for package :package is: | ||
*/ | ||
public function iHaveTheFollowingFusionCodeForTheSite(PyStringNode $fusionCode, string $package) | ||
{ | ||
$testingFusionHandler = $this->getObject(\Neos\Neos\Testing\TestingFusionAutoIncludeHandler::class); | ||
$testingFusionHandler->setFusionForPackage($package, \Neos\Fusion\Core\FusionSourceCodeCollection::fromString($fusionCode->getRaw())); | ||
} | ||
|
||
/** | ||
* @When I dispatch the following request :requestUri | ||
*/ | ||
public function iDispatchTheFollowingRequest(string $requestUri) | ||
{ | ||
$testingFusionHandler = $this->getObject(\Neos\Neos\Testing\TestingFusionAutoIncludeHandler::class); | ||
$testingFusionHandler->setIncludeFusionPackage('Neos.Fusion'); | ||
$testingFusionHandler->setIncludeFusionPackage('Neos.Neos'); | ||
|
||
$httpRequest = $this->getObject(ServerRequestFactoryInterface::class)->createServerRequest('GET', $requestUri); | ||
|
||
$this->frontendNodeControllerResponse = $this->getObject(\Neos\Flow\Http\Middleware\MiddlewaresChain::class)->handle( | ||
$httpRequest | ||
); | ||
} | ||
|
||
/** | ||
* @Then I expect the following response header: | ||
*/ | ||
public function iExpectTheFollowingResponseHeader(PyStringNode $expectedResult): void | ||
{ | ||
Assert::assertNotNull($this->frontendNodeControllerResponse); | ||
Assert::assertSame($expectedResult->getRaw(), $this->frontendNodeControllerResponse->getBody()->getContents()); | ||
} | ||
|
||
/** | ||
* @Then I expect the following response: | ||
*/ | ||
public function iExpectTheFollowingResponse(PyStringNode $expectedResult): void | ||
{ | ||
Assert::assertNotNull($this->frontendNodeControllerResponse); | ||
Assert::assertEquals($expectedResult->getRaw(), str_replace("\r\n", "\n", Message::toString($this->frontendNodeControllerResponse))); | ||
} | ||
} |
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
Oops, something went wrong.