public function testGetDataExcludesAvailableDataWhenFlagged()
 {
     $this->extension->setCustomData($this->customData)->setReturnAvailableData(false);
     $this->extension->expects($this->at(0))->method('yamlParse')->with('data.yml')->will($this->returnValue($this->currentData));
     $expectedResult = ['version' => '54', 'composer' => '0', 'modules' => ['php' => [], 'pear' => [], 'pecl' => []], 'ini' => ['display_errors' => 'Off'], 'timezone' => 'America/Chihuahua'];
     $this->assertEquals($expectedResult, $this->extension->getData());
 }
 /**
  * @param array $setData
  * @param string $attributeObjectFrontendInput
  * @param array $attrObjectSourceAllOptionsValue
  * @param array $attrSetCollectionOptionsArray
  * @param bool $expectedAttrObjSourceAllOptionsParam
  * @param array $expectedValueSelectOptions
  * @param array $expectedValueOption
  * @dataProvider prepareValueOptionsDataProvider
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 public function testPrepareValueOptions($setData, $attributeObjectFrontendInput, $attrObjectSourceAllOptionsValue, $attrSetCollectionOptionsArray, $expectedAttrObjSourceAllOptionsParam, $expectedValueSelectOptions, $expectedValueOption)
 {
     foreach ($setData as $key => $value) {
         $this->_condition->setData($key, $value);
     }
     $attrObjectSourceMock = $this->getMockBuilder('Magento\\Eav\\Model\\Entity\\Attribute\\Source\\AbstractSource')->setMethods(['getAllOptions'])->disableOriginalConstructor()->getMock();
     $attrObjectSourceMock->expects(null === $expectedAttrObjSourceAllOptionsParam ? $this->never() : $this->once())->method('getAllOptions')->with($expectedAttrObjSourceAllOptionsParam)->willReturn($attrObjectSourceAllOptionsValue);
     $attributeObjectMock = $this->getMockBuilder('Magento\\Catalog\\Model\\ResourceModel\\Eav\\Attribute')->setMethods(['usesSource', 'getFrontendInput', 'getSource', 'getAllOptions'])->disableOriginalConstructor()->getMock();
     $attributeObjectMock->method('usesSource')->willReturn(true);
     $attributeObjectMock->expects(null === $attributeObjectFrontendInput ? $this->never() : $this->once())->method('getFrontendInput')->willReturn($attributeObjectFrontendInput);
     $attributeObjectMock->method('getSource')->willReturn($attrObjectSourceMock);
     $entityTypeMock = $this->getMockBuilder('Magento\\Framework\\Model\\AbstractModel\\Type')->setMethods(['getId'])->disableOriginalConstructor()->getMock();
     $entityTypeMock->method('getId')->willReturn('SomeEntityType');
     $configValueMock = $this->getMock('Magento\\Eav\\Model\\Config', ['getAttribute', 'getEntityType'], [], '', false);
     $configValueMock->method('getAttribute')->willReturn($attributeObjectMock);
     $configValueMock->method('getEntityType')->willReturn($entityTypeMock);
     $configProperty = new ReflectionProperty('Magento\\Rule\\Model\\Condition\\Product\\AbstractProduct', '_config');
     $configProperty->setAccessible(true);
     $configProperty->setValue($this->_condition, $configValueMock);
     $attrSetCollectionValueMock = $this->getMockBuilder('Magento\\Eav\\Model\\ResourceModel\\Entity\\Attribute\\Set\\Collection')->setMethods(['setEntityTypeFilter', 'load', 'toOptionArray'])->disableOriginalConstructor()->getMock();
     $attrSetCollectionValueMock->method('setEntityTypeFilter')->will($this->returnSelf());
     $attrSetCollectionValueMock->method('load')->will($this->returnSelf());
     $attrSetCollectionValueMock->expects(null === $attrSetCollectionOptionsArray ? $this->never() : $this->once())->method('toOptionArray')->willReturn($attrSetCollectionOptionsArray);
     $attrSetCollectionProperty = new ReflectionProperty('Magento\\Rule\\Model\\Condition\\Product\\AbstractProduct', '_attrSetCollection');
     $attrSetCollectionProperty->setAccessible(true);
     $attrSetCollectionProperty->setValue($this->_condition, $attrSetCollectionValueMock);
     $testedMethod = new ReflectionMethod('Magento\\Rule\\Model\\Condition\\Product\\AbstractProduct', '_prepareValueOptions');
     $testedMethod->setAccessible(true);
     $testedMethod->invoke($this->_condition);
     $this->assertEquals($expectedValueSelectOptions, $this->_condition->getData('value_select_options'));
     $this->assertEquals($expectedValueOption, $this->_condition->getData('value_option'));
 }
Example #3
0
 /**
  * @param array $orderData
  * @param array $invoiceData
  * @param array $expectedResults
  * @dataProvider collectDataProvider
  */
 public function testCollect($orderData, $invoiceData, $expectedResults)
 {
     $roundingDelta = [];
     //Set up order mock
     foreach ($orderData['data_fields'] as $key => $value) {
         $this->order->setData($key, $value);
     }
     /** @var \Magento\Sales\Model\Order\Invoice[] $previousInvoices */
     $previousInvoices = [];
     foreach ($orderData['previous_invoices'] as $previousInvoiceData) {
         $previousInvoice = $this->getMockBuilder('\\Magento\\Sales\\Model\\Order\\Invoice')->disableOriginalConstructor()->setMethods(['isCanceled', '__wakeup'])->getMock();
         $previousInvoice->setData('shipping_amount', $previousInvoiceData['shipping_amount']);
         $previousInvoices[] = $previousInvoice;
     }
     $this->order->expects($this->once())->method('getInvoiceCollection')->will($this->returnValue($previousInvoices));
     //Set up invoice mock
     /** @var \Magento\Sales\Model\Order\Invoice\Item[] $invoiceItems */
     $invoiceItems = [];
     foreach ($invoiceData['items'] as $itemKey => $invoiceItemData) {
         $invoiceItems[$itemKey] = $this->getInvoiceItem($invoiceItemData);
     }
     $this->invoice->expects($this->once())->method('getAllItems')->will($this->returnValue($invoiceItems));
     $this->invoice->expects($this->once())->method('isLast')->will($this->returnValue($invoiceData['is_last']));
     foreach ($invoiceData['data_fields'] as $key => $value) {
         $this->invoice->setData($key, $value);
     }
     $this->invoice->expects($this->any())->method('roundPrice')->will($this->returnCallback(function ($price, $type) use(&$roundingDelta) {
         if (!isset($roundingDelta[$type])) {
             $roundingDelta[$type] = 0;
         }
         $roundedPrice = round($price + $roundingDelta[$type], 2);
         $roundingDelta[$type] = $price - $roundedPrice;
         return $roundedPrice;
     }));
     $this->model->collect($this->invoice);
     //verify invoice data
     foreach ($expectedResults['invoice_data'] as $key => $value) {
         $this->assertEquals($value, $this->invoice->getData($key));
     }
     //verify invoice item data
     foreach ($expectedResults['invoice_items'] as $itemKey => $itemData) {
         $invoiceItem = $invoiceItems[$itemKey];
         foreach ($itemData as $key => $value) {
             $this->assertEquals($value, $invoiceItem->getData($key));
         }
     }
 }
 /**
  * @covers \Magento\Framework\View\Design\Theme\Image::removePreviewImage
  */
 public function testRemoveEmptyPreviewImage()
 {
     $this->_themeMock->setData($this->_getThemeSampleData());
     $this->_themeMock->setData('preview_image', null);
     $this->_filesystemMock->expects($this->never())->method('delete');
     $this->_model->removePreviewImage();
     $this->assertNull($this->_themeMock->getData('preview_image'));
 }
