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/SearchEngine/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

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

namespace Magento\Search\Test\Unit\Model\SearchEngine;

use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
use Magento\Search\Model\SearchEngine\Validator;
use Magento\Search\Model\SearchEngine\ValidatorInterface;
use PHPUnit\Framework\TestCase;

/**
 * Test search engine validator
 */
class ValidatorTest extends TestCase
{
    private $validator;

    private $otherEngineValidatorMock;

    private $scopeConfigMock;

    protected function setUp(): void
    {
        $objectManager = new ObjectManager($this);
        $this->otherEngineValidatorMock = $this->getMockForAbstractClass(ValidatorInterface::class);
        $this->scopeConfigMock = $this->getMockBuilder(ScopeConfigInterface::class)->getMock();
        $this->validator = $objectManager->getObject(
            Validator::class,
            [
                'scopeConfig' => $this->scopeConfigMock,
                'engineValidators' => ['otherEngine' => $this->otherEngineValidatorMock],
                'excludedEngineList' => ['badEngine' => 'Bad Engine']
            ]
        );
    }

    public function testValidateValid()
    {
        $expectedErrors = [];

        $this->scopeConfigMock
            ->expects($this->once())
            ->method('getValue')
            ->with('catalog/search/engine')
            ->willReturn('otherEngine');

        $this->otherEngineValidatorMock->expects($this->once())->method('validate')->willReturn([]);

        $this->assertEquals($expectedErrors, $this->validator->validate());
    }

    public function testValidateExcludedList()
    {
        $this->scopeConfigMock
            ->expects($this->once())
            ->method('getValue')
            ->with('catalog/search/engine')
            ->willReturn('badEngine');

        $expectedErrors = [
            "Your current search engine, 'Bad Engine', is not supported."
            . " You must install a supported search engine before upgrading."
            . " See the System Upgrade Guide for more information."
        ];

        $this->assertEquals($expectedErrors, $this->validator->validate());
    }

    public function testValidateInvalid()
    {
        $expectedErrors = ['Validation failed for otherEngine'];

        $this->scopeConfigMock
            ->expects($this->once())
            ->method('getValue')
            ->with('catalog/search/engine')
            ->willReturn('otherEngine');
        $this->otherEngineValidatorMock
            ->expects($this->once())
            ->method('validate')
            ->willReturn($expectedErrors);

        $this->assertEquals($expectedErrors, $this->validator->validate());
    }
}

Spamworldpro Mini