Skip to content

Commit

Permalink
PIM-10485 : add test
Browse files Browse the repository at this point in the history
  • Loading branch information
Antoine Trouve committed Jun 22, 2022
1 parent fed8021 commit ecf413d
Showing 1 changed file with 57 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace AkeneoTest\Pim\Enrichment\Integration\Category;

use Akeneo\Pim\Enrichment\Bundle\Filter\CollectionFilterInterface;
use Akeneo\Pim\Enrichment\Component\Category\Model\Category;
use Akeneo\Pim\Enrichment\Component\Category\Query\PublicApi\CategoryTree;
use Akeneo\Pim\Enrichment\Bundle\Storage\Sql\Category\SqlFindCategoryTrees;
use Akeneo\Test\Integration\Configuration;
Expand All @@ -17,6 +18,7 @@ final class SqlFindCategoryTreesIntegration extends TestCase
public function setUp(): void
{
parent::setUp();
$this->createCategory(['code' => 'sales']);
$this->sqlFindCategoryTrees = $this->createQuery(new AllowAll());
}

Expand All @@ -30,7 +32,12 @@ public function it_fetches_the_category_trees(): void
$masterTree->code = 'master';
$masterTree->labels = ['en_US' => 'Master catalog'];

$expected = [$masterTree];
$saleTree = new CategoryTree();
$saleTree->id = $actual[1]->id;
$saleTree->code = 'sales';
$saleTree->labels = [];

$expected = [$masterTree, $saleTree];
self::assertEquals($expected, $actual);
}

Expand All @@ -44,6 +51,42 @@ public function it_filters_the_category_trees(): void
self::assertEmpty($actual);
}

/** @test */
public function it_does_not_apply_permission_on_category_trees(): void
{
$actual = $this->sqlFindCategoryTrees->execute(false);

$masterTree = new CategoryTree();
$masterTree->id = $actual[0]->id;
$masterTree->code = 'master';
$masterTree->labels = ['en_US' => 'Master catalog'];

$saleTree = new CategoryTree();
$saleTree->id = $actual[1]->id;
$saleTree->code = 'sales';
$saleTree->labels = [];

$expected = [$masterTree, $saleTree];
self::assertEquals($expected, $actual);
}

/** @test */
public function it_applies_permission_on_category_trees(): void
{
$this->sqlFindCategoryTrees = $this->createQuery(new DenySalesCategory());

$actual = $this->sqlFindCategoryTrees->execute();

$masterTree = new CategoryTree();
$masterTree->id = $actual[0]->id;
$masterTree->code = 'master';
$masterTree->labels = ['en_US' => 'Master catalog'];

$expected = [$masterTree];
self::assertEquals($expected, $actual);
}


protected function getConfiguration(): Configuration
{
return $this->catalog->useMinimalCatalog();
Expand Down Expand Up @@ -84,3 +127,16 @@ public function supportsCollection($collection, $type, array $options = [])
return true;
}
}

class DenySalesCategory implements CollectionFilterInterface
{
public function filterCollection($collection, $type, array $options = [])
{
return array_filter($collection, fn (Category $category) => $category->getCode() != 'sales');
}

public function supportsCollection($collection, $type, array $options = [])
{
return true;
}
}

0 comments on commit ecf413d

Please sign in to comment.