<?php

namespace KupShop\CatalogBundle\Tests\Section;

use KupShop\CatalogBundle\Util\SectionUtil;

class SectionUtilTest extends \DatabaseTestCase
{
    protected function setUp(): void
    {
        parent::setUp();

        $this->sectionUtils = $this->get(SectionUtil::class);
    }

    public function testGetDescendantCategories()
    {
        $ids = $this->sectionUtils->getDescendantCategories([1, 4]);
        sort($ids);
        $this->assertEquals([1, 2, 3, 4, 5, 6], $ids);
    }

    public function testGetNotHiddenDescendantCategories()
    {
        // Sekce 2 skryta
        sqlQuery('UPDATE sections SET figure="N" WHERE id=2');
        $ids = $this->sectionUtils->getDescendantCategories([1, 4]);
        sort($ids);
        $this->assertEquals([1, 3, 4, 5, 6], $ids);
    }

    public function testGetHiddenInMenuDescendantCategories()
    {
        // Sekce 2 skryta v menu - chceme stále vidět
        sqlQuery('UPDATE sections SET figure="O" WHERE id=2');
        $ids = $this->sectionUtils->getDescendantCategories([1, 4]);
        sort($ids);
        $this->assertEquals([1, 2, 3, 4, 5, 6], $ids);
    }

    public function testGetCommonDescendantCategories()
    {
        $ids = array_merge(getDescendantCategories(1), getDescendantCategories(4));
        sort($ids);
        $this->assertEquals([1, 2, 3, 4, 5, 6], $ids);
    }

    public function testGetNotHiddenCommonDescendantCategories()
    {
        // Sekce 2 skryta v menu - chceme stále vidět
        sqlQuery('UPDATE sections SET figure="O" WHERE id=2');
        $ids = array_merge(getDescendantCategories(1), getDescendantCategories(4));
        sort($ids);
        $this->assertEquals([1, 2, 3, 4, 5, 6], $ids);
    }

    public function testGetHiddenCommonDescendantCategories()
    {
        // Sekce 2 skryta
        sqlQuery('UPDATE sections SET figure="N" WHERE id=2');
        $ids = array_merge(getDescendantCategories(1), getDescendantCategories(4));
        sort($ids);
        $this->assertEquals([1, 3, 4, 5, 6], $ids);
    }
}
