Exemplo n.º 1
0
 public function testAfterGetOptions()
 {
     $resultJson = '[]';
     $this->jsonDecoder->expects($this->once())->method('decode')->with('[]')->willReturn([]);
     $expected = ['configurable_attribute_1' => [['mediaType' => 'type', 'videoUrl' => 'url', 'isBase' => true]]];
     $this->jsonEncoder->expects($this->any())->method('encode')->with($expected)->willReturn(json_encode($expected));
     $blockMock = $this->getMockBuilder('\\Magento\\ProductVideo\\Block\\Product\\View\\Gallery')->disableOriginalConstructor()->getMock();
     $result = $this->plugin->afterGetOptionsMediaGalleryDataJson($blockMock, $resultJson);
     $this->assertEquals(json_encode($expected), $result);
 }
Exemplo n.º 2
0
 public function testGetWidgetOptions()
 {
     $rand = rand();
     $this->mathRandom->expects($this->any())->method('getUniqueHash')->with('id_')->willReturn('id_' . $rand);
     $saveVideoUrl = 'http://host/index.php/admin/catalog/product_gallery/upload/key/';
     $saveRemoteVideoUrl = 'http://host/index.php/admin/product_video/product_gallery/retrieveImage/';
     $this->urlBuilder->expects($this->exactly(2))->method('getUrl')->willReturnOnConsecutiveCalls($saveVideoUrl, $saveRemoteVideoUrl);
     $value = ['saveVideoUrl' => $saveVideoUrl, 'saveRemoteVideoUrl' => $saveRemoteVideoUrl, 'htmlId' => 'id_' . $rand];
     $this->jsonEncoderMock->expects($this->once())->method('encode')->with($value)->willReturn(json_encode($value));
     $this->block->getWidgetOptions();
 }
 /**
  * Setup
  *
  * @return void
  */
 public function setUp()
 {
     $this->config = $this->getMockBuilder('Magento\\NewRelicReporting\\Model\\Config')->disableOriginalConstructor()->setMethods(['isNewRelicEnabled'])->getMock();
     $this->collectMock = $this->getMockBuilder('Magento\\NewRelicReporting\\Model\\Module\\Collect')->disableOriginalConstructor()->setMethods(['getModuleData'])->getMock();
     $this->systemFactoryMock = $this->getMockBuilder('Magento\\NewRelicReporting\\Model\\SystemFactory')->disableOriginalConstructor()->setMethods(['create'])->getMock();
     $this->systemModelMock = $this->getMockBuilder('Magento\\NewRelicReporting\\Model\\System')->disableOriginalConstructor()->getMock();
     $this->jsonEncoderMock = $this->getMockBuilder('Magento\\Framework\\Json\\EncoderInterface')->getMock();
     $this->systemFactoryMock->expects($this->any())->method('create')->willReturn($this->systemModelMock);
     $this->jsonEncoderMock->expects($this->any())->method('encode')->willReturn('json_string');
     $this->model = new ReportModulesInfo($this->config, $this->collectMock, $this->systemFactoryMock, $this->jsonEncoderMock);
 }
 /**
  * Test case when module is enabled in config
  *
  * @return void
  */
 public function testReportSystemCacheFlush()
 {
     $testType = 'systemCacheFlush';
     $testAction = 'JSON string';
     /** @var \Magento\Framework\Event\Observer|\PHPUnit_Framework_MockObject_MockObject $eventObserver */
     $eventObserver = $this->getMockBuilder('Magento\\Framework\\Event\\Observer')->disableOriginalConstructor()->getMock();
     $this->config->expects($this->once())->method('isNewRelicEnabled')->willReturn(true);
     $this->jsonEncoder->expects($this->once())->method('encode')->willReturn($testAction);
     $this->systemModel->expects($this->once())->method('setData')->with(['type' => $testType, 'action' => $testAction])->willReturnSelf();
     $this->systemModel->expects($this->once())->method('save');
     $this->model->execute($eventObserver);
 }
 /**
  * Setup
  *
  * @return void
  */
 public function setUp()
 {
     $this->config = $this->getMockBuilder('Magento\\NewRelicReporting\\Model\\Config')->disableOriginalConstructor()->setMethods(['isNewRelicEnabled'])->getMock();
     $this->collect = $this->getMockBuilder('Magento\\NewRelicReporting\\Model\\Module\\Collect')->disableOriginalConstructor()->setMethods(['getModuleData'])->getMock();
     $this->systemFactory = $this->getMockBuilder('Magento\\NewRelicReporting\\Model\\SystemFactory')->disableOriginalConstructor()->setMethods(['create'])->getMock();
     $this->systemModel = $this->getMockBuilder('Magento\\NewRelicReporting\\Model\\System')->disableOriginalConstructor()->getMock();
     $this->jsonEncoder = $this->getMockBuilder('Magento\\Framework\\Json\\EncoderInterface')->getMock();
     $this->dateTime = $this->getMockBuilder('Magento\\Framework\\Stdlib\\DateTime')->disableOriginalConstructor()->setMethods(['formatDate'])->getMock();
     $this->systemFactory->expects($this->any())->method('create')->willReturn($this->systemModel);
     $this->jsonEncoder->expects($this->any())->method('encode')->willReturn('json_string');
     $this->dateTime->expects($this->any())->method('formatDate')->willReturn('1970-01-01 00:00:00');
     $this->model = new ReportModulesInfo($this->config, $this->collect, $this->systemFactory, $this->jsonEncoder, $this->dateTime);
 }
 public function testGetUsersPositiveNumberOfRolesAndJsonTrue()
 {
     $roleId = 1;
     $roles = ['role1', 'role2', 'role3'];
     /** @var \Magento\Authorization\Model\Role|\PHPUnit_Framework_MockObject_MockObject */
     $roleModelMock = $this->getMockBuilder('Magento\\Authorization\\Model\\Role')->disableOriginalConstructor()->setMethods([])->getMock();
     $this->requestInterfaceMock->expects($this->at(0))->method('getParam')->willReturn("");
     $this->requestInterfaceMock->expects($this->at(1))->method('getParam')->willReturn($roleId);
     $this->requestInterfaceMock->expects($this->at(2))->method('getParam')->willReturn($roleId);
     $this->registryMock->expects($this->once())->method('registry')->with(\Magento\User\Controller\Adminhtml\User\Role\SaveRole::IN_ROLE_USER_FORM_DATA_SESSION_KEY)->willReturn('role1=value1&role2=value2&role3=value3');
     $this->roleFactoryMock->expects($this->never())->method('create')->willReturn($roleModelMock);
     $this->jsonEncoderMock->expects($this->once())->method('encode')->willReturn($roles);
     $this->assertEquals($roles, $this->model->getUsers(true));
 }
