DescriptionGeneratorTest.php 2.76 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
<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
namespace Magento\Setup\Test\Unit\Model\Description;

class DescriptionGeneratorTest extends \PHPUnit\Framework\TestCase
{
    /**
     * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Setup\Model\Description\DescriptionParagraphGenerator
     */
    private $descriptionParagraphGeneratorMock;

    /**
     * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Setup\Model\Description\MixinManager
     */
    private $mixinManagerMock;

    /**
     * @var array
     */
    private $paragraphs = [
        'Paragraph#1', 'Paragraph#2', 'Paragraph#3'
     ];

    /**
     * @var array
     */
    private $descriptionConfigWithMixin = [
        'paragraphs' => [
            'count-min' => 3,
            'count-max' => 3
        ],
        'mixin' => [
            'tags' => ['p', 'b', 'div']
        ]
    ];

    /**
     * @var array
     */
    private $descriptionConfigWithoutMixin = [
        'paragraphs' => [
            'count-min' => 3,
            'count-max' => 3
        ]
    ];

    public function setUp()
    {
        $this->descriptionParagraphGeneratorMock =
            $this->createMock(\Magento\Setup\Model\Description\DescriptionParagraphGenerator::class);
        $this->descriptionParagraphGeneratorMock
            ->expects($this->exactly(3))
            ->method('generate')
            ->will($this->onConsecutiveCalls(
                $this->paragraphs[0],
                $this->paragraphs[1],
                $this->paragraphs[2]
            ));

        $this->mixinManagerMock = $this->createMock(\Magento\Setup\Model\Description\MixinManager::class);
    }

    public function testGeneratorWithMixin()
    {
        $descriptionWithMixin = 'Some description with mixin';
        $this->mixinManagerMock
            ->expects($this->once())
            ->method('apply')
            ->with(
                implode(PHP_EOL, $this->paragraphs),
                $this->descriptionConfigWithMixin['mixin']['tags']
            )
            ->willReturn($descriptionWithMixin);

        $generator = new \Magento\Setup\Model\Description\DescriptionGenerator(
            $this->descriptionParagraphGeneratorMock,
            $this->mixinManagerMock,
            $this->descriptionConfigWithMixin
        );

        $this->assertEquals($descriptionWithMixin, $generator->generate());
    }

    public function testGeneratorWithoutMixin()
    {
        $generator = new \Magento\Setup\Model\Description\DescriptionGenerator(
            $this->descriptionParagraphGeneratorMock,
            $this->mixinManagerMock,
            $this->descriptionConfigWithoutMixin
        );

        $this->assertEquals(implode(PHP_EOL, $this->paragraphs), $generator->generate());
    }
}