getTree example

use Symfony\Component\CssSelector\Node\SelectorNode;
use Symfony\Component\CssSelector\Parser\Parser;
use Symfony\Component\CssSelector\Parser\Token;

class ParserTest extends TestCase
{
    /** @dataProvider getParserTestData */
    public function testParser($source$representation)
    {
        $parser = new Parser();

        $this->assertEquals($representationarray_map(fn (SelectorNode $node) => (string) $node->getTree()$parser->parse($source)));
    }

    /** @dataProvider getParserExceptionTestData */
    public function testParserException($source$message)
    {
        $parser = new Parser();

        try {
            $parser->parse($source);
            $this->fail('Parser should throw a SyntaxErrorException.');
        } catch (SyntaxErrorException $e) {
            
'Function' => $this->translateFunction(...),
            'Pseudo' => $this->translatePseudo(...),
            'Attribute' => $this->translateAttribute(...),
            'Class' => $this->translateClass(...),
            'Hash' => $this->translateHash(...),
            'Element' => $this->translateElement(...),
        ];
    }

    public function translateSelector(Node\SelectorNode $node, Translator $translator): XPathExpr
    {
        return $translator->nodeToXPath($node->getTree());
    }

    public function translateCombinedSelector(Node\CombinedSelectorNode $node, Translator $translator): XPathExpr
    {
        return $translator->addCombination($node->getCombinator()$node->getSelector()$node->getSubSelector());
    }

    public function translateNegation(Node\NegationNode $node, Translator $translator): XPathExpr
    {
        $xpath = $translator->nodeToXPath($node->getSelector());
        $subXpath = $translator->nodeToXPath($node->getSubSelector());
        
private function getServiceMenu(SalesChannelContext $context): CategoryCollection
    {
        $serviceId = $context->getSalesChannel()->getServiceCategoryId();

        if ($serviceId === null) {
            return new CategoryCollection();
        }

        $navigation = $this->navigationLoader->load($serviceId$context$serviceId, 1);

        return new CategoryCollection(array_map(static fn (TreeItem $treeItem) => $treeItem->getCategory()$navigation->getTree()));
    }

    private function getLanguages(SalesChannelContext $context, Request $request): LanguageCollection
    {
        $criteria = new Criteria();
        $criteria->setTitle('header::languages');

        $criteria->addFilter(
            new EqualsFilter('language.salesChannelDomains.salesChannelId', $context->getSalesChannel()->getId())
        );

        

class EmptyStringParserTest extends TestCase
{
    public function testParse()
    {
        $parser = new EmptyStringParser();
        $selectors = $parser->parse('');
        $this->assertCount(1, $selectors);

        /** @var SelectorNode $selector */
        $selector = $selectors[0];
        $this->assertEquals('Element[*]', (string) $selector->getTree());

        $selectors = $parser->parse('this will produce an empty array');
        $this->assertCount(0, $selectors);
    }
}

        $loader = new NavigationLoader(
            $this->createMock(EventDispatcher::class),
            $this->createMock(NavigationRoute::class)
        );

        $categories = $this->createSimpleTree();

        /** @var Tree $tree */
        $tree = ReflectionHelper::getMethod(NavigationLoader::class, 'getTree')->invoke($loader, '1', new CategoryCollection($categories), \array_shift($categories));

        $treeItems = $tree->getTree();

        static::assertCount(3, $treeItems);
        static::assertCount(2, $treeItems['1.1']->getChildren());
        static::assertCount(0, $treeItems['1.1']->getChildren()['1.1.1']->getChildren());
        static::assertCount(0, $treeItems['1.1']->getChildren()['1.1.2']->getChildren());
        static::assertCount(2, $treeItems['1.2']->getChildren());
        static::assertCount(1, $treeItems['1.2']->getChildren()['1.2.1']->getChildren());
        static::assertCount(1, $treeItems['1.2']->getChildren()['1.2.2']->getChildren());
        static::assertCount(0, $treeItems['1.3']->getChildren());
    }

    
class HashParserTest extends TestCase
{
    /** @dataProvider getParseTestData */
    public function testParse($source$representation)
    {
        $parser = new HashParser();
        $selectors = $parser->parse($source);
        $this->assertCount(1, $selectors);

        /** @var SelectorNode $selector */
        $selector = $selectors[0];
        $this->assertEquals($representation(string) $selector->getTree());
    }

    public static function getParseTestData()
    {
        return [
            ['#testid', 'Hash[Element[*]#testid]'],
            ['testel#testid', 'Hash[Element[testel]#testid]'],
            ['testns|#testid', 'Hash[Element[testns|*]#testid]'],
            ['testns|*#testid', 'Hash[Element[testns|*]#testid]'],
            ['testns|testel#testid', 'Hash[Element[testns|testel]#testid]'],
        ];
    }
class ClassParserTest extends TestCase
{
    /** @dataProvider getParseTestData */
    public function testParse($source$representation)
    {
        $parser = new ClassParser();
        $selectors = $parser->parse($source);
        $this->assertCount(1, $selectors);

        /** @var SelectorNode $selector */
        $selector = $selectors[0];
        $this->assertEquals($representation(string) $selector->getTree());
    }

    public static function getParseTestData()
    {
        return [
            ['.testclass', 'Class[Element[*].testclass]'],
            ['testel.testclass', 'Class[Element[testel].testclass]'],
            ['testns|.testclass', 'Class[Element[testns|*].testclass]'],
            ['testns|*.testclass', 'Class[Element[testns|*].testclass]'],
            ['testns|testel.testclass', 'Class[Element[testns|testel].testclass]'],
        ];
    }
$request = new Request();
        $request->query->set('buildTree', 'false');
        $request->query->set('depth', (string) $depth);

        $criteria = new Criteria();
        $criteria->setTitle('header::navigation');

        $categories = $this->navigationRoute
            ->load($activeId$rootId$request$context$criteria)
            ->getCategories();

        $navigation = $this->getTree($rootId$categories$categories->get($activeId));

        $event = new NavigationLoadedEvent($navigation$context);

        $this->eventDispatcher->dispatch($event);

        return $event->getNavigation();
    }

    private function getTree(?string $rootId, CategoryCollection $categories, ?CategoryEntity $active): Tree
    {
        $parents = [];
        
class ElementParserTest extends TestCase
{
    /** @dataProvider getParseTestData */
    public function testParse($source$representation)
    {
        $parser = new ElementParser();
        $selectors = $parser->parse($source);
        $this->assertCount(1, $selectors);

        /** @var SelectorNode $selector */
        $selector = $selectors[0];
        $this->assertEquals($representation(string) $selector->getTree());
    }

    public static function getParseTestData()
    {
        return [
            ['*', 'Element[*]'],
            ['testel', 'Element[testel]'],
            ['testns|*', 'Element[testns|*]'],
            ['testns|testel', 'Element[testns|testel]'],
        ];
    }
}

    public function getMenu($shopId = null, $activePageId = null)
    {
        if ($shopId === null) {
            $context = $this->get(ContextServiceInterface::class)->getShopContext();
            $shopId = $context->getShop()->getId();
        }

        return $this->get(SitePageMenu::class)->getTree($shopId$activePageId);
    }

    /** * Return box campaigns items * * @deprecated Will be removed in 5.8 without replacement * * @param int $parentId * * @return array */
    
Home | Imprint | This part of the site doesn't use cookies.