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/framework/App/Test/Unit/Language/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

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

namespace Magento\Framework\App\Test\Unit\Language;

use Magento\Framework\App\Language\Config;
use Magento\Framework\App\Language\ConfigFactory;
use Magento\Framework\App\Language\Dictionary;
use Magento\Framework\Component\ComponentRegistrar;
use Magento\Framework\Filesystem\Directory\ReadFactory;
use Magento\Framework\Filesystem\File\ReadInterface;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;

class DictionaryTest extends TestCase
{
    /**
     * @var Dictionary
     */
    private $model;

    /**
     * @var MockObject
     */
    private $readFactory;

    /**
     * @var MockObject
     */
    private $componentRegistrar;

    /**
     * @var MockObject
     */
    private $configFactory;

    /**
     * @inheritDoc
     */
    protected function setUp(): void
    {
        $this->readFactory = $this->createMock(ReadFactory::class);
        $this->componentRegistrar = $this->createMock(ComponentRegistrar::class);
        $this->configFactory = $this->getMockBuilder(ConfigFactory::class)
            ->onlyMethods(['create'])
            ->disableOriginalConstructor()
            ->getMock();
        $this->model = new Dictionary($this->readFactory, $this->componentRegistrar, $this->configFactory);
    }

    /**
     * @return void
     */
    public function testDictionaryGetter(): void
    {
        $csvFileName = 'abc.csv';
        $data = [['one', '1'], ['two', '2']];
        $expected = [];
        foreach ($data as $item) {
            $expected[$item[0]] = $item[1];
        }

        $file = $this->getMockForAbstractClass(ReadInterface::class);
        $willReturnArgs = [];

        for ($i = 0, $count = count($data); $i < $count; $i++) {
            $willReturnArgs[] = $data[$i];
        }
        $willReturnArgs[] = false;
        $file
            ->method('readCsv')
            ->willReturnOnConsecutiveCalls(...$willReturnArgs);

        $readMock = $this->getMockForAbstractClass(\Magento\Framework\Filesystem\Directory\ReadInterface::class);
        $readMock->expects($this->any())->method('readFile')->willReturnMap([
            ['language.xml', $readMock],
            [$csvFileName, $file],
        ]);
        $readMock->expects($this->any())->method('openFile')->willReturn($file);
        $readMock->expects($this->any())->method('isExist')->willReturn(true);
        $readMock->expects($this->any())->method('search')->willReturn([$csvFileName]);

        $this->componentRegistrar->expects($this->once())->method('getPaths')->willReturn(['foo/en_us']);
        $this->componentRegistrar->expects($this->once())->method('getPath')->willReturn('foo/en_us');

        $this->readFactory->expects($this->any())->method("create")->willReturn($readMock);

        $languageConfig = $this->createMock(Config::class);
        $languageConfig->expects($this->any())->method('getCode')->willReturn('en_US');
        $languageConfig->expects($this->any())->method('getVendor')->willReturn('foo');
        $languageConfig->expects($this->any())->method('getPackage')->willReturn('en_us');
        $languageConfig->expects($this->any())->method('getSortOrder')->willReturn(0);
        $languageConfig->expects($this->any())->method('getUses')->willReturn([]);

        $this->configFactory->expects($this->any())->method('create')->willReturn($languageConfig);

        $result = $this->model->getDictionary("en_US");
        $this->assertSame($expected, $result);
    }
}

Spamworldpro Mini