public function testJsonEncode()
 {
     $expectedValue = 'string';
     $this->jsonHelperMock->expects($this->once())->method('jsonEncode')->with($this->equalTo($expectedValue))->will($this->returnValue($expectedValue));
     $result = $this->object->jsonEncode($expectedValue);
     $this->assertEquals($expectedValue, $result);
 }
Beispiel #2
0
 public function testExecuteWithException()
 {
     $this->requestMock->expects($this->once())->method('getParam')->with('item_id', null)->willReturn('1');
     $exception = new \Exception('Error message!');
     $this->sidebarMock->expects($this->once())->method('checkQuoteItem')->with(1)->willThrowException($exception);
     $this->loggerMock->expects($this->once())->method('critical')->with($exception)->willReturn(null);
     $this->sidebarMock->expects($this->once())->method('getResponseData')->with('Error message!')->willReturn(['success' => false, 'error_message' => 'Error message!']);
     $this->jsonHelperMock->expects($this->once())->method('jsonEncode')->with(['success' => false, 'error_message' => 'Error message!'])->willReturn('json encoded');
     $this->responseMock->expects($this->once())->method('representJson')->with('json encoded')->willReturn('json represented');
     $this->assertEquals('json represented', $this->removeItem->executeInternal());
 }
Beispiel #3
0
 public function testGetRegionJson()
 {
     $countries = [new \Magento\Framework\DataObject(['country_id' => 'Country1']), new \Magento\Framework\DataObject(['country_id' => 'Country2'])];
     $countryIterator = new \ArrayIterator($countries);
     $this->_countryCollection->expects($this->atLeastOnce())->method('getIterator')->will($this->returnValue($countryIterator));
     $regions = [new \Magento\Framework\DataObject(['country_id' => 'Country1', 'region_id' => 'r1', 'code' => 'r1-code', 'name' => 'r1-name']), new \Magento\Framework\DataObject(['country_id' => 'Country1', 'region_id' => 'r2', 'code' => 'r2-code', 'name' => 'r2-name']), new \Magento\Framework\DataObject(['country_id' => 'Country2', 'region_id' => 'r3', 'code' => 'r3-code', 'name' => 'r3-name'])];
     $regionIterator = new \ArrayIterator($regions);
     $this->_regionCollection->expects($this->once())->method('addCountryFilter')->with(['Country1', 'Country2'])->will($this->returnSelf());
     $this->_regionCollection->expects($this->once())->method('load');
     $this->_regionCollection->expects($this->once())->method('getIterator')->will($this->returnValue($regionIterator));
     $expectedDataToEncode = ['config' => ['show_all_regions' => false, 'regions_required' => []], 'Country1' => ['r1' => ['code' => 'r1-code', 'name' => 'r1-name'], 'r2' => ['code' => 'r2-code', 'name' => 'r2-name']], 'Country2' => ['r3' => ['code' => 'r3-code', 'name' => 'r3-name']]];
     $this->jsonHelperMock->expects($this->once())->method('jsonEncode')->with(new \PHPUnit_Framework_Constraint_IsIdentical($expectedDataToEncode))->will($this->returnValue('encoded_json'));
     // Test
     $result = $this->_object->getRegionJson();
     $this->assertEquals('encoded_json', $result);
 }
 public function testAfterRenderResultWithWrongArray()
 {
     $messageType = 'message1type';
     $messageText = 'message1text';
     $messages = [['type' => $messageType, 'text' => $messageText]];
     /** @var Redirect|\PHPUnit_Framework_MockObject_MockObject $resultMock */
     $resultMock = $this->getMockBuilder(Redirect::class)->disableOriginalConstructor()->getMock();
     /** @var PublicCookieMetadata|\PHPUnit_Framework_MockObject_MockObject $cookieMetadataMock */
     $cookieMetadataMock = $this->getMockBuilder(PublicCookieMetadata::class)->disableOriginalConstructor()->getMock();
     $this->cookieMetadataFactoryMock->expects($this->once())->method('createPublicCookieMetadata')->willReturn($cookieMetadataMock);
     $this->cookieManagerMock->expects($this->once())->method('setPublicCookie')->with(MessagePlugin::MESSAGES_COOKIES_NAME, \Zend_Json::encode($messages), $cookieMetadataMock);
     $this->cookieManagerMock->expects($this->once())->method('getCookie')->with(MessagePlugin::MESSAGES_COOKIES_NAME, \Zend_Json::encode([]))->willReturn(\Zend_Json::encode('string'));
     $this->dataMock->expects($this->any())->method('jsonDecode')->willReturnCallback(function ($data) {
         return \Zend_Json::decode($data);
     });
     $this->dataMock->expects($this->any())->method('jsonEncode')->willReturnCallback(function ($data) {
         return \Zend_Json::encode($data);
     });
     /** @var MessageInterface|\PHPUnit_Framework_MockObject_MockObject $messageMock */
     $messageMock = $this->getMockBuilder(MessageInterface::class)->getMock();
     $messageMock->expects($this->once())->method('getType')->willReturn($messageType);
     $this->interpretationStrategyMock->expects($this->once())->method('interpret')->with($messageMock)->willReturn($messageText);
     /** @var Collection|\PHPUnit_Framework_MockObject_MockObject $collectionMock */
     $collectionMock = $this->getMockBuilder(Collection::class)->disableOriginalConstructor()->getMock();
     $collectionMock->expects($this->once())->method('getItems')->willReturn([$messageMock]);
     $this->managerMock->expects($this->once())->method('getMessages')->with(true, null)->willReturn($collectionMock);
     $this->assertEquals($resultMock, $this->model->afterRenderResult($resultMock, $resultMock));
 }
