DeployStaticContentCommandTest.php 5.77 KB
Newer Older
Ketan's avatar
Ketan committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151
<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
namespace Magento\Deploy\Test\Unit\Console\Command;

use Magento\Deploy\Console\Command\DeployStaticContentCommand;
use Symfony\Component\Console\Tester\CommandTester;
use Magento\Framework\Validator\Locale;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;

require 'FunctionExistMock.php';

class DeployStaticContentCommandTest extends \PHPUnit_Framework_TestCase
{
    /**
     * @var \Magento\Deploy\Model\DeployManager|\PHPUnit_Framework_MockObject_MockObject
     */
    private $deployer;

    /**
     * @var \Magento\Framework\ObjectManagerInterface|\PHPUnit_Framework_MockObject_MockObject
     */
    private $objectManager;

    /**
     * @var \Magento\Framework\App\ObjectManagerFactory|\PHPUnit_Framework_MockObject_MockObject
     */
    private $objectManagerFactory;

    /**
     * @var \Magento\Framework\App\Utility\Files|\PHPUnit_Framework_MockObject_MockObject
     */
    private $filesUtil;

    /**
     * @var DeployStaticContentCommand
     */
    private $command;

    /**
     * @var Locale|\PHPUnit_Framework_MockObject_MockObject
     */
    private $validator;

    protected function setUp()
    {
        $this->objectManager = $this->getMockForAbstractClass(\Magento\Framework\ObjectManagerInterface::class);
        $this->objectManagerFactory = $this->getMock(
            \Magento\Framework\App\ObjectManagerFactory::class,
            [],
            [],
            '',
            false
        );
        $this->deployer = $this->getMock(\Magento\Deploy\Model\DeployManager::class, [], [], '', false);
        $this->filesUtil = $this->getMock(\Magento\Framework\App\Utility\Files::class, [], [], '', false);

        $this->validator = $this->getMock(\Magento\Framework\Validator\Locale::class, [], [], '', false);
        $this->command = (new ObjectManager($this))->getObject(DeployStaticContentCommand::class, [
            'objectManagerFactory' => $this->objectManagerFactory,
            'validator' => $this->validator,
            'objectManager' => $this->objectManager,
        ]);
    }

    public function testExecute()
    {
        $this->filesUtil->expects(self::any())->method('getStaticPreProcessingFiles')->willReturn([]);
        $this->deployer->expects($this->once())->method('deploy');
        $this->objectManager->expects($this->at(0))->method('create')->willReturn($this->filesUtil);
        $this->objectManager->expects($this->at(1))->method('create')->willReturn($this->deployer);

        $tester = new CommandTester($this->command);
        $tester->execute([]);
    }

    public function testExecuteValidateLanguages()
    {
        $this->filesUtil->expects(self::any())->method('getStaticPreProcessingFiles')->willReturn([]);
        $this->deployer->expects($this->once())->method('deploy');
        $this->objectManager->expects($this->at(0))->method('create')->willReturn($this->filesUtil);
        $this->objectManager->expects($this->at(1))->method('create')->willReturn($this->deployer);
        $this->validator->expects(self::exactly(2))->method('isValid')->willReturnMap([
            ['en_US', true],
            ['uk_UA', true],
        ]);

        $tester = new CommandTester($this->command);
        $tester->execute(['languages' => ['en_US', 'uk_UA']]);
    }

    /**
     * @expectedException \InvalidArgumentException
     * @expectedExceptionMessage --language (-l) and --exclude-language cannot be used at the same tim
     */
    public function testExecuteIncludedExcludedLanguages()
    {
        $this->filesUtil->expects(self::any())->method('getStaticPreProcessingFiles')->willReturn([]);
        $this->objectManager->expects($this->at(0))->method('create')->willReturn($this->filesUtil);
        $this->validator->expects(self::exactly(2))->method('isValid')->willReturnMap([
            ['en_US', true],
            ['uk_UA', true],
        ]);

        $tester = new CommandTester($this->command);
        $tester->execute(['--language' => ['en_US', 'uk_UA'], '--exclude-language' => 'ru_RU']);
    }

    /**
     * @expectedException \InvalidArgumentException
     * @expectedExceptionMessage --area (-a) and --exclude-area cannot be used at the same tim
     */
    public function testExecuteIncludedExcludedAreas()
    {
        $this->filesUtil->expects(self::any())->method('getStaticPreProcessingFiles')->willReturn([]);
        $this->objectManager->expects($this->at(0))->method('create')->willReturn($this->filesUtil);

        $tester = new CommandTester($this->command);
        $tester->execute(['--area' => ['a1', 'a2'], '--exclude-area' => 'a3']);
    }

    /**
     * @expectedException \InvalidArgumentException
     * @expectedExceptionMessage --theme (-t) and --exclude-theme cannot be used at the same tim
     */
    public function testExecuteIncludedExcludedThemes()
    {
        $this->filesUtil->expects(self::any())->method('getStaticPreProcessingFiles')->willReturn([]);
        $this->objectManager->expects($this->at(0))->method('create')->willReturn($this->filesUtil);

        $tester = new CommandTester($this->command);
        $tester->execute(['--theme' => ['t1', 't2'], '--exclude-theme' => 't3']);
    }

    /**
     * @expectedException \InvalidArgumentException
     * @expectedExceptionMessage ARG_IS_WRONG argument has invalid value, please run info:language:list
     */
    public function testExecuteInvalidLanguageArgument()
    {
        $this->filesUtil->expects(self::any())->method('getStaticPreProcessingFiles')->willReturn([]);
        $this->objectManager->expects($this->at(0))
            ->method('create')
            ->willReturn($this->filesUtil);
        $wrongParam = ['languages' => ['ARG_IS_WRONG']];
        $commandTester = new CommandTester($this->command);
        $commandTester->execute($wrongParam);
    }
}