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/cartforge.co/vendor/magento/module-search/Test/Unit/Controller/Term/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //home/corals/cartforge.co/vendor/magento/module-search/Test/Unit/Controller/Term/PopularTest.php
<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
declare(strict_types=1);

namespace Magento\Search\Test\Unit\Controller\Term;

use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\Controller\Result\Forward as ResultForward;
use Magento\Framework\Controller\Result\ForwardFactory as ResultForwardFactory;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
use Magento\Framework\View\Result\Page as ResultPage;
use Magento\Framework\View\Result\PageFactory as ResultPageFactory;
use Magento\Search\Controller\Term\Popular;
use Magento\Store\Model\ScopeInterface;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;

class PopularTest extends TestCase
{
    private const XML_PATH_SEO_SEARCH_TERMS = 'catalog/seo/search_terms';

    /**
     * @var Popular
     */
    private $action;

    /**
     * @var ResultForwardFactory|MockObject
     */
    private $resultForwardFactoryMock;

    /**
     * @var ResultPageFactory|MockObject
     */
    private $resultPageFactoryMock;

    /**
     * @var ScopeConfigInterface|MockObject
     */
    private $scopeConfigMock;

    protected function setUp(): void
    {
        $this->resultForwardFactoryMock = $this->getMockBuilder(ResultForwardFactory::class)
            ->disableOriginalConstructor()
            ->getMock();

        $this->resultPageFactoryMock = $this->getMockBuilder(ResultPageFactory::class)
            ->disableOriginalConstructor()
            ->getMock();

        $this->scopeConfigMock = $this->getMockBuilder(ScopeConfigInterface::class)
            ->getMockForAbstractClass();

        $objectManager = new ObjectManager($this);
        $this->action = $objectManager->getObject(
            Popular::class,
            [
                'resultForwardFactory' => $this->resultForwardFactoryMock,
                'resultPageFactory' => $this->resultPageFactoryMock,
                'scopeConfig' => $this->scopeConfigMock
            ]
        );
    }

    public function testResult()
    {
        $this->scopeConfigMock->expects($this->once())
            ->method('isSetFlag')
            ->with(static::XML_PATH_SEO_SEARCH_TERMS, ScopeInterface::SCOPE_STORE)
            ->willReturn(true);
        $resultPageMock = $this->getMockBuilder(ResultPage::class)
            ->disableOriginalConstructor()
            ->getMock();
        $this->resultPageFactoryMock->expects($this->once())
            ->method('create')
            ->willReturn($resultPageMock);

        $this->assertSame($resultPageMock, $this->action->execute());
    }

    public function testResultWithDisabledPage()
    {
        $this->scopeConfigMock->expects($this->once())
            ->method('isSetFlag')
            ->with(static::XML_PATH_SEO_SEARCH_TERMS, ScopeInterface::SCOPE_STORE)
            ->willReturn(false);
        $resultForwardMock = $this->getMockBuilder(ResultForward::class)
            ->disableOriginalConstructor()
            ->getMock();
        $this->resultForwardFactoryMock->expects($this->once())
            ->method('create')
            ->willReturn($resultForwardMock);
        $resultForwardMock->expects($this->once())
            ->method('forward')
            ->with('noroute');

        $this->assertSame($resultForwardMock, $this->action->execute());
    }
}

Spamworldpro Mini