Skip to content

Commit

Permalink
[Tests] Added unit test coverage for IsPreview View Matcher
Browse files Browse the repository at this point in the history
  • Loading branch information
alongosz committed Oct 23, 2023
1 parent acc4803 commit 10132c3
Showing 1 changed file with 96 additions and 0 deletions.
96 changes: 96 additions & 0 deletions tests/lib/MVC/Symfony/Matcher/ContentBased/IsPreviewTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
<?php

/**
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);

namespace Ibexa\Tests\Core\MVC\Symfony\Matcher\ContentBased;

use Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException;
use Ibexa\Core\MVC\Symfony\Matcher\ContentBased\IsPreview;
use Ibexa\Core\MVC\Symfony\View\ContentView;
use Ibexa\Core\MVC\Symfony\View\View;
use PHPUnit\Framework\TestCase;

/**
* @covers \Ibexa\Core\MVC\Symfony\Matcher\ContentBased\IsPreview
*/
final class IsPreviewTest extends TestCase
{
private IsPreview $isPreviewMatcher;

protected function setUp(): void
{
$this->isPreviewMatcher = new IsPreview();
}

/**
* @return iterable<string, array{\Ibexa\Core\MVC\Symfony\View\View, boolean, boolean}>
*/
public static function getDataForTestMatch(): iterable
{
$previewContentView = new ContentView();
$previewContentView->setParameters(['isPreview' => true]);

$notPreviewContentView = new ContentView();
$notPreviewContentView->setParameters(['isPreview' => false]);

$viewContentView = new ContentView();
yield 'match for preview content view' => [
$previewContentView,
true, // IsPreview: true
true, // matches the view
];

yield 'do not match for preview content view' => [
$previewContentView,
false, // IsPreview: false
false, // doesn't match the view
];

yield 'match for view content view' => [
$notPreviewContentView,
false, // IsPreview: false
true, // matches since it's not a preview content view
];

yield 'do not match for view content view' => [
$notPreviewContentView,
true, // IsPreview: true
false, // doesn't match since it's not a preview content view
];

yield 'not match for not set isPreview parameter' => [
$viewContentView,
true, // IsPreview: true
false, // by default, it's not a preview view if parameter is not set
];

yield 'do not match for not set isPreview parameter' => [
$viewContentView,
false,
true, // matches not a preview view, when parameter is not set
];
}

/**
* @dataProvider getDataForTestMatch
*
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException
*/
public function testMatch(View $view, bool $matchConfig, bool $expectedIsPreview): void
{
$this->isPreviewMatcher->setMatchingConfig($matchConfig);

self::assertSame($expectedIsPreview, $this->isPreviewMatcher->match($view));
}

public function testSetMatchConfigThrowsInvalidArgumentException(): void
{
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('IsPreview matcher expects true or false value, got a value of integer type');
$this->isPreviewMatcher->setMatchingConfig(123);
}
}

0 comments on commit 10132c3

Please sign in to comment.