Example #5
0
 /**
  * @param array $orderData
  * @param array $invoiceData
  * @param array $expectedResults
  * @dataProvider collectDataProvider
  */
 public function testCollect($orderData, $invoiceData, $expectedResults)
 {
     $roundingDelta = [];
     $this->setupOrder($orderData);
     //Set up weeeData mock
     $this->weeeData->expects($this->once())->method('includeInSubtotal')->will($this->returnValue($invoiceData['include_in_subtotal']));
     //Set up invoice mock
     /** @var \Magento\Sales\Model\Order\Invoice\Item[] $invoiceItems */
     $invoiceItems = [];
     foreach ($invoiceData['items'] as $itemKey => $invoiceItemData) {
         $invoiceItems[$itemKey] = $this->getInvoiceItem($invoiceItemData);
     }
     $this->invoice->expects($this->once())->method('getAllItems')->will($this->returnValue($invoiceItems));
     $this->invoice->expects($this->once())->method('isLast')->will($this->returnValue($invoiceData['is_last']));
     foreach ($invoiceData['data_fields'] as $key => $value) {
         $this->invoice->setData($key, $value);
     }
     $this->invoice->expects($this->any())->method('roundPrice')->will($this->returnCallback(function ($price, $type) use(&$roundingDelta) {
         if (!isset($roundingDelta[$type])) {
             $roundingDelta[$type] = 0;
         }
         $roundedPrice = round($price + $roundingDelta[$type], 2);
         $roundingDelta[$type] = $price - $roundedPrice;
         return $roundedPrice;
     }));
     $this->model->collect($this->invoice);
     //verify invoice data
     foreach ($expectedResults['invoice_data'] as $key => $value) {
         $this->assertEquals($value, $this->invoice->getData($key), 'Invoice data field ' . $key . ' is incorrect');
     }
     //verify invoice item data
     foreach ($expectedResults['invoice_items'] as $itemKey => $itemData) {
         $invoiceItem = $invoiceItems[$itemKey];
         foreach ($itemData as $key => $value) {
             if ($key == 'tax_ratio') {
                 $taxRatio = unserialize($invoiceItem->getData($key));
                 $expectedTaxRatio = unserialize($itemData[$key]);
                 $this->assertEquals($expectedTaxRatio['weee'], $taxRatio['weee'], "Tax ratio is incorrect");
             } else {
                 $this->assertEquals($value, $invoiceItem->getData($key), 'Invoice item field ' . $key . ' is incorrect');
             }
         }
     }
 }
 public function testGetCurrentCategoryIfCurrentCategoryIsNotSet()
 {
     $rootCategoryId = 333;
     $this->currentCategory->getData('current_category', null);
     $this->registry->expects($this->once())->method('registry')->with($this->equalTo('current_category'))->willReturn(null);
     $this->categoryRepository->expects($this->once())->method('get')->with($rootCategoryId)->willReturn($this->category);
     $this->store->expects($this->any())->method('getRootCategoryId')->will($this->returnValue($rootCategoryId));
     $this->assertEquals($this->currentCategory, $this->model->getCurrentCategory());
     $this->assertEquals($this->currentCategory, $this->model->getData('current_category'));
 }