Beispiel #5
0
 /**
  * @param $paymentMethod
  * @param $controller
  * @param $quoteId
  * @param $result
  * @dataProvider textExecuteFailedPlaceOrderDataProvider
  */
 public function testExecuteFailedPlaceOrder($paymentMethod, $controller, $quoteId, $result)
 {
     $this->requestMock->expects($this->at(0))->method('getParam')->with('payment')->will($this->returnValue($paymentMethod));
     $this->requestMock->expects($this->at(1))->method('getParam')->with('controller')->will($this->returnValue($controller));
     $this->quoteMock->expects($this->any())->method('getId')->will($this->returnValue($quoteId));
     $this->cartManagementMock->expects($this->once())->method('placeOrder')->willThrowException(new \Exception());
     $this->jsonHelperMock->expects($this->any())->method('jsonEncode')->with($result);
     $this->placeOrderController->execute();
 }
 /**
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function testGenerateSimpleProducts()
 {
     $productsData = [6 => ['image' => 'image.jpg', 'name' => 'config-red', 'configurable_attribute' => '{"new_attr":"6"}', 'sku' => 'config-red', 'quantity_and_stock_status' => ['qty' => ''], 'weight' => '333']];
     $stockData = ['manage_stock' => '0', 'use_config_enable_qty_increments' => '1', 'use_config_qty_increments' => '1', 'use_config_manage_stock' => 0, 'is_decimal_divided' => 0];
     $parentProductMock = $this->getMockBuilder('\\Magento\\Catalog\\Model\\Product')->setMethods(['__wakeup', 'hasData', 'getData', 'getNewVariationsAttributeSetId', 'getStockData', 'getQuantityAndStockStatus', 'getWebsiteIds'])->disableOriginalConstructor()->getMock();
     $newSimpleProductMock = $this->getMockBuilder('\\Magento\\Catalog\\Model\\Product')->setMethods(['__wakeup', 'save', 'getId', 'setStoreId', 'setTypeId', 'setAttributeSetId', 'getTypeInstance', 'getStoreId', 'addData', 'setWebsiteIds', 'setStatus', 'setVisibility'])->disableOriginalConstructor()->getMock();
     $attributeMock = $this->getMockBuilder('\\Magento\\Eav\\Model\\Entity\\Attribute')->setMethods(['isInSet', 'setAttributeSetId', 'setAttributeGroupId', 'save'])->disableOriginalConstructor()->getMock();
     $attributeSetMock = $this->getMockBuilder('Magento\\Eav\\Model\\Entity\\Attribute\\Set')->setMethods(['load', 'addSetInfo', 'getDefaultGroupId'])->disableOriginalConstructor()->getMock();
     $eavEntityMock = $this->getMockBuilder('\\Magento\\Eav\\Model\\Entity')->setMethods(['setType', 'getTypeId'])->disableOriginalConstructor()->getMock();
     $productTypeMock = $this->getMockBuilder('Magento\\Catalog\\Model\\Product\\Type')->setMethods(['getEditableAttributes'])->disableOriginalConstructor()->getMock();
     $editableAttributeMock = $this->getMockBuilder('Magento\\Eav\\Model\\Entity\\Attribute')->setMethods(['getIsUnique', 'getAttributeCode', 'getFrontend', 'getIsVisible'])->disableOriginalConstructor()->getMock();
     $frontendAttributeMock = $this->getMockBuilder('Magento\\Eav\\Model\\Entity\\Attribute\\Frontend')->setMethods(['getInputType'])->disableOriginalConstructor()->getMock();
     $parentProductMock->expects($this->once())->method('hasData')->with('_cache_instance_used_product_attributes')->willReturn(true);
     $parentProductMock->expects($this->once())->method('getData')->with('_cache_instance_used_product_attributes')->willReturn([$attributeMock]);
     $parentProductMock->expects($this->any())->method('getNewVariationsAttributeSetId')->willReturn('new_attr_set_id');
     $this->_attributeSetFactory->expects($this->once())->method('create')->willReturn($attributeSetMock);
     $attributeSetMock->expects($this->once())->method('load')->with('new_attr_set_id')->willReturnSelf();
     $this->_entityFactoryMock->expects($this->once())->method('create')->willReturn($eavEntityMock);
     $eavEntityMock->expects($this->once())->method('setType')->with('catalog_product')->willReturnSelf();
     $eavEntityMock->expects($this->once())->method('getTypeId')->willReturn('type_id');
     $attributeSetMock->expects($this->once())->method('addSetInfo')->with('type_id', [$attributeMock]);
     $attributeMock->expects($this->once())->method('isInSet')->with('new_attr_set_id')->willReturn(false);
     $attributeMock->expects($this->once())->method('setAttributeSetId')->with('new_attr_set_id')->willReturnSelf();
     $attributeSetMock->expects($this->once())->method('getDefaultGroupId')->with('new_attr_set_id')->willReturn('default_group_id');
     $attributeMock->expects($this->once())->method('setAttributeGroupId')->with('default_group_id')->willReturnSelf();
     $attributeMock->expects($this->once())->method('save')->willReturnSelf();
     $this->_productFactoryMock->expects($this->once())->method('create')->willReturn($newSimpleProductMock);
     $this->jsonHelperMock->expects($this->once())->method('jsonDecode')->with('{"new_attr":"6"}')->willReturn(['new_attr' => 6]);
     $newSimpleProductMock->expects($this->once())->method('setStoreId')->with(0)->willReturnSelf();
     $newSimpleProductMock->expects($this->once())->method('setTypeId')->with('simple')->willReturnSelf();
     $newSimpleProductMock->expects($this->once())->method('setAttributeSetId')->with('new_attr_set_id')->willReturnSelf();
     $newSimpleProductMock->expects($this->once())->method('getTypeInstance')->willReturn($productTypeMock);
     $productTypeMock->expects($this->once())->method('getEditableAttributes')->with($newSimpleProductMock)->willReturn([$editableAttributeMock]);
     $editableAttributeMock->expects($this->once())->method('getIsUnique')->willReturn(false);
     $editableAttributeMock->expects($this->once())->method('getAttributeCode')->willReturn('some_code');
     $editableAttributeMock->expects($this->any())->method('getFrontend')->willReturn($frontendAttributeMock);
     $frontendAttributeMock->expects($this->any())->method('getInputType')->willReturn('input_type');
     $editableAttributeMock->expects($this->any())->method('getIsVisible')->willReturn(false);
     $parentProductMock->expects($this->once())->method('getStockData')->willReturn($stockData);
     $parentProductMock->expects($this->once())->method('getQuantityAndStockStatus')->willReturn(['is_in_stock' => 1]);
     $newSimpleProductMock->expects($this->once())->method('getStoreId')->willReturn('store_id');
     $this->_stockConfiguration->expects($this->once())->method('getManageStock')->with('store_id')->willReturn(1);
     $newSimpleProductMock->expects($this->once())->method('addData')->willReturnSelf();
     $parentProductMock->expects($this->once())->method('getWebsiteIds')->willReturn('website_id');
     $newSimpleProductMock->expects($this->once())->method('setWebsiteIds')->with('website_id')->willReturnSelf();
     $newSimpleProductMock->expects($this->once())->method('setStatus')->with(1)->willReturnSelf();
     $newSimpleProductMock->expects($this->once())->method('setVisibility')->with(1)->willReturnSelf();
     $newSimpleProductMock->expects($this->once())->method('save')->willReturnSelf();
     $newSimpleProductMock->expects($this->once())->method('getId')->willReturn('product_id');
     $this->assertEquals(['product_id'], $this->_model->generateSimpleProducts($parentProductMock, $productsData));
 }
 public function testExecute()
 {
     $themeId = 23;
     $theme = $this->getMockForAbstractClass('Magento\\Framework\\View\\Design\\ThemeInterface', [], '', false);
     $jsFile = $this->getMockForAbstractClass('Magento\\Framework\\View\\Design\\Theme\\FileInterface', [], '', false, true, true, ['setTheme', 'setFileName', 'setData', 'save']);
     $this->_request->expects($this->at(0))->method('getParam')->with('id')->willReturn($themeId);
     $this->_objectManagerMock->expects($this->at(0))->method('get')->with('Magento\\Theme\\Model\\Uploader\\Service')->WillReturn($this->serviceModel);
     $this->_objectManagerMock->expects($this->at(1))->method('get')->with('Magento\\Framework\\View\\Design\\Theme\\FlyweightFactory')->WillReturn($this->themeFactory);
     $this->_objectManagerMock->expects($this->at(2))->method('get')->with('Magento\\Framework\\View\\Design\\Theme\\Customization\\File\\Js')->WillReturn($this->customizationJs);
     $this->_objectManagerMock->expects($this->at(4))->method('get')->with('Magento\\Framework\\Json\\Helper\\Data')->WillReturn($this->jsonHelper);
     $this->themeFactory->expects($this->once())->method('create')->willReturn($theme);
     $this->serviceModel->expects($this->once())->method('uploadJsFile')->with('js_files_uploader')->willReturn(['filename' => 'filename', 'content' => 'content']);
     $this->customizationJs->expects($this->once())->method('create')->willReturn($jsFile);
     $jsFile->expects($this->once())->method('setTheme')->with($theme);
     $jsFile->expects($this->once())->method('setFileName')->with('filename');
     $jsFile->expects($this->once())->method('setData')->with('content', 'content');
     $jsFile->expects($this->once())->method('save');
     $this->_objectManagerMock->expects($this->once())->method('create')->with('Magento\\Framework\\View\\Design\\Theme\\CustomizationInterface', ['theme' => $theme])->willReturn($this->themeCustomization);
     $this->themeCustomization->expects($this->once())->method('getFilesByType')->with(\Magento\Framework\View\Design\Theme\Customization\File\Js::TYPE)->willReturn([$jsFile]);
     $this->themeCustomization->expects($this->once())->method('generateFileInfo')->with([$jsFile])->willReturn(['fileOne' => ['name' => 'name']]);
     $this->jsonHelper->expects($this->once())->method('jsonEncode')->with(['error' => false, 'files' => ['fileOne' => ['name' => 'name']]])->willReturn('{"error":false,"files":{"fileOne":{"name":"name"}}}');
     $this->response->expects($this->once())->method('representJson')->with('{"error":false,"files":{"fileOne":{"name":"name"}}}');
     $this->_model->execute();
 }
Beispiel #8
0
 public function testLoginFailure()
 {
     $jsonRequest = '{"username":"******", "password":"******"}';
     $loginFailureResponse = '{"message":"Invalid login or password."}';
     $this->request->expects($this->any())->method('getContent')->willReturn($jsonRequest);
     $this->request->expects($this->any())->method('getMethod')->willReturn('POST');
     $this->request->expects($this->any())->method('isXmlHttpRequest')->willReturn(true);
     $this->resultJsonFactory->expects($this->once())->method('create')->willReturn($this->resultJson);
     $this->jsonHelperMock->expects($this->any())->method('jsonDecode')->with($jsonRequest)->willReturn(['username' => '*****@*****.**', 'password' => 'invalid']);
     $customerMock = $this->getMockForAbstractClass('Magento\\Customer\\Api\\Data\\CustomerInterface');
     $this->customerAccountManagementMock->expects($this->any())->method('authenticate')->with('*****@*****.**', 'invalid')->willThrowException(new InvalidEmailOrPasswordException(__('Invalid login or password.')));
     $this->customerSession->expects($this->never())->method('setCustomerDataAsLoggedIn')->with($customerMock);
     $this->customerSession->expects($this->never())->method('regenerateId');
     $result = ['errors' => true, 'message' => __('Invalid login or password.')];
     $this->resultJson->expects($this->once())->method('setData')->with($result)->willReturn($loginFailureResponse);
     $this->assertEquals($loginFailureResponse, $this->object->execute());
 }
 public function testSaveWithFile()
 {
     $sampleId = 1;
     $productId = 1;
     $productSku = 'simple';
     $sampleFile = '/s/a/sample.jpg';
     $sampleData = ['id' => $sampleId, 'title' => 'Updated Title', 'sort_order' => 1, 'sample_type' => 'file', 'file' => $sampleFile];
     $this->repositoryMock->expects($this->once())->method('get')->with($productSku, true)->willReturn($this->productMock);
     $this->productMock->expects($this->once())->method('getTypeId')->willReturn('downloadable');
     $this->productMock->expects($this->once())->method('getData')->with('id')->willReturn($productId);
     $sampleMock = $this->getSampleMock($sampleData);
     $this->contentValidatorMock->expects($this->any())->method('isValid')->with($sampleMock)->willReturn(true);
     $sampleMock->expects($this->once())->method('setProductId')->with($productId);
     $sampleMock->expects($this->exactly(2))->method('getFile')->willReturn($sampleFile);
     $this->jsonEncoderMock->expects($this->once())->method('jsonDecode')->willReturn($sampleFile);
     $this->contentUploaderMock->expects($this->once())->method('moveFileFromTmp')->with($sampleMock->getBaseTmpPath(), $sampleMock->getBasePath(), $sampleFile)->willReturn($sampleFile);
     $sampleMock->expects($this->once())->method('setSampleFile')->with($sampleFile);
     $sampleMock->expects($this->once())->method('setSampleUrl')->with(null);
     $this->sampleResourceMock->expects($this->once())->method('save')->with($sampleMock)->willReturn($sampleId);
     $this->assertEquals($sampleId, $this->service->save($productSku, $sampleMock));
 }