Skip to content
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
22 changes: 13 additions & 9 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,23 @@ jobs:
tests:
name: Tests
runs-on: ubuntu-latest
continue-on-error: ${{ matrix.experimental }}
strategy:
fail-fast: false
matrix:
php: [ '8.2', '8.3' ]
php: [ '8.2', '8.3', '8.4', '8.5' ]
typo3: [ '12', '13' ]
experimental: [false]
composerInstall: [ 'composerInstallLowest', 'composerInstallHighest' ]
include:
- typo3: '12'
php: '8.1'
- typo3: '14'
php: '8.5'
composerInstall: 'composerInstallLowest'
- typo3: '12'
php: '8.1'
experimental: true
- typo3: '14'
php: '8.5'
composerInstall: 'composerInstallHighest'
experimental: true

steps:
- name: Checkout
Expand All @@ -42,11 +46,11 @@ jobs:
- name: PHPStan
run: Build/Scripts/runTests.sh -t ${{ matrix.typo3 }} -p ${{ matrix.php }} -s phpstan -e "--error-format=github"

#- name: Functional tests
#run: Build/Scripts/runTests.sh -t ${{ matrix.typo3 }} -p ${{ matrix.php }} -s functional
- name: Functional tests
run: Build/Scripts/runTests.sh -t ${{ matrix.typo3 }} -p ${{ matrix.php }} -s functional

#- name: Unit tests
#run: Build/Scripts/runTests.sh -t ${{ matrix.typo3 }} -p ${{ matrix.php }} -s unit
- name: Unit tests
run: Build/Scripts/runTests.sh -t ${{ matrix.typo3 }} -p ${{ matrix.php }} -s unit

#- name: Functional tests coverage
#if: matrix.php == '8.2' && matrix.typo3 == '13' && matrix.composerInstall == 'composerInstallHighest'
Expand Down
45 changes: 23 additions & 22 deletions Build/Scripts/runTests.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env bash

#
# EXT:yoast_seo test runner based on docker/podman.
# EXT:frontend_request test runner based on docker/podman.
#