Example #7
0
 /**
  * @param array $orderData
  * @param array $creditmemoData
  * @param array $expectedResults
  * @dataProvider collectDataProvider
  */
 public function testCollect($orderData, $creditmemoData, $expectedResults)
 {
     $roundingDelta = [];
     //Set up order mock
     foreach ($orderData['data_fields'] as $key => $value) {
         $this->order->setData($key, $value);
     }
     //Set up creditmemo mock
     /** @var \Magento\Sales\Model\Order\Creditmemo\Item[] $creditmemoItems */
     $creditmemoItems = [];
     foreach ($creditmemoData['items'] as $itemKey => $creditmemoItemData) {
         $creditmemoItems[$itemKey] = $this->getCreditmemoItem($creditmemoItemData);
     }
     $this->creditmemo->expects($this->once())->method('getAllItems')->will($this->returnValue($creditmemoItems));
     $this->creditmemo->expects($this->any())->method('isLast')->will($this->returnValue($creditmemoData['is_last']));
     foreach ($creditmemoData['data_fields'] as $key => $value) {
         $this->creditmemo->setData($key, $value);
     }
     $this->creditmemo->expects($this->any())->method('roundPrice')->will($this->returnCallback(function ($price, $type) use(&$roundingDelta) {
         if (!isset($roundingDelta[$type])) {
             $roundingDelta[$type] = 0;
         }
         $roundedPrice = round($price + $roundingDelta[$type], 2);
         $roundingDelta[$type] = $price - $roundedPrice;
         return $roundedPrice;
     }));
     $this->model->collect($this->creditmemo);
     //verify invoice data
     foreach ($expectedResults['creditmemo_data'] as $key => $value) {
         $this->assertEquals($value, $this->creditmemo->getData($key));
     }
     //verify invoice item data
     foreach ($expectedResults['creditmemo_items'] as $itemKey => $itemData) {
         $creditmemoItem = $creditmemoItems[$itemKey];
         foreach ($itemData as $key => $value) {
             $this->assertEquals($value, $creditmemoItem->getData($key));
         }
     }
 }
 /**
  * Checks if getData() works with type "data:page"
  *
  * @test
  */
 public function getDataWithTypeDebugPage()
 {
     $uid = rand();
     $GLOBALS['TSFE']->page = array('uid' => $uid);
     $expectedResult = 'array(1item)uid=>' . $uid . '(integer)';
     $result = $this->subject->getData('debug:page');
     $cleanedResult = strip_tags($result);
     $cleanedResult = str_replace("\r", '', $cleanedResult);
     $cleanedResult = str_replace("\n", '', $cleanedResult);
     $cleanedResult = str_replace("\t", '', $cleanedResult);
     $cleanedResult = str_replace(' ', '', $cleanedResult);
     $this->assertEquals($expectedResult, $cleanedResult);
 }
