/**
  * @covers \Magento\SalesRule\Model\Rule\Action\Discount\CartFixed::calculate
  */
 public function testCalculate()
 {
     $this->rule->setData(['id' => 1, 'discount_amount' => 10.0]);
     $this->address->expects($this->any())->method('getCartFixedRules')->will($this->returnValue([]));
     $store = $this->getMock('Magento\\Store\\Model\\Store', [], [], '', false);
     $this->priceCurrency->expects($this->atLeastOnce())->method('convert')->will($this->returnArgument(0));
     $this->priceCurrency->expects($this->atLeastOnce())->method('round')->will($this->returnArgument(0));
     $this->quote->expects($this->any())->method('getStore')->will($this->returnValue($store));
     /** validators data */
     $this->validator->expects($this->once())->method('getItemPrice')->with($this->item)->will($this->returnValue(100));
     $this->validator->expects($this->once())->method('getItemBasePrice')->with($this->item)->will($this->returnValue(100));
     $this->validator->expects($this->once())->method('getItemOriginalPrice')->with($this->item)->will($this->returnValue(100));
     $this->validator->expects($this->once())->method('getItemBaseOriginalPrice')->with($this->item)->will($this->returnValue(100));
     $this->address->expects($this->once())->method('setCartFixedRules')->with([1 => 0.0]);
     $this->model->calculate($this->rule, $this->item, 1);
     $this->assertEquals($this->data->getAmount(), 10);
     $this->assertEquals($this->data->getBaseAmount(), 10);
     $this->assertEquals($this->data->getOriginalAmount(), 10);
     $this->assertEquals($this->data->getBaseOriginalAmount(), 100);
 }
 /**
  * @param array $addressData
  * @param bool $useBaseCurrency
  * @param string $shippingTaxClass
  * @param bool shippingPriceInclTax
  * @param array $expectedValue
  * @dataProvider getShippingDataObjectDataProvider
  */
 public function testGetShippingDataObject(array $addressData, $useBaseCurrency, $shippingTaxClass, $shippingPriceInclTax)
 {
     $baseShippingAmount = $addressData['base_shipping_amount'];
     $shippingAmount = $addressData['shipping_amount'];
     $itemMock = $this->getMock('Magento\\Tax\\Api\\Data\\QuoteDetailsItemInterface');
     $this->taxConfig->expects($this->any())->method('getShippingTaxClass')->with($this->store)->will($this->returnValue($shippingTaxClass));
     $this->taxConfig->expects($this->any())->method('shippingPriceIncludesTax')->with($this->store)->will($this->returnValue($shippingPriceInclTax));
     $this->address->expects($this->atLeastOnce())->method('getShippingDiscountAmount')->willReturn($shippingAmount);
     if ($shippingAmount) {
         if ($useBaseCurrency && $shippingAmount != 0) {
             $this->address->expects($this->once())->method('getBaseShippingDiscountAmount')->willReturn($baseShippingAmount);
             $this->quoteDetailsItemBuilderMock->expects($this->once())->method('setDiscountAmount')->with($baseShippingAmount);
         } else {
             $this->address->expects($this->never())->method('getBaseShippingDiscountAmount');
             $this->quoteDetailsItemBuilderMock->expects($this->once())->method('setDiscountAmount')->with($shippingAmount);
         }
     }
     foreach ($addressData as $key => $value) {
         $this->address->setData($key, $value);
     }
     $this->taxClassKeyBuilderMock->expects($this->any())->method('setType')->willReturnSelf();
     $this->taxClassKeyBuilderMock->expects($this->any())->method('setValue')->with($shippingTaxClass)->willReturnSelf();
     $this->quoteDetailsItemBuilderMock->expects($this->once())->method('create')->willReturn($itemMock);
     $this->assertEquals($itemMock, $this->commonTaxCollector->getShippingDataObject($this->address, $useBaseCurrency));
 }
 /**
  * @param $existingValue
  * @param $operator
  * @param $valueForValidate
  * @param $expectedResult
  * @param $inputType
  *
  * @dataProvider validateAttributeArrayInputTypeDataProvider
  */
 public function testValidateArrayOperatorType($existingValue, $operator, $valueForValidate, $expectedResult, $inputType)
 {
     $this->_condition->setOperator($operator);
     $this->_condition->setData('value_parsed', $existingValue);
     $this->_condition->getDefaultOperatorInputByType();
     $this->_condition->expects($this->any())->method('getInputType')->will($this->returnValue($inputType));
     $this->assertEquals($expectedResult, $this->_condition->validateAttribute($valueForValidate), "Failed asserting that " . var_export($existingValue, true) . $operator . var_export($valueForValidate, true));
 }
