Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ProductFrontendActionSectionTest.php
Go to the documentation of this file.
1 <?php
7 
11 use Psr\Log\LoggerInterface;
13 
14 class ProductFrontendActionSectionTest extends \PHPUnit\Framework\TestCase
15 {
17  protected $model;
18 
20  protected $synchronizerMock;
21 
24 
26  private $appConfigMock;
27 
29  private $loggerMock;
30 
31  protected function setUp()
32  {
33  $this->synchronizerMock = $this
34  ->getMockBuilder(Synchronizer::class)
35  ->disableOriginalConstructor()
36  ->getMock();
37  $this->safeReflectionClassMock = $this->getMockBuilder(\SafeReflectionClass::class)
38  ->disableOriginalConstructor()
39  ->getMock();
40  $this->appConfigMock = $this->getMockBuilder(Config::class)
41  ->disableOriginalConstructor()
42  ->getMock();
43  $this->loggerMock = $this->getMockBuilder(LoggerInterface::class)
44  ->getMockForAbstractClass();
45 
46  $this->model = new ProductFrontendActionSection(
47  $this->synchronizerMock,
48  '1',
49  $this->loggerMock,
50  $this->appConfigMock
51  );
52  }
53 
54  public function testGetSectionData()
55  {
56  $this->appConfigMock->expects($this->once())
57  ->method('getValue')
59  ->willReturn(1);
60  $actionFirst = $this->getMockBuilder(ProductFrontendActionInterface::class)
61  ->getMockForAbstractClass();
62  $actionSecond = $this->getMockBuilder(ProductFrontendActionInterface::class)
63  ->getMockForAbstractClass();
64  $actions = [$actionFirst, $actionSecond];
65  $actionFirst->expects($this->exactly(2))
66  ->method('getProductId')
67  ->willReturn(1);
68  $actionFirst->expects($this->once())
69  ->method('getAddedAt')
70  ->willReturn(12);
71  $actionSecond->expects($this->once())
72  ->method('getAddedAt')
73  ->willReturn(13);
74  $actionSecond->expects($this->exactly(2))
75  ->method('getProductId')
76  ->willReturn(2);
77  $this->synchronizerMock->expects($this->once())
78  ->method('getActionsByType')
79  ->willReturn($actions);
80 
81  $this->assertEquals(
82  [
83  'count' => 2,
84  'items' => [
85  1 => [
86  'added_at' => 12,
87  'product_id' => 1
88  ],
89  2 => [
90  'added_at' => 13,
91  'product_id' => 2
92  ]
93  ]
94  ],
95  $this->model->getSectionData()
96  );
97  }
98 
99  public function testGetSectionDataNoSync()
100  {
101  $this->appConfigMock->expects($this->once())
102  ->method('getValue')
104  ->willReturn(0);
105 
106  $this->assertEquals(
107  [
108  'count' => 0,
109  'items' => [
110  ]
111  ],
112  $this->model->getSectionData()
113  );
114  }
115 }