Skip to content

Commit

Permalink
Add test for ComponentFilters::filterComponent
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcelOxid committed Aug 19, 2024
1 parent 431a1b7 commit 56ddf41
Showing 1 changed file with 57 additions and 3 deletions.
60 changes: 57 additions & 3 deletions tests/Unit/Shared/DataType/ComponentFiltersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

use OxidEsales\GraphQL\Base\DataType\Filter\StringFilter;
use OxidEsales\GraphQL\Base\DataType\Filter\BoolFilter;
use OxidEsales\GraphQL\ConfigurationAccess\Shared\DataType\ComponentDataTypeInterface;
use OxidEsales\GraphQL\ConfigurationAccess\Shared\DataType\ComponentFilters;
use PHPUnit\Framework\TestCase;
use ReflectionClass;
Expand Down Expand Up @@ -48,12 +49,12 @@ public static function componentByTitleDataProvider(): \Generator

public function testComponentFiltersWithoutFilter(): void
{
$themeFilters = new ComponentFilters();
$componentFilters = new ComponentFilters();
$filterComponentByTitleMethod = $this->getComponentFiltersMethod('filterComponentByTitle');
$filterComponentByStatusMethod = $this->getComponentFiltersMethod('filterComponentByStatus');

$this->assertTrue($filterComponentByTitleMethod->invoke($themeFilters, uniqid()));
$this->assertTrue($filterComponentByStatusMethod->invoke($themeFilters, (bool)random_int(0, 1)));
$this->assertTrue($filterComponentByTitleMethod->invoke($componentFilters, uniqid()));
$this->assertTrue($filterComponentByStatusMethod->invoke($componentFilters, (bool)random_int(0, 1)));
}

/** @dataProvider componentByStatusDataProvider */
Expand Down Expand Up @@ -98,6 +99,59 @@ public static function componentByStatusDataProvider(): \Generator
];
}

/** @dataProvider filterProvider */
public function testFilterComponent(
string $title,
bool $isActive,
StringFilter $stringFilter,
BoolFilter $boolFilter,
bool $expectedResult
): void {
$sut = new ComponentFilters($stringFilter, $boolFilter);

$componentStub = $this->createConfiguredStub(ComponentDataTypeInterface::class, [
'getTitle' => $title,
'isActive' => $isActive,
]);
$result = $sut->filterComponent($componentStub);
$this->assertEquals($expectedResult, $result);
}

public static function filterProvider(): \Generator
{
yield "title and active-filter are true" => [
'title' => 'testTitle',
'isActive' => false,
'stringFilter' => new StringFilter(equals: 'testTitle'),
'boolFilter' => new BoolFilter(false),
'expectedResult' => true
];

yield "title and active-filter are false" => [
'title' => 'testTitle',
'isActive' => true,
'stringFilter' => new StringFilter(equals: 'notTestTitle'),
'boolFilter' => new BoolFilter(false),
'expectedResult' => false
];

yield "title-filter is true but active-filter are false" => [
'title' => 'testTitle',
'isActive' => true,
'stringFilter' => new StringFilter(equals: 'testTitle'),
'boolFilter' => new BoolFilter(false),
'expectedResult' => false
];

yield "title-filter is false but active-filter are true" => [
'title' => 'testTitle',
'isActive' => true,
'stringFilter' => new StringFilter(equals: 'notTestTitle'),
'boolFilter' => new BoolFilter(true),
'expectedResult' => false
];
}

public function testCreateModuleFilterList(): void
{
$stringFilter = $this->createStub(StringFilter::class);
Expand Down

0 comments on commit 56ddf41

Please sign in to comment.