Example #4
0
 /**
  * @dataProvider getInfoDataProvider
  */
 public function testGetInfoData($field, $value, $expected)
 {
     $methodInstance = $this->getMockBuilder('\\Magento\\Payment\\Model\\Method\\AbstractMethod')->setMethods(['getData'])->disableOriginalConstructor()->getMock();
     $methodInstance->expects($this->any())->method('getData')->with($field)->will($this->returnValue($value));
     $method = $this->getMockBuilder('Magento\\Payment\\Model\\MethodInterface')->getMockForAbstractClass();
     $method->expects($this->any())->method('getInfoInstance')->will($this->returnValue($methodInstance));
     $this->_object->setData('method', $method);
     $this->assertEquals($expected, $this->_object->getInfoData($field));
 }
Example #5
0
 public function testCheckQuoteItemQty()
 {
     $this->_model->setData('manage_stock', 1);
     $this->_model->setData('is_in_stock', 1);
     $this->_model->setProductName('qwerty');
     $this->_model->setData('backorders', 3);
     $result = $this->_model->checkQuoteItemQty(1, 1);
     $this->assertEquals('We don\'t have as many "qwerty" as you requested.', $result->getMessage());
 }
Example #6
0
 public function testJsonEncode_EncodesData()
 {
     $testData = 'something something 123';
     $testType = 'testType';
     $expected = json_encode(['type' => $testType, 'data' => $testData]);
     $this->abstractCommand->expects($this->once())->method('getType')->willReturn('testType');
     $this->abstractCommand->setData($testData);
     $this->assertJsonStringEqualsJsonString($expected, json_encode($this->abstractCommand));
 }
Example #7
0
 /**
  * @covers \Magento\Bundle\Pricing\Price\TierPrice::isFirstPriceBetter
  * @dataProvider providerForGetterTierPriceList
  */
 public function testGetterTierPriceList($tierPrices, $basePrice, $expectedResult)
 {
     $this->product->setData(TierPrice::PRICE_CODE, $tierPrices);
     $price = $this->getMock('Magento\\Framework\\Pricing\\Price\\PriceInterface');
     $price->expects($this->any())->method('getValue')->will($this->returnValue($basePrice));
     $this->priceInfo->expects($this->any())->method('getPrice')->will($this->returnValue($price));
     $this->calculator->expects($this->atLeastOnce())->method('getAmount')->will($this->returnArgument(0));
     $this->assertEquals($expectedResult, $this->model->getTierPriceList());
     $this->assertEquals(count($expectedResult), $this->model->getTierPriceCount());
 }
Example #8
0
 /**
  * @param array $addressData
  * @param bool $useBaseCurrency
  * @param string $shippingTaxClass
  * @param bool shippingPriceInclTax
  * @param array $expectedValue
  * @dataProvider getShippingDataObjectDataProvider
  */
 public function testGetShippingDataObject(array $addressData, $useBaseCurrency, $shippingTaxClass, $shippingPriceInclTax, array $expectedValue)
 {
     $this->taxConfig->expects($this->any())->method('getShippingTaxClass')->with($this->store)->will($this->returnValue($shippingTaxClass));
     $this->taxConfig->expects($this->any())->method('shippingPriceIncludesTax')->with($this->store)->will($this->returnValue($shippingPriceInclTax));
     foreach ($addressData as $key => $value) {
         $this->address->setData($key, $value);
     }
     $shippingDataObject = $this->commonTaxCollector->getShippingDataObject($this->address, $useBaseCurrency);
     $this->assertEquals($expectedValue, $shippingDataObject->__toArray());
     //call it again, make sure we get the same output
     $shippingDataObject = $this->commonTaxCollector->getShippingDataObject($this->address, $useBaseCurrency);
     $this->assertEquals($expectedValue, $shippingDataObject->__toArray());
 }
