Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
DownloadablePanelTest.php
Go to the documentation of this file.
1 <?php
7 
16 
21 class DownloadablePanelTest extends \PHPUnit\Framework\TestCase
22 {
27 
31  protected $locatorMock;
32 
36  protected $arrayManagerMock;
37 
41  protected $productMock;
42 
46  protected $downloadablePanel;
47 
51  protected function setUp()
52  {
53  $this->objectManagerHelper = new ObjectManagerHelper($this);
54  $this->productMock = $this->createMock(ProductInterface::class);
55  $this->locatorMock = $this->createMock(LocatorInterface::class);
56  $this->arrayManagerMock = $this->createMock(ArrayManager::class);
57  $this->downloadablePanel = $this->objectManagerHelper->getObject(
58  DownloadablePanel::class,
59  [
60  'locator' => $this->locatorMock,
61  'arrayManager' => $this->arrayManagerMock
62  ]
63  );
64  }
65 
72  public function testModifyData($typeId, $isDownloadable)
73  {
74  $productId = 1;
75  $this->locatorMock->expects(static::once())
76  ->method('getProduct')
77  ->willReturn($this->productMock);
78  $this->productMock->expects(static::once())
79  ->method('getId')
80  ->willReturn($productId);
81  $this->productMock->expects(static::once())
82  ->method('getTypeId')
83  ->willReturn($typeId);
84  $resultData = [
85  $productId => [
87  ]
88  ];
89 
90  $this->assertEquals($resultData, $this->downloadablePanel->modifyData([]));
91  }
92 
96  public function modifyDataDataProvider()
97  {
98  return [
99  ['typeId' => Type::TYPE_DOWNLOADABLE, 'isDownloadable' => '1'],
100  ['typeId' => 'someType', 'isDownloadable' => '0'],
101  ];
102  }
103 
107  public function testModifyMeta()
108  {
109  $this->locatorMock->expects(static::once())
110  ->method('getProduct')
111  ->willReturn($this->productMock);
112  $this->productMock->expects(static::any())
113  ->method('getTypeId');
114  $this->arrayManagerMock->expects(static::exactly(3))
115  ->method('set')
116  ->willReturn([]);
117 
118  $this->assertEquals([], $this->downloadablePanel->modifyMeta([]));
119  }
120 }