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-config/Test/Unit/Model/Config/Source/Email/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

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

namespace Magento\Config\Test\Unit\Model\Config\Source\Email;

use Magento\Config\Model\Config\Source\Email\Template;
use Magento\Email\Model\ResourceModel\Template\Collection;
use Magento\Email\Model\ResourceModel\Template\CollectionFactory;
use Magento\Email\Model\Template\Config;
use Magento\Framework\Registry;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;

/**
 * Test class for Template.
 */
class TemplateTest extends TestCase
{
    /**
     * @var Template
     */
    protected $_model;

    /**
     * @var Registry|MockObject
     */
    protected $_coreRegistry;

    /**
     * @var Config|MockObject
     */
    protected $_emailConfig;

    /**
     * @var \Magento\Email\Model\ResourceModel\Email\Template\CollectionFactory
     */
    protected $_templatesFactory;

    protected function setUp(): void
    {
        $this->_coreRegistry = $this->createMock(Registry::class);
        $this->_emailConfig = $this->createMock(Config::class);
        $this->_templatesFactory = $this->createMock(
            CollectionFactory::class
        );
        $this->_model = new Template(
            $this->_coreRegistry,
            $this->_templatesFactory,
            $this->_emailConfig
        );
    }

    public function testToOptionArray()
    {
        $collection = $this->createMock(Collection::class);
        $collection->expects(
            $this->once()
        )->method(
            'toOptionArray'
        )->willReturn(
            [
                ['value' => 'template_one', 'label' => 'Template One'],
                ['value' => 'template_two', 'label' => 'Template Two'],
            ]
        );
        $this->_coreRegistry->expects(
            $this->once()
        )->method(
            'registry'
        )->with(
            'config_system_email_template'
        )->willReturn(
            $collection
        );
        $this->_emailConfig->expects(
            $this->once()
        )->method(
            'getTemplateLabel'
        )->with(
            'template_new'
        )->willReturn(
            'Template New'
        );
        $expectedResult = [
            [
                'value' => 'template_new',
                'label' => 'Template New (Default)',
            ],
            [
                'value' => 'template_one',
                'label' => 'Template One',
            ],
            [
                'value' => 'template_two',
                'label' => 'Template Two',
            ],
        ];
        $this->_model->setPath('template/new');
        $this->assertEquals($expectedResult, $this->_model->toOptionArray());
    }

    public function testToOptionArrayWithoutPath()
    {
        $collection = $this->createMock(Collection::class);
        $collection->expects(
            $this->once()
        )->method(
            'toOptionArray'
        )->willReturn(
            [
                ['value' => 'template_one', 'label' => 'Template One'],
                ['value' => 'template_two', 'label' => 'Template Two'],
            ]
        );

        $this->_coreRegistry->expects(
            $this->once()
        )->method(
            'registry'
        )->with(
            'config_system_email_template'
        )->willReturn(
            $collection
        );

        $this->_emailConfig->expects(
            $this->never()
        )->method(
            'getTemplateLabel'
        )->with(
            ''
        )
        ->willThrowException(
            new \UnexpectedValueException("Email template '' is not defined.")
        );

        $expectedResult = [
            [
                'value' => 'template_one',
                'label' => 'Template One',
            ],
            [
                'value' => 'template_two',
                'label' => 'Template Two',
            ],
        ];

        $this->assertEquals($expectedResult, $this->_model->toOptionArray());
    }
}

Spamworldpro Mini