Example #9
0
 /**
  * @covers \Magento\Bundle\Pricing\Price\TierPrice::isFirstPriceBetter
  * @dataProvider providerForGetterTierPriceList
  */
 public function testGetterTierPriceList($tierPrices, $basePrice, $expectedResult)
 {
     $this->product->setData(TierPrice::PRICE_CODE, $tierPrices);
     $price = $this->getMock('Magento\\Framework\\Pricing\\Price\\PriceInterface');
     $price->expects($this->any())->method('getValue')->will($this->returnValue($basePrice));
     $this->priceInfo->expects($this->any())->method('getPrice')->will($this->returnValue($price));
     $this->calculator->expects($this->atLeastOnce())->method('getAmount')->will($this->returnArgument(0));
     $this->priceCurrencyMock->expects($this->never())->method('convertAndRound');
     $group = $this->getMock('\\Magento\\Customer\\Model\\Data\\Group', [], [], '', false);
     $group->expects($this->any())->method('getId')->willReturn(\Magento\Customer\Model\GroupManagement::CUST_GROUP_ALL);
     $this->groupManagement->expects($this->any())->method('getAllCustomersGroup')->will($this->returnValue($group));
     $this->assertEquals($expectedResult, $this->model->getTierPriceList());
     $this->assertEquals(count($expectedResult), $this->model->getTierPriceCount());
 }
Example #10
0
 /**
  * @dataProvider validateDataProvider
  * @param bool $value
  */
 public function testValidate($value)
 {
     $attributeCode = 'attr_code';
     $attribute = $this->getMock('Magento\\Eav\\Model\\Entity\\Attribute', ['getAttributeCode', 'getIsRequired', 'isValueEmpty', 'getIsUnique', 'getEntityType', '__wakeup'], [], '', false);
     $attributeEntity = $this->getMock('\\Magento\\Framework\\Model\\ResourceModel\\AbstractResourceAbstractEntity', ['checkAttributeUniqueValue']);
     $attribute->expects($this->any())->method('getAttributeCode')->will($this->returnValue($attributeCode));
     $attribute->expects($this->any())->method('getIsRequired')->will($this->returnValue(true));
     $attribute->expects($this->any())->method('isValueEmpty')->will($this->returnValue($value));
     $attribute->expects($this->any())->method('getIsUnique')->will($this->returnValue(true));
     $attribute->expects($this->any())->method('getEntityType')->will($this->returnValue($attributeEntity));
     $attributeEntity->expects($this->any())->method('checkAttributeUniqueValue')->will($this->returnValue(true));
     $this->attributeRepository->expects($this->once())->method('get')->with('media_gallery')->willReturn($attribute);
     $this->dataObject->setData(['attr_code' => 'attribute data']);
     $this->assertEquals(!$value, $this->model->validate($this->dataObject));
 }
Example #11
0
 /**
  * @dataProvider getIsSecureModeDataProvider
  * @param bool $isSecureMode
  * @param bool $methodInstance
  * @param bool $store
  * @param string $storeCode
  * @param bool $expectedResult
  */
 public function testGetIsSecureMode($isSecureMode, $methodInstance, $store, $storeCode, $expectedResult)
 {
     if (isset($store)) {
         $methodInstance = $this->_getMethodInstanceMock($store);
     }
     if (isset($storeCode)) {
         $storeMock = $this->_getStoreMock($storeCode);
         $this->_storeManager->expects($this->any())->method('getStore')->will($this->returnValue($storeMock));
     }
     $paymentInfo = $this->getMockBuilder('\\Magento\\Payment\\Model\\Info')->disableOriginalConstructor()->getMock();
     $paymentInfo->expects($this->any())->method('getMethodInstance')->will($this->returnValue($methodInstance));
     $this->_object->setData('info', $paymentInfo);
     $this->_object->setData('is_secure_mode', $isSecureMode);
     $result = $this->_object->getIsSecureMode();
     $this->assertEquals($result, $expectedResult);
 }
 /**
  * @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 #13
0
 /**
  * @param array $badStoreData
  *
  * @dataProvider saveValidationDataProvider
  * @magentoAppIsolation enabled
  * @magentoAppArea adminhtml
  * @magentoDbIsolation enabled
  * @expectedException \Magento\Framework\Exception\LocalizedException
  */
 public function testSaveValidation($badStoreData)
 {
     $normalStoreData = ['code' => 'test', 'website_id' => 1, 'group_id' => 1, 'name' => 'test name', 'sort_order' => 0, 'is_active' => 1];
     $data = array_merge($normalStoreData, $badStoreData);
     $this->model->setData($data);
     $this->model->save();
 }
Example #14
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));
         }
     }
 }
Example #15
0
 /**
  * @magentoAppIsolation enabled
  */
 public function testCRUD()
 {
     $this->_model->setData(array('code' => 'test', 'website_id' => 1, 'group_id' => 1, 'name' => 'test name', 'sort_order' => 0, 'is_active' => 1));
     /* emulate admin store */
     Mage::app()->getStore()->setId(Mage_Core_Model_App::ADMIN_STORE_ID);
     $crud = new Magento_Test_Entity($this->_model, array('name' => 'new name'));
     $crud->testCrud();
 }
