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
51 changes: 51 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Tests

on:
push:
branches: [ main, '[0-9]+.[0-9]+' ]
pull_request:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
functional-tests:
name: Functional tests (Neos ${{ matrix.neos-version }}, PHP ${{ matrix.php-version }})
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
# the lowest and the newest supported Neos 9 line, each with its minimum PHP version
include:
- neos-version: '9.0'
php-version: '8.2'
- neos-version: '9.2'
php-version: '8.4'

steps:
- uses: actions/checkout@v7

- uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
extensions: mbstring, intl, pdo_sqlite
tools: composer:v2
coverage: none

- name: Get composer cache directory
id: composer-cache
run: echo "dir=$(composer config cache-files-dir)" >> "$GITHUB_OUTPUT"

- uses: actions/cache@v6
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: composer-${{ runner.os }}-neos${{ matrix.neos-version }}-php${{ matrix.php-version }}-${{ hashFiles('composer.json', 'Tests/Functional/setup-test-distribution.sh') }}
restore-keys: composer-${{ runner.os }}-neos${{ matrix.neos-version }}-php${{ matrix.php-version }}-

- name: Run functional tests
# builds a throwaway Neos distribution with this package symlinked into it, see the script
run: Tests/Functional/run-tests.sh "$RUNNER_TEMP/test-distribution"
env:
NEOS_VERSION: ${{ matrix.neos-version }}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# IDE settings
.idea/
14 changes: 9 additions & 5 deletions Classes/Fusion/PaginationArrayImplementation.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function evaluate(): array
if ($totalCount > 0 !== true) {
return [];
}
$numberOfPages = ceil($totalCount / $itemsPerPage);
$numberOfPages = (int)ceil($totalCount / $itemsPerPage);
if ($maximumNumberOfLinks > $numberOfPages) {
$maximumNumberOfLinks = $numberOfPages;
}
Expand All @@ -35,12 +35,16 @@ public function evaluate(): array
$displayRangeStart = (integer)max($displayRangeStart, 1);
$displayRangeEnd = (integer)min($displayRangeEnd, $numberOfPages);
$links = \range($displayRangeStart, $displayRangeEnd);
if ($displayRangeStart > 2) {
array_unshift($links, '...');
if ($displayRangeStart > 1) {
if ($displayRangeStart > 2) {
array_unshift($links, '...');
}
array_unshift($links, 1);
}
if ($displayRangeEnd + 1 < $numberOfPages) {
$links[] = '...';
if ($displayRangeEnd < $numberOfPages) {
if ($displayRangeEnd + 1 < $numberOfPages) {
$links[] = '...';
}
$links[] = $numberOfPages;
}

Expand Down
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@ The idea is very simple: you often need to display list of things (e.g. news, ar
5. For each of your nodetypes create a new Fusion object of type NodeTypeName + '.Short', or manually define a rendering object.
6. Rely on public API keys when overriding settings.

# Versioning scheme

| Package Version | Branch | Neos / Flow Version | PHP Version | Supported | Remarks |
|-----------------------------|--------|---------------------|-------------|-----------|-----------------------------------------------------------------|
| 4.x (current `main` branch) | `main` | 9.x | >= 8.2 | ☑️ | Neos 9 / new Content Repository. |
| 3.6.x | `3.6` | 3.3 – 8.x | | ☑️ | Bugfixes for Neos 8 (and older) installations. |
| 3.0 – 3.5 | | 3.x – 7.x | | ⛔️ | Superseded by 3.6.x. |
| 2.x and older | | 3.x and older | | ⛔️ | |

# Fusion objects

Keys documented here are considered public API and would be treated with semantic versioning in mind. Extend all other properties at your own risk.
Expand Down Expand Up @@ -154,3 +163,21 @@ Sort nodes by their position in the node tree. Please use with care, as this can
Example:

${q(node).children("main").sortRecursiveByIndex('DESC').get()}

# Running the tests

The functional tests boot a Flow application, so they run inside a throwaway Neos distribution with this package
symlinked into it. The script creates the distribution on the first run (in your temp directory) and reuses it
afterwards:

Tests/Functional/run-tests.sh

# custom distribution directory and additional PHPUnit arguments
Tests/Functional/run-tests.sh /tmp/listable-tests -- --filter PaginationArrayTest

# another Neos 9 minor version (default: 9.2)
NEOS_VERSION=9.0 Tests/Functional/run-tests.sh

Delete the distribution directory to start from scratch. The same script runs in the GitHub CI
(`.github/workflows/tests.yml`), against the lowest and the newest supported Neos version. The `3.6` branch has
the same setup for Neos 8.3.
47 changes: 47 additions & 0 deletions Tests/Functional/Fusion/AbstractFusionTestCase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php
namespace Flowpack\Listable\Tests\Functional\Fusion;

use Neos\Flow\Mvc\ActionRequest;
use Neos\Flow\Tests\FunctionalTestCase;
use Neos\Fusion\Core\FusionGlobals;
use Neos\Fusion\Core\FusionSourceCodeCollection;
use Neos\Fusion\Core\RuntimeFactory;
use Psr\Http\Message\ServerRequestFactoryInterface;

/**
* Base class for tests that evaluate this package's Fusion prototypes in a booted Flow application.
*
* Only the Fusion files given in {@see self::FUSION_FILES} are loaded (not the whole Neos.Neos Fusion), so tests
* stay fast and independent of the content repository.
*/
abstract class AbstractFusionTestCase extends FunctionalTestCase
{
protected const FUSION_FILES = [
'resource://Flowpack.Listable/Private/Fusion/Pagination.fusion',
];

/**
* Evaluates the Fusion path $fusionPath, defined in $fusionSourceCode, with this package's Fusion loaded.
*/
protected function evaluateFusion(string $fusionPath, string $fusionSourceCode): mixed
{
$sourceCode = FusionSourceCodeCollection::empty();
foreach (static::FUSION_FILES as $fusionFile) {
$sourceCode = $sourceCode->union(FusionSourceCodeCollection::fromFilePath($fusionFile));
}
$sourceCode = $sourceCode->union(FusionSourceCodeCollection::fromString($fusionSourceCode));

$runtime = $this->objectManager->get(RuntimeFactory::class)
->createFromSourceCode($sourceCode, FusionGlobals::fromArray(['request' => $this->buildActionRequest()]));

return $runtime->evaluate($fusionPath);
}

private function buildActionRequest(): ActionRequest
{
$httpRequest = $this->objectManager->get(ServerRequestFactoryInterface::class)
->createServerRequest('GET', 'http://localhost/');

return ActionRequest::fromHttpRequest($httpRequest);
}
}
Loading
Loading