Exemplo n.º 7
0
 public function testGetUsersPositiveNumberOfRolesAndJsonTrue()
 {
     $roleId = 1;
     $roles = ['role1', 'role2', 'role3'];
     /** @var \Magento\Authorization\Model\Role|\PHPUnit_Framework_MockObject_MockObject */
     $roleModelMock = $this->getMockBuilder('Magento\\Authorization\\Model\\Role')->disableOriginalConstructor()->setMethods([])->getMock();
     $this->requestInterfaceMock->expects($this->at(0))->method('getParam')->willReturn("");
     $this->requestInterfaceMock->expects($this->at(1))->method('getParam')->willReturn($roleId);
     $this->requestInterfaceMock->expects($this->at(2))->method('getParam')->willReturn($roleId);
     $this->roleFactoryMock->expects($this->once())->method('create')->willReturn($roleModelMock);
     $roleModelMock->expects($this->once())->method('setId')->willReturnSelf();
     $roleModelMock->expects($this->once())->method('getRoleUsers')->willReturn($roles);
     $this->jsonEncoderMock->expects($this->once())->method('encode')->willReturn($roles);
     $this->assertEquals($roles, $this->model->getUsers(true));
 }
 /**
  * Test case when module is enabled in config
  *
  * @return void
  */
 public function testReportProductDeleted()
 {
     $testType = 'adminProductChange';
     $testAction = 'JSON string';
     /** @var \Magento\Framework\Event\Observer|\PHPUnit_Framework_MockObject_MockObject $eventObserver */
     $eventObserver = $this->getMockBuilder('Magento\\Framework\\Event\\Observer')->disableOriginalConstructor()->getMock();
     $this->config->expects($this->once())->method('isNewRelicEnabled')->willReturn(true);
     $event = $this->getMockBuilder('Magento\\Framework\\Event')->setMethods(['getProduct'])->disableOriginalConstructor()->getMock();
     $eventObserver->expects($this->once())->method('getEvent')->willReturn($event);
     $product = $this->getMockBuilder('Magento\\Catalog\\Model\\Product')->setMethods(['getId'])->disableOriginalConstructor()->getMock();
     $event->expects($this->once())->method('getProduct')->willReturn($product);
     $this->jsonEncoder->expects($this->once())->method('encode')->willReturn($testAction);
     $this->systemModel->expects($this->once())->method('setData')->with(['type' => $testType, 'action' => $testAction])->willReturnSelf();
     $this->systemModel->expects($this->once())->method('save');
     $this->model->execute($eventObserver);
 }
