<?php

declare(strict_types=1);

namespace KupShop\RestrictionsBundle\Tests;

use KupShop\CatalogBundle\Section\SectionTree;
use KupShop\RestrictionsBundle\Utils\RestrictionUtil;

class RestrictionsSectionsTest extends \DatabaseTestCase
{
    private RestrictionUtil $restrictionUtil;
    private SectionTree $sectionTree;

    protected function setUp(): void
    {
        parent::setUp();

        $this->restrictionUtil = $this->get(RestrictionUtil::class);
        $this->sectionTree = $this->get(SectionTree::class);
    }

    /** @dataProvider data_testRestrictSections */
    public function testRestrictSections(string $showEmptySections, int $expectedCount): void
    {
        \Settings::getDefault()->cat_show_empty = $showEmptySections;

        $sections = $this->restrictionUtil->restrictSections(
            $this->sectionTree->getTree()
        );

        $this->assertCount($expectedCount, $sections);
    }

    public function data_testRestrictSections(): iterable
    {
        yield 'Show empty sections is disabled' => ['N', 1];
        yield 'Show empty sections is enabled' => ['Y', 3];
    }

    protected function getDataSet()
    {
        return $this->getJsonDataSetFromFile();
    }
}
