Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[WIP][TASK] Add frontend functional tests
- Loading branch information
Showing
5 changed files
with
203 additions
and
4 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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
/.Build | ||
.phpunit.result.cache | ||
/composer.lock | ||
/var |
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,55 @@ | ||
page = PAGE | ||
page.10 = TEXT | ||
page.10.value = Hello World | ||
page.config.disableAllHeaderCode = 1 | ||
|
||
|
||
# Enable language redirect | ||
config.tx_locate = 1 | ||
config.tx_locate { | ||
# Set this param if you do not want to execute the redirect | ||
dryRun = 0 | ||
|
||
# Whether bots should be excluded from the behavior of the extension. | ||
excludeBots = 0 | ||
|
||
# If this option is enabled, the verdict will be saved in a session and will not be evaluated again. | ||
sessionHandling = 0 | ||
|
||
# If this option is enabled, it is possible to overwrite the verdict stored in the session. | ||
overrideSessionValue = 0 | ||
|
||
# URL Parameter which has to be true when overrideCookie is allowed within action and cookieHandling is enabled | ||
overrideQueryParameter = setLang | ||
|
||
verdicts { | ||
redirectToMainlandChina = Leuchtfeuer\Locate\Verdict\Redirect | ||
redirectToMainlandChina { | ||
page = 4 | ||
} | ||
redirectToEN = Leuchtfeuer\Locate\Verdict\Redirect | ||
redirectToEN { | ||
page = 2 | ||
} | ||
|
||
} | ||
|
||
facts { | ||
# browserAcceptLanguage = Leuchtfeuer\Locate\FactProvider\BrowserAcceptedLanguage | ||
countryByIP = Leuchtfeuer\Locate\FactProvider\IP2Country | ||
} | ||
|
||
judges { | ||
# Users from mainland China should be redirected to a specific URL. | ||
100 = Leuchtfeuer\Locate\Judge\Condition | ||
100 { | ||
verdict = redirectToMainlandChina | ||
fact = countryByIP | ||
prosecution = cn | ||
} | ||
|
||
# All other users should be redirected to the English language version of the current page. | ||
999999 = Leuchtfeuer\Locate\Judge\Fixed | ||
999999.verdict = redirectToEN | ||
} | ||
} |
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,32 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<dataset> | ||
<pages> | ||
<uid>1</uid> | ||
<pid>0</pid> | ||
<title>Root 1</title> | ||
<is_siteroot>1</is_siteroot> | ||
<deleted>0</deleted> | ||
<slug>/</slug> | ||
</pages> | ||
<pages> | ||
<uid>2</uid> | ||
<pid>1</pid> | ||
<title>GB</title> | ||
<deleted>0</deleted> | ||
<slug>/gb</slug> | ||
</pages> | ||
<pages> | ||
<uid>3</uid> | ||
<pid>1</pid> | ||
<title>DE</title> | ||
<deleted>0</deleted> | ||
<slug>/de</slug> | ||
</pages> | ||
<pages> | ||
<uid>4</uid> | ||
<pid>1</pid> | ||
<title>ZN</title> | ||
<deleted>0</deleted> | ||
<slug>/zn</slug> | ||
</pages> | ||
</dataset> |
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,114 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the "Locate" extension for TYPO3 CMS. | ||
* | ||
* For the full copyright and license information, please read the | ||
* LICENSE.txt file that was distributed with this source code. | ||
* | ||
* Florian Wessels <f.wessels@Leuchtfeuer.com>, Leuchtfeuer Digital Marketing | ||
*/ | ||
|
||
namespace Leuchtfeuer\Locate\Tests\Functional; | ||
|
||
use Symfony\Component\Yaml\Yaml; | ||
use TYPO3\CMS\Core\Cache\CacheManager; | ||
use TYPO3\CMS\Core\Utility\GeneralUtility; | ||
use TYPO3\TestingFramework\Core\Functional\Framework\Frontend\InternalRequest; | ||
use TYPO3\TestingFramework\Core\Functional\Framework\Frontend\InternalRequestContext; | ||
use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase; | ||
|
||
class FrontendTest extends FunctionalTestCase | ||
{ | ||
protected $testExtensionsToLoad = [ | ||
'typo3conf/ext/locate' | ||
]; | ||
|
||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
$this->importDataSet(__DIR__ . '/Fixtures/redirect-scenario.xml'); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function redirectToMainlandChinaFromIpAddress(): void | ||
{ | ||
$this->setUpFrontendRootPage( | ||
1, | ||
['setup' => ['EXT:locate/Tests/Functional/Fixtures/TypoScript/setup.typoscript']] | ||
); | ||
$this->setUpFrontendSite(1); | ||
$response = $this->executeFrontendRequest( | ||
(new InternalRequest()) | ||
->withPageId(1) | ||
->withHeader('Accept-Language', 'en-GB,en-US;q=0.9,en;q=0.8'), | ||
(new InternalRequestContext())->withGlobalSettings([ | ||
'_SERVER' => [ | ||
'REMOTE_ADDR' => '1.207.255.250', | ||
], | ||
]) | ||
); | ||
self::assertSame('Hello World', (string)$response->getBody()); | ||
} | ||
|
||
/** | ||
* Copied from \TYPO3\CMS\Core\Tests\Functional\DataHandling\AbstractDataHandlerActionTestCase::setUpFrontendSite | ||
* in typo3/cms-core | ||
* | ||
* Create a simple site config for the tests that | ||
* call a frontend page. | ||
* | ||
* @param int $pageId | ||
* @param array $additionalLanguages | ||
*/ | ||
protected function setUpFrontendSite(int $pageId, array $additionalLanguages = []): void | ||
{ | ||
$languages = [ | ||
0 => [ | ||
'title' => 'English', | ||
'enabled' => true, | ||
'languageId' => 0, | ||
'base' => '/', | ||
'typo3Language' => 'default', | ||
'locale' => 'en_US.UTF-8', | ||
'iso-639-1' => 'en', | ||
'navigationTitle' => '', | ||
'hreflang' => '', | ||
'direction' => '', | ||
'flag' => 'us', | ||
], | ||
1 => [ | ||
'title' => 'ZN', | ||
'enabled' => true, | ||
'languageId' => 1, | ||
'base' => '/zn', | ||
'typo3Language' => 'default', | ||
'locale' => 'zn_ZN.UTF-8', | ||
'iso-639-1' => 'zn', | ||
'navigationTitle' => '', | ||
'hreflang' => '', | ||
'direction' => '', | ||
'flag' => 'zn', | ||
], | ||
]; | ||
$languages = array_merge($languages, $additionalLanguages); | ||
$configuration = [ | ||
'rootPageId' => $pageId, | ||
'base' => '/', | ||
'languages' => $languages, | ||
'errorHandling' => [], | ||
'routes' => [], | ||
]; | ||
GeneralUtility::mkdir_deep($this->instancePath . '/typo3conf/sites/testing/'); | ||
$yamlFileContents = Yaml::dump($configuration, 99, 2); | ||
$fileName = $this->instancePath . '/typo3conf/sites/testing/config.yaml'; | ||
GeneralUtility::writeFile($fileName, $yamlFileContents); | ||
// Ensure that no other site configuration was cached before | ||
$cache = GeneralUtility::makeInstance(CacheManager::class)->getCache('core'); | ||
if ($cache->has('sites-configuration')) { | ||
$cache->remove('sites-configuration'); | ||
} | ||
} | ||
} |
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