Example #16
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');
             }
         }
     }
 }
Example #17
0
 /**
  * @param array $initialData
  * @param string $expectedValue
  * @dataProvider serializeDataProvider
  * @covers \Magento\Framework\Data\Form\Element\AbstractElement::serialize()
  */
 public function testSerialize(array $initialData, $expectedValue)
 {
     $attributes = [];
     if (isset($initialData['attributes'])) {
         $attributes = $initialData['attributes'];
         unset($initialData['attributes']);
     }
     $this->_model->setData($initialData);
     $this->assertEquals($expectedValue, $this->_model->serialize($attributes));
 }
Example #18
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));
         }
     }
 }
 public function testApplyRulesThatAppliedRuleIdsAreCollected()
 {
     $positivePrice = 1;
     $ruleId1 = 123;
     $ruleId2 = 234;
     $expectedRuleIds = [$ruleId1 => $ruleId1, $ruleId2 => $ruleId2];
     $this->model->init($this->model->getWebsiteId(), $this->model->getCustomerGroupId(), $this->model->getCouponCode());
     $this->item->setDiscountCalculationPrice($positivePrice);
     $this->item->setData('calculation_price', $positivePrice);
     $this->model->setSkipActionsValidation(true);
     $this->rulesApplier->expects($this->once())->method('applyRules')->with($this->equalTo($this->item), $this->equalTo($this->ruleCollection), $this->anything(), $this->anything())->will($this->returnValue($expectedRuleIds));
     $this->rulesApplier->expects($this->once())->method('setAppliedRuleIds')->with($this->anything(), $expectedRuleIds);
     $this->model->process($this->item);
 }
Example #20
0
 /**
  * @param string $displayType
  * @param bool $pagerEnable
  * @param int $productsCount
  * @param int $productsPerPage
  */
 protected function startTestGetProductCollection($displayType, $pagerEnable, $productsCount, $productsPerPage)
 {
     $productCollectionFactory = $this->getMock('Magento\\Catalog\\Model\\ResourceModel\\Product\\CollectionFactory', ['create'], [], '', false, false);
     $productCollectionFactory->expects($this->atLeastOnce())->method('create')->willReturn($this->productCollection);
     $this->block = $this->objectManager->getObject('Magento\\Catalog\\Block\\Product\\Widget\\NewWidget', ['context' => $this->context, 'productCollectionFactory' => $productCollectionFactory]);
     if (null === $productsPerPage) {
         $this->block->unsetData('products_per_page');
     } else {
         $this->block->setData('products_per_page', $productsPerPage);
     }
     $this->block->setData('show_pager', $pagerEnable);
     $this->block->setData('display_type', $displayType);
     $this->block->setProductsCount($productsCount);
     $this->block->toHtml();
 }
 public function testSaveExistingWithMediaGalleryEntries()
 {
     //update one entry, delete one entry
     $newEntries = [['id' => 5, "label" => "new_label_text", 'file' => 'filename1', 'position' => 10, 'disabled' => false, 'types' => ['image', 'small_image']]];
     $existingMediaGallery = ['images' => [['value_id' => 5, "label" => "label_text", 'file' => 'filename1', 'position' => 10, 'disabled' => true], ['value_id' => 6, 'file' => 'filename2']]];
     $expectedResult = [['id' => 5, 'value_id' => 5, "label" => "new_label_text", 'file' => 'filename1', 'position' => 10, 'disabled' => false, 'types' => ['image', 'small_image']], ['value_id' => 6, 'file' => 'filename2', 'removed' => true]];
     $this->setupProductMocksForSave();
     //media gallery data
     $this->productData['media_gallery_entries'] = $newEntries;
     $this->extensibleDataObjectConverterMock->expects($this->once())->method('toNestedArray')->will($this->returnValue($this->productData));
     $this->initializedProductMock->setData('media_gallery', $existingMediaGallery);
     $this->initializedProductMock->expects($this->any())->method('getMediaAttributes')->willReturn(["image" => "filename1", "small_image" => "filename2"]);
     $this->mediaGalleryProcessor->expects($this->once())->method('clearMediaAttribute')->with($this->initializedProductMock, ['image', 'small_image']);
     $this->mediaGalleryProcessor->expects($this->once())->method('setMediaAttribute')->with($this->initializedProductMock, ['image', 'small_image'], 'filename1');
     $this->initializedProductMock->expects($this->once())->method('getWebsiteIds')->willReturn([]);
     $this->model->save($this->productMock);
     $this->assertEquals($expectedResult, $this->initializedProductMock->getMediaGallery('images'));
 }