Example #9
0
 /**
  * Verify that correct fields of address has been set
  *
  * @param \PHPUnit_Framework_MockObject_MockObject|\Magento\Quote\Model\Quote\Address $address
  * @param array $addressData
  */
 public function verifyTotals($address, $addressData)
 {
     foreach ($addressData as $key => $value) {
         if ($key != self::KEY_WEEE_TOTALS && $key != self::KEY_WEEE_BASE_TOTALS) {
             // just check the output values
             $this->assertEquals($value, $address->getData($key), 'address ' . $key . ' is incorrect');
         }
     }
 }
Example #10
0
 /**
  * @param \Magento\Catalog\Model\Product|\PHPUnit_Framework_MockObject_MockObject $product
  * @param array $modelData
  * @return \Magento\Downloadable\Model\Sample|\PHPUnit_Framework_MockObject_MockObject
  */
 private function createSampleModel($product, array $modelData)
 {
     $sample = $this->getMockBuilder('\\Magento\\Downloadable\\Model\\Sample')->disableOriginalConstructor()->setMethods(['setData', 'setSampleType', 'setProductId', 'setStoreId', 'setProductWebsiteIds', 'setNumberOfDownloads', 'setSampleUrl', 'setLinkFile', 'setSampleFile', 'save'])->getMock();
     $sample->expects($this->once())->method('setData')->with($modelData)->will($this->returnSelf());
     $sample->expects($this->once())->method('setSampleType')->with($modelData['type'])->will($this->returnSelf());
     $sample->expects($this->once())->method('setProductId')->with($product->getData('id'))->willReturnSelf();
     $sample->expects($this->once())->method('setStoreId')->with($product->getStoreId())->will($this->returnSelf());
     return $sample;
 }
Example #11
0
 /**
  * Verify that correct fields of address has been set
  *
  * @param \PHPUnit_Framework_MockObject_MockObject|\Magento\Quote\Model\Quote\Address $address
  * @param $addressData
  */
 public function verifyAddress($address, $addressData)
 {
     foreach ($addressData as $key => $value) {
         $this->assertEquals($value, $address->getData($key), 'address ' . $key . ' is incorrect');
     }
 }
Example #12
0
 /**
  * @param \Magento\Catalog\Model\Product|\PHPUnit_Framework_MockObject_MockObject $product
  * @param array $modelData
  * @param bool $isUnlimited
  * @return \Magento\Downloadable\Model\Link|\PHPUnit_Framework_MockObject_MockObject
  */
 private function createLinkkModel($product, array $modelData, $isUnlimited)
 {
     $link = $this->getMockBuilder('\\Magento\\Downloadable\\Model\\Link')->disableOriginalConstructor()->setMethods(['setData', 'setLinkType', 'setProductId', 'setStoreId', 'setWebsiteId', 'setProductWebsiteIds', 'setPrice', 'setNumberOfDownloads', 'setSampleUrl', 'setSampleType', 'setLinkFile', 'setSampleFile', 'save', 'getIsUnlimited'])->getMock();
     $link->expects($this->once())->method('setData')->with($modelData)->will($this->returnSelf());
     $link->expects($this->once())->method('setLinkType')->with($modelData['type'])->will($this->returnSelf());
     $link->expects($this->once())->method('setProductId')->with($product->getData('id'))->will($this->returnSelf());
     $link->expects($this->once())->method('setStoreId')->with($product->getStoreId())->will($this->returnSelf());
     $link->expects($this->once())->method('setWebsiteId')->with($product->getStore()->getWebsiteId())->will($this->returnSelf());
     $link->expects($this->once())->method('setPrice')->with(0);
     $link->expects($this->any())->method('setNumberOfDownloads')->with(0);
     $link->expects($this->once())->method('getIsUnlimited')->will($this->returnValue($isUnlimited));
     return $link;
 }
Example #13
0
 public function testHoldsData()
 {
     $testData = 'whatever';
     $this->assertSame($this->abstractCommand, $this->abstractCommand->setData($testData));
     $this->assertEquals($testData, $this->abstractCommand->getData());
 }