Spamworldpro Mini Shell
Spamworldpro


Server : Apache
System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64
User : corals ( 1002)
PHP Version : 7.4.33
Disable Function : exec,passthru,shell_exec,system
Directory :  /home/corals/old/dev/tests/integration/testsuite/Magento/Cms/Ui/Component/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/corals/old/dev/tests/integration/testsuite/Magento/Cms/Ui/Component/DataProviderTest.php
<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
declare(strict_types=1);

namespace Magento\Cms\Ui\Component;

use Magento\Cms\Api\Data\BlockInterface;
use Magento\Cms\Api\Data\PageInterface;
use Magento\Framework\App\RequestInterface;
use Magento\Framework\ObjectManagerInterface;
use Magento\Framework\View\Element\UiComponentFactory;
use Magento\Framework\View\Element\UiComponentInterface;
use Magento\TestFramework\Helper\Bootstrap;
use PHPUnit\Framework\TestCase;

/**
 * Checks Cms UI component data provider behaviour
 *
 * @magentoAppArea adminhtml
 * @magentoDbIsolation enabled
 */
class DataProviderTest extends TestCase
{
    /** @var ObjectManagerInterface */
    private $objectManager;

    /** @var UiComponentFactory */
    private $componentFactory;

    /** @var RequestInterface */
    private $request;

    /**
     * @inheritdoc
     */
    protected function setUp(): void
    {
        parent::setUp();

        $this->objectManager = Bootstrap::getObjectManager();
        $this->request = $this->objectManager->get(RequestInterface::class);
        $this->componentFactory = $this->objectManager->get(UiComponentFactory::class);
    }

    /**
     * @magentoDataFixture Magento/Cms/_files/pages.php
     *
     * @return void
     */
    public function testPageFilteringByTitlePart(): void
    {
        $this->request->setParams(['search' => 'Cms Page 1']);
        $data = $this->getComponentProvidedData('cms_page_listing');
        $items = $data['items'];
        $this->assertCount(1, $items);
        $this->assertEquals('page100', reset($items)[PageInterface::IDENTIFIER]);
    }

    /**
     * @magentoDataFixture Magento/Cms/_files/blocks.php
     *
     * @return void
     */
    public function testBlockFilteringByTitlePart(): void
    {
        $this->request->setParams(['search' => 'Enabled CMS Block']);
        $data = $this->getComponentProvidedData('cms_block_listing');
        $items = $data['items'];
        $this->assertCount(1, $items);
        $this->assertEquals('enabled_block', reset($items)[BlockInterface::IDENTIFIER]);
    }

    /**
     * Call prepare method in the child components
     *
     * @param UiComponentInterface $component
     * @return void
     */
    private function prepareChildComponents(UiComponentInterface $component): void
    {
        foreach ($component->getChildComponents() as $child) {
            $this->prepareChildComponents($child);
        }

        $component->prepare();
    }

    /**
     * Get component provided data
     *
     * @param string $namespace
     * @return array
     */
    private function getComponentProvidedData(string $namespace): array
    {
        $component = $this->componentFactory->create($namespace);
        $this->prepareChildComponents($component);

        return $component->getContext()->getDataProvider()->getData();
    }
}

Spamworldpro Mini