trap 'cleanUp;exit 2' SIGINT
Expand Down Expand Up @@ -144,7 +144,7 @@ handleDbmsOptions() {
loadHelp() {
# Load help text into $HELP
read -r -d '' HELP <<EOF
EXT:yoast_seo test runner. Check code styles, lint PHP files and some other details.
EXT:frontend_request test runner. Check code styles, lint PHP files and some other details.

Usage: $0 [options] [file]

Expand Down Expand Up @@ -222,19 +222,20 @@ Options:
- 15 maintained until 2027-11-11
- 16 maintained until 2028-11-09

-t <11|12|13>
-t <12|13|14>
Only with -s composerInstall|composerInstallLowest|composerInstallHighest
Specifies the TYPO3 CORE Version to be used
- 11.5: use TYPO3 v11 (default)
- 12.4: use TYPO3 v12
- 13.3: use TYPO3 v13
- 12: use TYPO3 v12
- 13: use TYPO3 v13 (default)
- 14: use TYPO3 v14

-p <8.0|8.2|8.3|8.4>
-p <8.0|8.2|8.3|8.4|8.5>
Specifies the PHP minor version to be used
- 8.0: use PHP 8.0
- 8.2: (default) use PHP 8.2
- 8.3: use PHP 8.3
- 8.4: use PHP 8.4
- 8.5: use PHP 8.5

-x
Only with -s functional|unit
Expand Down Expand Up @@ -278,7 +279,7 @@ fi

# Option defaults
TEST_SUITE="help"
TYPO3_VERSION="11"
TYPO3_VERSION="13"
EXTRA_TEST_OPTIONS=""
DATABASE_DRIVER=""
DBMS="sqlite"
Expand Down Expand Up @@ -320,7 +321,7 @@ while getopts "a:b:d:i:s:p:e:t:xy:nhu" OPT; do
;;
p)
PHP_VERSION=${OPTARG}
if ! [[ ${PHP_VERSION} =~ ^(8.0|8.1|8.2|8.3|8.4)$ ]]; then
if ! [[ ${PHP_VERSION} =~ ^(8.2|8.3|8.4|8.5)$ ]]; then
INVALID_OPTIONS+=("p ${OPTARG}")
fi
;;
Expand All @@ -329,7 +330,7 @@ while getopts "a:b:d:i:s:p:e:t:xy:nhu" OPT; do
;;
t)
TYPO3_VERSION=${OPTARG}
if ! [[ ${TYPO3_VERSION} =~ ^(11|12|13)$ ]]; then
if ! [[ ${TYPO3_VERSION} =~ ^(12|13|14)$ ]]; then
INVALID_OPTIONS+=("-t ${OPTARG}")
fi
;;
Expand Down Expand Up @@ -495,17 +496,17 @@ case ${TEST_SUITE} in
cleanComposer
stashComposerFiles
${CONTAINER_BIN} run ${CONTAINER_COMMON_PARAMS} --name composer-install-highest-${SUFFIX} -e COMPOSER_CACHE_DIR=.cache/composer -e COMPOSER_ROOT_VERSION=${COMPOSER_ROOT_VERSION} ${IMAGE_PHP} /bin/bash -c "
if [ ${TYPO3_VERSION} -eq 11 ]; then
composer require --no-ansi --no-interaction --no-progress --no-install \
typo3/cms-core:^11.5 typo3/cms-dashboard:^11.5 || exit 1
fi
if [ ${TYPO3_VERSION} -eq 12 ]; then
composer require --no-ansi --no-interaction --no-progress --no-install \
typo3/cms-core:^12.4 typo3/cms-dashboard:^12.4 || exit 1
typo3/cms-core:^12.4 || exit 1
fi
if [ ${TYPO3_VERSION} -eq 13 ]; then
composer require --no-ansi --no-interaction --no-progress --no-install \
typo3/cms-core:^13.3 typo3/cms-dashboard:^13.3 || exit 1
typo3/cms-core:^13.4 || exit 1
fi
if [ ${TYPO3_VERSION} -eq 14 ]; then
composer require --no-ansi --no-interaction --no-progress --no-install \
typo3/cms-core:^14.1 || exit 1
fi
composer update --no-progress --no-interaction || exit 1
composer show || exit 1
Expand All @@ -517,17 +518,17 @@ case ${TEST_SUITE} in
cleanComposer
stashComposerFiles
${CONTAINER_BIN} run ${CONTAINER_COMMON_PARAMS} --name composer-install-lowest-${SUFFIX} -e COMPOSER_CACHE_DIR=.cache/composer -e COMPOSER_ROOT_VERSION=${COMPOSER_ROOT_VERSION} ${IMAGE_PHP} /bin/bash -c "
if [ ${TYPO3_VERSION} -eq 11 ]; then
composer require --no-ansi --no-interaction --no-progress --no-install \
typo3/cms-core:^11.5 typo3/cms-dashboard:^11.5 || exit 1
fi
if [ ${TYPO3_VERSION} -eq 12 ]; then
composer require --no-ansi --no-interaction --no-progress --no-install \
typo3/cms-core:^12.4 typo3/cms-dashboard:^12.4 || exit 1
typo3/cms-core:^12.4 || exit 1
fi
if [ ${TYPO3_VERSION} -eq 13 ]; then
composer require --no-ansi --no-interaction --no-progress --no-install \
typo3/cms-core:^13.3 typo3/cms-dashboard:^13.3 || exit 1
typo3/cms-core:^13.4 || exit 1
fi
if [ ${TYPO3_VERSION} -eq 14 ]; then
composer require --no-ansi --no-interaction --no-progress --no-install \
typo3/cms-core:^14.1 || exit 1
fi
composer update --no-ansi --no-interaction --no-progress --with-dependencies --prefer-lowest || exit 1
composer show || exit 1
Expand Down
15 changes: 15 additions & 0 deletions Build/phpunit/FunctionalTests.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd"
bootstrap="../../.Build/vendor/typo3/testing-framework/Resources/Core/Build/FunctionalTestsBootstrap.php"
cacheResult="false"
colors="true"
failOnRisky="true"
failOnWarning="true"
>
<testsuites>
<testsuite name="Functional Tests">
<directory>../../Tests/Functional/</directory>
</testsuite>
</testsuites>
</phpunit>
15 changes: 15 additions & 0 deletions Build/phpunit/UnitTests.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd"
bootstrap="../../.Build/vendor/typo3/testing-framework/Resources/Core/Build/UnitTestsBootstrap.php"
cacheResult="false"
colors="true"
failOnRisky="true"
failOnWarning="true"
>
<testsuites>
<testsuite name="Unit Tests">
<directory>../../Tests/Unit/</directory>
</testsuite>
</testsuites>
</phpunit>
23 changes: 23 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Change Log

