Skip to content
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

Add end-to-end tests #2

Merged
merged 2 commits into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .github/workflows/lint_test_pull_requests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,20 @@ jobs:
container_workdir: /app/${{ matrix.directory }}
command: ${{ matrix.composer-command.command }}
memory_limit: 512M

tests:
runs-on: ubuntu-latest
name: End to end tests
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.2'

- name: Run tests
working-directory: tests
run: ./run-test.sh
4 changes: 4 additions & 0 deletions tests/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/composer.lock
/vendor/

/*/output/
25 changes: 25 additions & 0 deletions tests/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"name": "a9f/fractor-tests-typo3-flexform",
"type": "project",
"require": {
"a9f/fractor": "@dev",
"a9f/fractor-extension-installer": "@dev",
"a9f/fractor-xml": "@dev",
"a9f/typo3-fractor": "@dev"
},
"require-dev": {
"ergebnis/composer-normalize": "^2.42"
},
"repositories": {
"fractor": {
"type": "path",
"url": "../*"
}
},
"config": {
"allow-plugins": {
"a9f/fractor-extension-installer": true,
"ergebnis/composer-normalize": true
}
}
}
24 changes: 24 additions & 0 deletions tests/run-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/env bash

set -x

TESTS_BASE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd)"
BASE_DIR="$TESTS_BASE_DIR/../"

cd $TESTS_BASE_DIR

rm -r composer.lock vendor || true
composer install

TEST_DIR=typo3-flexform

cd $TEST_DIR

[[ -d ./output/ ]] && rm -rf ./output/
cp -r fixtures/ output/

cd $TESTS_BASE_DIR
./vendor/bin/fractor process -c $TESTS_BASE_DIR/$TEST_DIR/fractor.php

# TODO remove -b once we keep the output format when re-writing the file
diff -rub $TEST_DIR/expected-output/ $TEST_DIR/output/
18 changes: 18 additions & 0 deletions tests/typo3-flexform/expected-output/FlexFormWithSelect.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<T3DataStructure>
<sheets>
<sDEF>
<ROOT>
<type>array</type>
<el>
<foo>
<config>
<type>select</type>
<renderType>selectSingle</renderType>
</config>
</foo>
</el>
</ROOT>
</sDEF>
</sheets>
</T3DataStructure>
18 changes: 18 additions & 0 deletions tests/typo3-flexform/fixtures/FlexFormWithSelect.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<T3DataStructure>
<sheets>
<sDEF>
<ROOT>
<type>array</type>
<el>
<foo>
<config>
<type>select</type>
<maxitems>1</maxitems>
</config>
</foo>
</el>
</ROOT>
</sDEF>
</sheets>
</T3DataStructure>
19 changes: 19 additions & 0 deletions tests/typo3-flexform/fractor.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

use a9f\Fractor\Configuration\FractorConfig;
use a9f\Fractor\Fractor\DummyRule;
use a9f\FractorXml\XmlFileProcessor;
use a9f\Typo3Fractor\Rules\FlexForm\AddRenderTypeToFlexFormFractor;

return static function (FractorConfig $config) {
$config->import(__DIR__ . '/../vendor/a9f/fractor-xml/config/fractor.php');

$config->setPaths([
__DIR__ . '/output/',
]);

$config->withFileProcessor(XmlFileProcessor::class);

$config->withRule(AddRenderTypeToFlexFormFractor::class);
$config->withRule(DummyRule::class);
};