Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
DescriptionGeneratorTest.php
Go to the documentation of this file.
1 <?php
7 
8 class DescriptionGeneratorTest extends \PHPUnit\Framework\TestCase
9 {
13  private $descriptionParagraphGeneratorMock;
14 
18  private $mixinManagerMock;
19 
23  private $paragraphs = [
24  'Paragraph#1', 'Paragraph#2', 'Paragraph#3'
25  ];
26 
30  private $descriptionConfigWithMixin = [
31  'paragraphs' => [
32  'count-min' => 3,
33  'count-max' => 3
34  ],
35  'mixin' => [
36  'tags' => ['p', 'b', 'div']
37  ]
38  ];
39 
43  private $descriptionConfigWithoutMixin = [
44  'paragraphs' => [
45  'count-min' => 3,
46  'count-max' => 3
47  ]
48  ];
49 
50  public function setUp()
51  {
52  $this->descriptionParagraphGeneratorMock =
53  $this->createMock(\Magento\Setup\Model\Description\DescriptionParagraphGenerator::class);
54  $this->descriptionParagraphGeneratorMock
55  ->expects($this->exactly(3))
56  ->method('generate')
57  ->will($this->onConsecutiveCalls(
58  $this->paragraphs[0],
59  $this->paragraphs[1],
60  $this->paragraphs[2]
61  ));
62 
63  $this->mixinManagerMock = $this->createMock(\Magento\Setup\Model\Description\MixinManager::class);
64  }
65 
66  public function testGeneratorWithMixin()
67  {
68  $descriptionWithMixin = 'Some description with mixin';
69  $this->mixinManagerMock
70  ->expects($this->once())
71  ->method('apply')
72  ->with(
73  implode(PHP_EOL, $this->paragraphs),
74  $this->descriptionConfigWithMixin['mixin']['tags']
75  )
76  ->willReturn($descriptionWithMixin);
77 
78  $generator = new \Magento\Setup\Model\Description\DescriptionGenerator(
79  $this->descriptionParagraphGeneratorMock,
80  $this->mixinManagerMock,
81  $this->descriptionConfigWithMixin
82  );
83 
84  $this->assertEquals($descriptionWithMixin, $generator->generate());
85  }
86 
87  public function testGeneratorWithoutMixin()
88  {
89  $generator = new \Magento\Setup\Model\Description\DescriptionGenerator(
90  $this->descriptionParagraphGeneratorMock,
91  $this->mixinManagerMock,
92  $this->descriptionConfigWithoutMixin
93  );
94 
95  $this->assertEquals(implode(PHP_EOL, $this->paragraphs), $generator->generate());
96  }
97 }