Exemplo n.º 9
0
 /**
  * Tests client request with Bad status
  *
  * @return void
  */
 public function testSendRequestStatusBad()
 {
     $json = '{"eventType":"Cron","appName":"app_name","appId":"app_id"}';
     $statusBad = '401';
     $uri = 'https://example.com/listener';
     $method = ZendClient::POST;
     $headers = ['X-Insert-Key' => 'insert_key_value', 'Content-Type' => 'application/json'];
     $accId = 'acc_id';
     $appId = 'app_id';
     $appName = 'app_name';
     $insightApiKey = 'insert_key_value';
     $this->zendClientMock->expects($this->once())->method('setUri')->with($uri)->willReturnSelf();
     $this->zendClientMock->expects($this->once())->method('setMethod')->with($method)->willReturnSelf();
     $this->zendClientMock->expects($this->once())->method('setHeaders')->with($headers)->willReturnSelf();
     $this->zendClientMock->expects($this->once())->method('setRawData')->with($json)->willReturnSelf();
     $this->configMock->expects($this->once())->method('getNewRelicAccountId')->willReturn($accId);
     $this->configMock->expects($this->once())->method('getInsightsApiUrl')->willReturn($uri);
     $this->configMock->expects($this->once())->method('getInsightsInsertKey')->willReturn($insightApiKey);
     $this->configMock->expects($this->once())->method('getNewRelicAppName')->willReturn($appName);
     $this->configMock->expects($this->once())->method('getNewRelicAppId')->willReturn($appId);
     $this->jsonEncoderMock->expects($this->once())->method('encode')->willReturn($json);
     $zendHttpResponseMock = $this->getMockBuilder('Zend_Http_Response')->disableOriginalConstructor()->getMock();
     $zendHttpResponseMock->expects($this->any())->method('getStatus')->willReturn($statusBad);
     $this->zendClientMock->expects($this->once())->method('request')->willReturn($zendHttpResponseMock);
     $this->zendClientFactoryMock->expects($this->once())->method('create')->willReturn($this->zendClientMock);
     $this->assertInternalType('bool', $this->model->sendRequest());
 }
Exemplo n.º 10
0
 public function testGetImagesJson()
 {
     $url = [['file_1.jpg', 'url_to_the_image/image_1.jpg'], ['file_2.jpg', 'url_to_the_image/image_2.jpg']];
     $mediaPath = [['file_1.jpg', 'catalog/product/image_1.jpg'], ['file_2.jpg', 'catalog/product/image_2.jpg']];
     $sizeMap = [['catalog/product/image_1.jpg', ['size' => 399659]], ['catalog/product/image_2.jpg', ['size' => 879394]]];
     $imagesResult = [['value_id' => '2', 'file' => 'file_2.jpg', 'media_type' => 'image', 'position' => '0', 'url' => 'url_to_the_image/image_2.jpg', 'size' => 879394], ['value_id' => '1', 'file' => 'file_1.jpg', 'media_type' => 'image', 'position' => '1', 'url' => 'url_to_the_image/image_1.jpg', 'size' => 399659]];
     $images = ['images' => [['value_id' => '1', 'file' => 'file_1.jpg', 'media_type' => 'image', 'position' => '1'], ['value_id' => '2', 'file' => 'file_2.jpg', 'media_type' => 'image', 'position' => '0']]];
     $this->content->setElement($this->galleryMock);
     $this->galleryMock->expects($this->once())->method('getImages')->willReturn($images);
     $this->fileSystemMock->expects($this->once())->method('getDirectoryRead')->willReturn($this->readMock);
     $this->mediaConfigMock->expects($this->any())->method('getMediaUrl')->willReturnMap($url);
     $this->mediaConfigMock->expects($this->any())->method('getMediaPath')->willReturnMap($mediaPath);
     $this->readMock->expects($this->any())->method('stat')->willReturnMap($sizeMap);
     $this->jsonEncoderMock->expects($this->once())->method('encode')->willReturnCallback('json_encode');
     $this->assertSame(json_encode($imagesResult), $this->content->getImagesJson());
 }
