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/vendor/magento/module-search/Test/Unit/Model/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

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

namespace Magento\Search\Test\Unit\Model;

use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Search\Model\PopularSearchTerms;
use Magento\Search\Model\ResourceModel\Query\Collection;
use Magento\Store\Model\ScopeInterface;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;

/**
 * @covers \Magento\Search\Model\PopularSearchTerms
 */
class PopularSearchTermsTest extends TestCase
{
    /**
     * Testable Object
     *
     * @var PopularSearchTerms
     */
    private $popularSearchTerms;

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

    /**
     * @var Collection|MockObject
     */
    private $queryCollectionMock;

    /**
     * Set Up
     *
     * @return void
     */
    protected function setUp(): void
    {
        $this->scopeConfigMock = $this->getMockForAbstractClass(ScopeConfigInterface::class);
        $this->queryCollectionMock = $this->createMock(Collection::class);
        $this->popularSearchTerms = new PopularSearchTerms($this->scopeConfigMock, $this->queryCollectionMock);
    }

    /**
     * Test isCacheableDataProvider method
     *
     * @return void
     */
    public function testIsCacheable()
    {
        $term = 'test1';
        $storeId = 1;
        $pageSize = 35;

        $this->scopeConfigMock->expects($this->exactly(2))
            ->method('getValue')
            ->with(
                PopularSearchTerms::XML_PATH_MAX_COUNT_CACHEABLE_SEARCH_TERMS,
                ScopeInterface::SCOPE_STORE,
                $storeId
            )->willReturn($pageSize);
        $this->queryCollectionMock->expects($this->exactly(2))
            ->method('isTopSearchResult')
            ->with($term, $storeId, $pageSize)
            ->willReturn(true, false);

        $this->assertTrue($this->popularSearchTerms->isCacheable($term, $storeId));
        $this->assertFalse($this->popularSearchTerms->isCacheable($term, $storeId));
    }
}

Spamworldpro Mini