Skip to content

Commit d7a4b6e

Browse files
committed
[TASK] Add e2e test for TypoScript Fractor
Also extends the e2e test script to run multiple tests and to compare the CLI output of Fractor
1 parent ca73644 commit d7a4b6e

File tree

14 files changed

+226
-15
lines changed

14 files changed

+226
-15
lines changed

e2e/.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/composer.lock
22
/vendor/
33

4-
/*/output/
4+
/*/output/
5+
/*/output.txt

e2e/run-test.sh

+39-12
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,42 @@ cd $TESTS_BASE_DIR
1010
rm -r composer.lock vendor || true
1111
composer install
1212

13-
TEST_DIR=typo3-yaml
14-
15-
cd $TEST_DIR
16-
17-
[[ -d ./output/ ]] && rm -rf ./output/
18-
cp -r fixtures/ output/
19-
20-
cd $TESTS_BASE_DIR
21-
./vendor/bin/fractor process --quiet -c $TESTS_BASE_DIR/$TEST_DIR/fractor.php
22-
23-
# TODO remove -b once we keep the output format when re-writing the file
24-
diff -rub $TEST_DIR/expected-output/ $TEST_DIR/output/
13+
for TEST_DIR in typo3-yaml typo3-typoscript
14+
do
15+
set +x
16+
echo
17+
echo "############################################################"
18+
echo "#"
19+
echo "# Running test in $TEST_DIR/"
20+
echo "#"
21+
echo "############################################################"
22+
echo
23+
set -x
24+
25+
# remove output from a previous run, if any
26+
[[ -f $TEST_DIR/output.txt ]] && rm $TEST_DIR/output.txt
27+
[[ -d $TEST_DIR/result/ ]] && rm -rf $TEST_DIR/result/
28+
# copy over our fixture to the path that Fractor will run in
29+
cp -r $TEST_DIR/fixtures/ $TEST_DIR/result/
30+
31+
./vendor/bin/fractor process -c $TESTS_BASE_DIR/$TEST_DIR/fractor.php > $TEST_DIR/output.txt
32+
33+
set +x
34+
echo
35+
echo "############################################################"
36+
echo "# Comparing Fractor result against expected result"
37+
echo
38+
set -x
39+
40+
# TODO remove -b once we keep the output format when re-writing the file
41+
diff -rub --color=auto $TEST_DIR/expected-result/ $TEST_DIR/result/
42+
43+
set +x
44+
echo
45+
echo "############################################################"
46+
echo "# Comparing Fractor CLI output against expected output"
47+
echo
48+
set -x
49+
50+
diff -u --color=auto $TEST_DIR/expected-output.txt $TEST_DIR/output.txt
51+
done
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---------- begin diff ----------
2+
@@ @@
3+
page.10.value = Link to page 23
4+
page.10.typolink {
5+
parameter = 23
6+
- useCacheHash = 1
7+
}
8+
9+
page.20 = TEXT
10+
page.20.value = Link to page 42
11+
page.20.typolink.parameter = 42
12+
-page.20.typolink.useCacheHash = 1
13+
----------- end diff -----------
14+
15+
Applied rules:
16+
RemoveUseCacheHashFromTypolinkTypoScriptFractor (https://docs.typo3.org/c/typo3/cms-core/main/en-us/Changelog/10.0/Deprecation-88406-SetCacheHashnoCacheHashOptionsInViewHelpersAndUriBuilder.html)
17+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
page = PAGE
2+
page.10 = TEXT
3+
page.10.value = Link to page 23
4+
page.10.typolink {
5+
parameter = 23
6+
}
7+
8+
page.20 = TEXT
9+
page.20.value = Link to page 42
10+
page.20.typolink.parameter = 42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
page = PAGE
2+
page.10 = TEXT
3+
page.10.value = Link to page 23
4+
page.10.typolink {
5+
parameter = 23
6+
useCacheHash = 1
7+
}
8+
9+
page.20 = TEXT
10+
page.20.value = Link to page 42
11+
page.20.typolink.parameter = 42
12+
page.20.typolink.useCacheHash = 1

e2e/typo3-typoscript/fractor.php

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use a9f\Fractor\Configuration\FractorConfiguration;
6+
use a9f\Typo3Fractor\Set\Typo3LevelSetList;
7+
8+
return FractorConfiguration::configure()
9+
->withPaths([__DIR__ . '/result/'])
10+
->withSets([Typo3LevelSetList::UP_TO_TYPO3_13]);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
page = PAGE
2+
page.10 = TEXT
3+
page.10.value = Link to page 23
4+
page.10.typolink {
5+
parameter = 23
6+
}
7+
8+
page.20 = TEXT
9+
page.20.value = Link to page 42
10+
page.20.typolink.parameter = 42

e2e/typo3-yaml/expected-output.txt

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
---------- begin diff ----------
2+
@@ @@
3+
-
4+
options:
5+
recipients:
6+
7+
8+
9+
subject: 'Kontaktanfrage von Website'
10+
- recipientAddress: [email protected]
11+
- recipientName: Bar
12+
- replyToAddress: [email protected]
13+
senderAddress: '{email}'
14+
senderName: '{lastName}'
15+
- carbonCopyAddress: [email protected]
16+
- blindCarbonCopyAddress: [email protected]
17+
format: html
18+
attachUploads: true
19+
+ replyToRecipients:
20+
21+
+ carbonCopyRecipients:
22+
23+
+ blindCarbonCopyRecipients:
24+
25+
identifier: EmailToReceiver
26+
-
27+
options:
28+
recipients:
29+
30+
31+
32+
subject: 'Kontaktanfrage von Website'
33+
- recipientAddress: [email protected]
34+
- recipientName: Bar
35+
- replyToAddress: [email protected]
36+
senderAddress: '{email}'
37+
senderName: '{lastName}'
38+
- carbonCopyAddress: [email protected]
39+
- blindCarbonCopyAddress: [email protected]
40+
format: html
41+
attachUploads: true
42+
+ replyToRecipients:
43+
44+
+ carbonCopyRecipients:
45+
46+
+ blindCarbonCopyRecipients:
47+
48+
identifier: EmailToSender
49+
variants:
50+
-
51+
@@ @@
52+
identifier: EmailToReceiver
53+
options:
54+
subject: 'Example Subject'
55+
- recipientAddress: [email protected]
56+
- recipientName: 'Example Recipient'
57+
senderAddress: [email protected]
58+
senderName: '{text-2} {text-1}'
59+
- replyToAddress: '{email}'
60+
+ replyToRecipients:
61+
+ - '{email}'
62+
+ recipients:
63+
+ [email protected]: 'Example Recipient'
64+
----------- end diff -----------
65+
66+
Applied rules:
67+
EmailFinisherYamlFractor (https://docs.typo3.org/c/typo3/cms-core/main/en-us/Changelog/10.0/Feature-80420-AllowMultipleRecipientsInEmailFinisher.html)
68+

e2e/typo3-yaml/fractor.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@
66
use a9f\Typo3Fractor\Set\Typo3LevelSetList;
77

88
return FractorConfiguration::configure()
9-
->withPaths([__DIR__ . '/output/'])
9+
->withPaths([__DIR__ . '/result/'])
1010
->withSets([Typo3LevelSetList::UP_TO_TYPO3_13]);
+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
finishers:
2+
-
3+
options:
4+
recipients:
5+
6+
7+
subject: 'Kontaktanfrage von Website'
8+
senderAddress: '{email}'
9+
senderName: '{lastName}'
10+
format: html
11+
attachUploads: true
12+
replyToRecipients:
13+
14+
carbonCopyRecipients:
15+
16+
blindCarbonCopyRecipients:
17+
18+
identifier: EmailToReceiver
19+
-
20+
options:
21+
recipients:
22+
23+
24+
subject: 'Kontaktanfrage von Website'
25+
senderAddress: '{email}'
26+
senderName: '{lastName}'
27+
format: html
28+
attachUploads: true
29+
replyToRecipients:
30+
31+
carbonCopyRecipients:
32+
33+
blindCarbonCopyRecipients:
34+
35+
identifier: EmailToSender
36+
variants:
37+
-
38+
identifier: variant-1
39+
condition: 'formValues["foo"] == "bar"'
40+
finishers:
41+
-
42+
identifier: EmailToReceiver
43+
options:
44+
subject: 'Example Subject'
45+
senderAddress: [email protected]
46+
senderName: '{text-2} {text-1}'
47+
replyToRecipients:
48+
- '{email}'
49+
recipients:
50+
[email protected]: 'Example Recipient'

packages/fractor-typoscript/composer.json

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"a9f/fractor": "^0.2",
1616
"a9f/fractor-extension-installer": "^0.2",
1717
"helmich/typo3-typoscript-parser": "^2.6",
18+
"thecodingmachine/safe": "^2.5",
1819
"webmozart/assert": "^1.11"
1920
},
2021
"require-dev": {

packages/fractor/src/Application/ValueObject/File.php

+5
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ public function __construct(
3636
$this->fileExtension = pathinfo($this->fileName, PATHINFO_EXTENSION);
3737
}
3838

39+
public static function forPath(string $filePath)
40+
{
41+
return new self($filePath, \Safe\file_get_contents($filePath));
42+
}
43+
3944
public function changeOriginalContent(string $originalContent): void
4045
{
4146
$this->originalContent = $originalContent;

packages/fractor/src/Configuration/ValueObject/Configuration.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
/**
1515
* @param string[] $fileExtensions
1616
* @param list<non-empty-string> $paths
17-
* @param string[] $skip
17+
* @param array<string, string> $skip
1818
*/
1919
public function __construct(
2020
private array $fileExtensions,

0 commit comments

Comments
 (0)