Exemplo n.º 11
0
 /**
  * @covers Magento\Swatches\Block\Product\Renderer\Listing\Configurable::getSwatchAttributesData
  */
 public function testGetJsonSwatchUsedInProductListing()
 {
     $products = [1 => 'testA', 3 => 'testB'];
     $expected = ['type' => null, 'value' => 'hello', 'label' => $products[3]];
     $this->prepareGetJsonSwatchConfig();
     $this->configurable->setProduct($this->product);
     $this->swatchHelper->expects($this->once())->method('getSwatchAttributesAsArray')->with($this->product)->willReturn([1 => ['options' => $products, 'use_product_image_for_swatch' => true, 'used_in_product_listing' => true, 'attribute_code' => 'code']]);
     $this->swatchHelper->expects($this->once())->method('getSwatchesByOptionsId')->with([1, 3])->willReturn([3 => ['type' => $expected['type'], 'value' => $expected['value']]]);
     $this->jsonEncoder->expects($this->once())->method('encode');
     $this->configurable->getJsonSwatchConfig();
 }
 public function testGetImagesJson()
 {
     $url = [['file_1.jpg', 'url_to_the_image/image_1.jpg'], ['file_2.jpg', 'url_to_the_image/image_2.jpg']];
     $mediaPath = [['file_1.jpg', 'catalog/product/image_1.jpg'], ['file_2.jpg', 'catalog/product/image_2.jpg']];
     // @codingStandardsIgnoreStart
     $encodedString = '[{"value_id":"1","file":"image_1.jpg","media_type":"image","url":"http:\\/\\/magento2.dev\\/pub\\/media\\/catalog\\/product\\/image_1.jpg","size":879394},{"value_id":"2","file":"image_2.jpg","media_type":"image","url":"http:\\/\\/magento2.dev\\/pub\\/media\\/catalog\\/product\\/image`_2.jpg","size":399659}]';
     // @codingStandardsIgnoreEnd
     $images = ['images' => [['value_id' => '1', 'file' => 'file_1.jpg', 'media_type' => 'image'], ['value_id' => '2', 'file' => 'file_2.jpg', 'media_type' => 'image']]];
     $firstStat = ['size' => 879394];
     $secondStat = ['size' => 399659];
     $this->content->setElement($this->galleryMock);
     $this->galleryMock->expects($this->any())->method('getImages')->willReturn($images);
     $this->fileSystemMock->expects($this->once())->method('getDirectoryRead')->willReturn($this->readMock);
     $this->mediaConfigMock->expects($this->any())->method('getMediaUrl')->willReturnMap($url);
     $this->mediaConfigMock->expects($this->any())->method('getMediaPath')->willReturn($mediaPath);
     $this->readMock->expects($this->at(0))->method('stat')->willReturn($firstStat);
     $this->readMock->expects($this->at(1))->method('stat')->willReturn($secondStat);
     $this->jsonEncoderMock->expects($this->once())->method('encode')->willReturn($encodedString);
     $this->assertSame($encodedString, $this->content->getImagesJson());
 }