Example #22
0
 public function testCalcRowTotal()
 {
     $this->item->setData(['order_item_id' => 1, 'qty' => 2]);
     $this->item->setInvoice($this->invoiceMock);
     $this->invoiceMock->expects($this->once())->method('getOrder')->willReturn($this->orderMock);
     $this->orderMock->expects($this->once())->method('getItemById')->with(1)->willReturn($this->orderItemMock);
     $this->orderItemMock->expects($this->once())->method('getQtyOrdered')->willReturn(1);
     $this->orderItemMock->expects($this->once())->method('getRowTotal')->willReturn(2);
     $this->orderItemMock->expects($this->once())->method('getRowInvoiced')->willReturn(1);
     $this->orderItemMock->expects($this->once())->method('getBaseRowTotal')->willReturn(2);
     $this->orderItemMock->expects($this->once())->method('getBaseRowInvoiced')->willReturn(1);
     $this->orderItemMock->expects($this->once())->method('getRowTotalInclTax')->willReturn(1);
     $this->orderItemMock->expects($this->once())->method('getBaseRowTotalInclTax')->willReturn(1);
     $this->orderItemMock->expects($this->once())->method('getQtyToInvoice')->willReturn(1);
     $this->orderItemMock->expects($this->once())->method('getQtyInvoiced')->willReturn(0);
     $this->invoiceMock->expects($this->exactly(4))->method('roundPrice')->willReturnMap([[2, 'regular', false, 2], [2, 'base', false, 2], [2, 'including', false, 2], [2, 'including_base', false, 2]]);
     $this->assertEquals($this->item->calcRowTotal(), $this->item);
 }
 /**
  * @param array $addressData
  * @param bool $useBaseCurrency
  * @param string $shippingTaxClass
  * @param bool $shippingPriceInclTax
  * @dataProvider getShippingDataObjectDataProvider
  */
 public function testGetShippingDataObject(array $addressData, $useBaseCurrency, $shippingTaxClass, $shippingPriceInclTax)
 {
     $baseShippingAmount = $addressData['base_shipping_amount'];
     $shippingAmount = $addressData['shipping_amount'];
     $this->taxConfig->expects($this->any())->method('getShippingTaxClass')->with($this->store)->will($this->returnValue($shippingTaxClass));
     $this->taxConfig->expects($this->any())->method('shippingPriceIncludesTax')->with($this->store)->will($this->returnValue($shippingPriceInclTax));
     $this->address->expects($this->atLeastOnce())->method('getShippingDiscountAmount')->willReturn($shippingAmount);
     if ($shippingAmount) {
         if ($useBaseCurrency && $shippingAmount != 0) {
             $this->address->expects($this->once())->method('getBaseShippingDiscountAmount')->willReturn($baseShippingAmount);
             $expectedDiscountAmount = $baseShippingAmount;
         } else {
             $this->address->expects($this->never())->method('getBaseShippingDiscountAmount');
             $expectedDiscountAmount = $shippingAmount;
         }
     }
     foreach ($addressData as $key => $value) {
         $this->address->setData($key, $value);
     }
     $this->assertEquals($this->quoteDetailsItemDataObject, $this->commonTaxCollector->getShippingDataObject($this->address, $useBaseCurrency));
     if ($shippingAmount) {
         $this->assertEquals($expectedDiscountAmount, $this->quoteDetailsItemDataObject->getDiscountAmount());
     }
 }
Example #24
0
 public function testGetSpecificInformation()
 {
     $paymentInfo = $this->getMockBuilder('\\Magento\\Payment\\Model\\Info')->disableOriginalConstructor()->getMock();
     $this->_object->setData('info', $paymentInfo);
     $this->_object->getSpecificInformation();
 }
Example #25
0
 /**
  * @covers \Magento\Framework\View\Design\Theme\Customization::getThemeFilesPath
  * @dataProvider getThemeFilesPathDataProvider
  * @param string $type
  * @param string $expectedMethod
  */
 public function testGetThemeFilesPath($type, $expectedMethod)
 {
     $this->theme->setData(array('id' => 123, 'type' => $type, 'area' => 'area51', 'theme_path' => 'theme_path'));
     $this->customizationPath->expects($this->once())->method($expectedMethod)->with($this->theme)->will($this->returnValue('path'));
     $this->assertEquals('path', $this->model->getThemeFilesPath());
 }