This changelog is according to [Keep a Changelog](http://keepachangelog.com).

All notable changes to this project will be documented in this file.
We will follow [Semantic Versioning](http://semver.org/).

## [2.0.0] = 2026-02-19

### Added

- TYPO3 14 Support
- Functional and unit tests

### Removed

- PHP 8.1 support

## 1.0.0 - 2025-11-07

### Added

- First version of the extension, javascript to make a frontend request and returning a json with page information
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[![Latest Stable Version](https://poser.pugx.org/maxserv/frontend-request/v/stable)](https://extensions.typo3.org/extension/frontend_request/)
[![TYPO3 14](https://img.shields.io/badge/TYPO3-14-orange.svg?style=flat-square)](https://get.typo3.org/version/14)
[![TYPO3 13](https://img.shields.io/badge/TYPO3-13-orange.svg?style=flat-square)](https://get.typo3.org/version/13)
[![TYPO3 12](https://img.shields.io/badge/TYPO3-12-orange.svg?style=flat-square)](https://get.typo3.org/version/12)
[![Total Downloads](https://poser.pugx.org/maxserv/frontend-request/d/total)](https://packagist.org/packages/maxserv/frontend-request)
Expand Down
Empty file removed Tests/.gitkeep
Empty file.
39 changes: 39 additions & 0 deletions Tests/Functional/PageParser/ParserCollectorTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

declare(strict_types=1);

namespace MaxServ\FrontendRequest\Tests\Functional\PageParser;

use MaxServ\FrontendRequest\PageParser\ParserCollector;
use PHPUnit\Framework\Attributes\Test;
use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;

final class ParserCollectorTest extends FunctionalTestCase
{
protected array $testExtensionsToLoad = [
'maxserv/frontend-request',
];

#[Test]
public function allParsersAreAutoDiscoveredViaDi(): void
{
$parserCollector = $this->get(ParserCollector::class);
$parsers = $parserCollector->getAll();

self::assertArrayHasKey('title', $parsers);
self::assertArrayHasKey('body', $parsers);
self::assertArrayHasKey('metadata', $parsers);
self::assertArrayHasKey('locale', $parsers);
self::assertArrayHasKey('url', $parsers);
self::assertArrayHasKey('favicon', $parsers);
}

#[Test]
public function parserCollectorReturnsCorrectNumberOfParsers(): void
{
$parserCollector = $this->get(ParserCollector::class);
$parsers = $parserCollector->getAll();

self::assertCount(6, $parsers);
}
}
124 changes: 124 additions & 0 deletions Tests/Unit/Builder/RequestParametersBuilderTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
<?php

declare(strict_types=1);

namespace MaxServ\FrontendRequest\Tests\Unit\Builder;

use MaxServ\FrontendRequest\Builder\RequestParametersBuilder;
use PHPUnit\Framework\Attributes\Test;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Message\StreamInterface;
use TYPO3\TestingFramework\Core\Unit\UnitTestCase;

final class RequestParametersBuilderTest extends UnitTestCase
{
private RequestParametersBuilder $subject;

protected function setUp(): void
{
parent::setUp();
$this->subject = new RequestParametersBuilder();
}

#[Test]
public function buildFromQueryParams(): void
{
$request = $this->createMock(ServerRequestInterface::class);
$request->method('getQueryParams')->willReturn([
'pageId' => '42',
'languageId' => '1',
'additionalGetVars' => 'tx_news=5',
]);

$parameters = $this->subject->build($request);

self::assertSame(42, $parameters->getPageId());
self::assertSame(1, $parameters->getLanguageId());
self::assertSame('tx_news=5', $parameters->getAdditionalParameters());
self::assertTrue($parameters->isValid());
}

#[Test]
public function buildFromQueryParamsWithoutAdditionalGetVars(): void
{
$request = $this->createMock(ServerRequestInterface::class);
$request->method('getQueryParams')->willReturn([
'pageId' => '10',
'languageId' => '0',
]);

$parameters = $this->subject->build($request);

self::assertSame(10, $parameters->getPageId());
self::assertSame(0, $parameters->getLanguageId());
self::assertSame('', $parameters->getAdditionalParameters());
}

#[Test]
public function buildFromJsonBody(): void
{
$body = $this->createMock(StreamInterface::class);
$body->method('getContents')->willReturn('{"pageId":7,"languageId":2,"additionalGetVars":"type=123"}');

$request = $this->createMock(ServerRequestInterface::class);
$request->method('getQueryParams')->willReturn([]);
$request->method('getBody')->willReturn($body);

$parameters = $this->subject->build($request);

self::assertSame(7, $parameters->getPageId());
self::assertSame(2, $parameters->getLanguageId());
self::assertSame('type=123', $parameters->getAdditionalParameters());
}

#[Test]
public function buildFallsBackToEmptyParametersWhenNoData(): void
{
$body = $this->createMock(StreamInterface::class);
$body->method('getContents')->willReturn('');

$request = $this->createMock(ServerRequestInterface::class);
$request->method('getQueryParams')->willReturn([]);
$request->method('getBody')->willReturn($body);

$parameters = $this->subject->build($request);

self::assertNull($parameters->getPageId());
self::assertNull($parameters->getLanguageId());
self::assertFalse($parameters->isValid());
}

#[Test]
public function buildHandlesInvalidJson(): void
{
$body = $this->createMock(StreamInterface::class);
$body->method('getContents')->willReturn('{invalid json}');

$request = $this->createMock(ServerRequestInterface::class);
$request->method('getQueryParams')->willReturn([]);
$request->method('getBody')->willReturn($body);

$parameters = $this->subject->build($request);

self::assertFalse($parameters->isValid());
}

#[Test]
public function buildPrefersQueryParamsOverJsonBody(): void
{
$body = $this->createMock(StreamInterface::class);
$body->method('getContents')->willReturn('{"pageId":99,"languageId":9}');

$request = $this->createMock(ServerRequestInterface::class);
$request->method('getQueryParams')->willReturn([
'pageId' => '1',
'languageId' => '0',
]);
$request->method('getBody')->willReturn($body);

$parameters = $this->subject->build($request);

self::assertSame(1, $parameters->getPageId());
self::assertSame(0, $parameters->getLanguageId());
}
}
Loading
Loading