Exemplo n.º 13
0
 public function testGetJsonSwatchConfigWithoutVisualImageType()
 {
     $this->configurable->setProduct($this->product);
     $this->swatchHelper->expects($this->once())->method('getSwatchAttributesAsArray')->with($this->product)->willReturn([1 => ['options' => [1 => 'testA', 3 => 'testB'], 'use_product_image_for_swatch' => true, 'attribute_code' => 'code']]);
     $this->swatchHelper->expects($this->once())->method('getSwatchesByOptionsId')->with([1, 3])->willReturn([3 => ['type' => Swatch::SWATCH_TYPE_VISUAL_IMAGE, 'value' => 'hello']]);
     $this->swatchHelper->expects($this->once())->method('loadFirstVariationWithSwatchImage')->with($this->product, ['code' => 3])->willReturn($this->product);
     $this->swatchMediaHelper->expects($this->exactly(2))->method('getSwatchAttributeImage')->withConsecutive(['swatch_image', 'hello'], ['swatch_thumb', 'hello'])->willReturn('/path');
     $this->product->expects($this->exactly(4))->method('getData')->withConsecutive(['swatch_image'], ['image'], ['swatch_image'], ['image'])->will($this->onConsecutiveCalls(null, null, null, null));
     $this->imageHelper->expects($this->never())->method('init');
     $this->imageHelper->expects($this->never())->method('resize');
     $this->jsonEncoder->expects($this->once())->method('encode');
     $this->configurable->getJsonSwatchConfig();
 }
 /**
  * Test case when module is enabled and user is logged in
  *
  * @return void
  */
 public function testReportConcurrentAdmins()
 {
     $testAction = 'JSON string';
     /** @var \Magento\Framework\Event\Observer|\PHPUnit_Framework_MockObject_MockObject $eventObserver */
     $eventObserver = $this->getMockBuilder('Magento\\Framework\\Event\\Observer')->disableOriginalConstructor()->getMock();
     $this->config->expects($this->once())->method('isNewRelicEnabled')->willReturn(true);
     $this->backendAuthSession->expects($this->once())->method('isLoggedIn')->willReturn(true);
     $userMock = $this->getMockBuilder('Magento\\User\\Model\\User')->disableOriginalConstructor()->getMock();
     $this->backendAuthSession->expects($this->once())->method('getUser')->willReturn($userMock);
     $this->jsonEncoder->expects($this->once())->method('encode')->willReturn($testAction);
     $this->usersModel->expects($this->once())->method('setData')->with(['type' => 'admin_activity', 'action' => $testAction])->willReturnSelf();
     $this->usersModel->expects($this->once())->method('save');
     $this->model->execute($eventObserver);
 }
 /**
  * Test case when module is enabled and user is logged in
  *
  * @return void
  */
 public function testReportConcurrentUsers()
 {
     $testCustomerId = 1;
     $testAction = 'JSON string';
     /** @var \Magento\Framework\Event\Observer|\PHPUnit_Framework_MockObject_MockObject $eventObserver */
     $eventObserver = $this->getMockBuilder('Magento\\Framework\\Event\\Observer')->disableOriginalConstructor()->getMock();
     $this->config->expects($this->once())->method('isNewRelicEnabled')->willReturn(true);
     $this->customerSession->expects($this->once())->method('isLoggedIn')->willReturn(true);
     $this->customerSession->expects($this->once())->method('getCustomerId')->willReturn($testCustomerId);
     $customerMock = $this->getMockBuilder('Magento\\Customer\\Api\\Data\\CustomerInterface')->getMock();
     $this->customerRepository->expects($this->once())->method('getById')->willReturn($customerMock);
     $storeMock = $this->getMockBuilder('Magento\\Store\\Model\\Store')->disableOriginalConstructor()->getMock();
     $this->storeManager->expects($this->once())->method('getStore')->willReturn($storeMock);
     $websiteMock = $this->getMockBuilder('Magento\\Store\\Model\\Website')->disableOriginalConstructor()->getMock();
     $this->storeManager->expects($this->once())->method('getWebsite')->willReturn($websiteMock);
     $this->jsonEncoder->expects($this->once())->method('encode')->willReturn($testAction);
     $this->usersModel->expects($this->once())->method('setData')->with(['type' => 'user_action', 'action' => $testAction])->willReturnSelf();
     $this->usersModel->expects($this->once())->method('save');
     $this->model->execute($eventObserver);
 }