Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
NewVideoTest.php
Go to the documentation of this file.
1 <?php
7 
8 class NewVideoTest extends \PHPUnit\Framework\TestCase
9 {
13  protected $contextMock;
14 
15  /*
16  * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\UrlInterface
17  */
18  protected $urlBuilder;
19 
23  protected $mathRandom;
24 
28  protected $registryMock;
29 
33  protected $formFactoryMock;
34 
38  protected $jsonEncoderMock;
39 
43  protected $mediaHelper;
44 
49  protected $block;
50 
51  protected function setUp()
52  {
53  $this->contextMock = $this->createMock(\Magento\Backend\Block\Template\Context::class);
54  $this->mediaHelper = $this->createMock(\Magento\ProductVideo\Helper\Media::class);
55  $this->mathRandom = $this->createMock(\Magento\Framework\Math\Random::class);
56  $this->urlBuilder = $this->createMock(\Magento\Framework\UrlInterface::class);
57  $this->contextMock->expects($this->any())->method('getMathRandom')->willReturn($this->mathRandom);
58  $this->contextMock->expects($this->any())->method('getUrlBuilder')->willReturn($this->urlBuilder);
59  $this->registryMock = $this->createMock(\Magento\Framework\Registry::class);
60  $this->formFactoryMock = $this->createMock(\Magento\Framework\Data\FormFactory::class);
61  $this->jsonEncoderMock = $this->createMock(\Magento\Framework\Json\EncoderInterface::class);
62 
63  $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
64 
65  $this->block = $objectManager->getObject(
66  \Magento\ProductVideo\Block\Adminhtml\Product\Edit\NewVideo::class,
67  [
68  'context' => $this->contextMock,
69  'mediaHelper' => $this->mediaHelper,
70  'urlBuilder' => $this->urlBuilder,
71  'jsonEncoder' => $this->jsonEncoderMock,
72  'registry' => $this->registryMock,
73  'formFactory' => $this->formFactoryMock,
74  ]
75  );
76  }
77 
78  public function testGetHtmlId()
79  {
80  $this->mathRandom->expects($this->any())->method('getUniqueHash')->with('id_')->willReturn('id_' . rand());
81  $result = $this->block->getHtmlId();
82  $this->assertNotNull($result);
83  }
84 
85  public function testGetWidgetOptions()
86  {
87  $rand = rand();
88  $this->mathRandom->expects($this->any())->method('getUniqueHash')->with('id_')->willReturn('id_' . $rand);
89  $saveVideoUrl = 'http://host/index.php/admin/catalog/product_gallery/upload/key/';
90  $saveRemoteVideoUrl = 'http://host/index.php/admin/product_video/product_gallery/retrieveImage/';
91  $this->urlBuilder->expects($this->exactly(2))->method('getUrl')->willReturnOnConsecutiveCalls(
92  $saveVideoUrl,
93  $saveRemoteVideoUrl
94  );
95  $value = [
96  'saveVideoUrl' => $saveVideoUrl,
97  'saveRemoteVideoUrl' => $saveRemoteVideoUrl,
98  'htmlId' => 'id_' . $rand,
99  'youTubeApiKey' => null,
100  'videoSelector' => '#media_gallery_content'
101  ];
102  $this->jsonEncoderMock->expects($this->once())->method('encode')->with(
103  $value
104  )->willReturn(
105  json_encode($value)
106  );
107  $result = $this->block->getWidgetOptions();
108  $this->assertNotNull($result);
109  }
110 }
$objectManager
Definition: bootstrap.php:17
$value
Definition: gender.phtml:16