Example #26
0
 /**
  * Prepare payment for the order
  *
  * @param \Magento\Sales\Model\Order|\PHPUnit_Framework_MockObject_MockObject $order
  * @param array $mockedMethods
  * @return \Magento\Sales\Model\Order\Payment|\PHPUnit_Framework_MockObject_MockObject
  */
 protected function _prepareOrderPayment($order, $mockedMethods = [])
 {
     $payment = $this->getMockBuilder('Magento\\Sales\\Model\\Order\\Payment')->disableOriginalConstructor()->getMock();
     foreach ($mockedMethods as $method => $value) {
         $payment->expects($this->any())->method($method)->will($this->returnValue($value));
     }
     $payment->expects($this->any())->method('isDeleted')->will($this->returnValue(false));
     $order->setData(\Magento\Sales\Api\Data\OrderInterface::PAYMENTS, [$payment]);
     return $payment;
 }
Example #27
0
 /**
  * @covers \Magento\Framework\View\Design\Theme\Image::getPreviewImageUrl
  */
 public function testGetDefaultPreviewImageUrl()
 {
     $this->_themeMock->setData($this->_getThemeSampleData());
     $this->_themeMock->setData('preview_image', null);
     $this->assertEquals('http://localhost/media_path/test_default_preview.png', $this->_model->getPreviewImageUrl());
 }
Example #28
0
 /**
  * @covers \Magento\Backend\Block\Widget\Button::getAttributesHtml
  * @dataProvider getAttributesHtmlDataProvider
  */
 public function testGetAttributesHtml($data, $expect)
 {
     $this->_blockMock->setData($data);
     $attributes = $this->_blockMock->getAttributesHtml();
     $this->assertRegExp($expect, $attributes);
 }
 public function testIsSalable()
 {
     $this->product->expects($this->any())->method('getStatus')->will($this->returnValue(Status::STATUS_ENABLED));
     $this->product->setData('is_salable', 3);
     $this->assertEquals(true, $this->model->isSalable($this->product));
 }
    public function testSaveExistingWithMediaGalleryEntries()
    {
        //update one entry, delete one entry
        $newEntries = [
            [
                'id' => 5,
                "label" => "new_label_text",
                'file' => 'filename1',
                'position' => 10,
                'disabled' => false,
                'types' => ['image', 'small_image'],
            ],
        ];

        $existingMediaGallery = [
            'images' => [
                [
                    'value_id' => 5,
                    "label" => "label_text",
                    'file' => 'filename1',
                    'position' => 10,
                    'disabled' => true,
                ],
                [
                    'value_id' => 6, //will be deleted
                    'file' => 'filename2',
                ],
            ],
        ];

        $expectedResult = [
            [
                'id' => 5,
                'value_id' => 5,
                "label" => "new_label_text",
                'file' => 'filename1',
                'position' => 10,
                'disabled' => false,
                'types' => ['image', 'small_image'],
            ],
            [
                'value_id' => 6, //will be deleted
                'file' => 'filename2',
                'removed' => true,
            ],
        ];

        $this->setupProductMocksForSave();
        //media gallery data
        $this->productData['media_gallery_entries'] = $newEntries;
        $this->extensibleDataObjectConverterMock
            ->expects($this->once())
            ->method('toNestedArray')
            ->will($this->returnValue($this->productData));

        $this->initializedProductMock->setData('media_gallery', $existingMediaGallery);
        $this->initializedProductMock->expects($this->any())
            ->method('getMediaAttributes')
            ->willReturn(["image" => "filename1", "small_image" => "filename2"]);

        //setup media attribute backend
        $galleryAttributeBackendMock = $this->getMockBuilder('\Magento\Catalog\Model\Product\Attribute\Backend\Media')
            ->disableOriginalConstructor()->getMock();
        $galleryAttributeBackendMock->expects($this->once())->method('clearMediaAttribute')
            ->with($this->initializedProductMock, ['image', 'small_image']);
        $this->initializedProductMock->expects($this->once())
            ->method('getGalleryAttributeBackend')
            ->willReturn($galleryAttributeBackendMock);
        $galleryAttributeBackendMock->expects($this->once())
            ->method('setMediaAttribute')
            ->with($this->initializedProductMock, ['image', 'small_image'], 'filename1');

        $this->model->save($this->productMock);
        $this->assertEquals($expectedResult, $this->initializedProductMock->getMediaGallery('images'));
    }