Label Text", $html);
+ $this->_label->setBold(true);
+ $html = $this->_label->getElementHtml();
+ $this->assertContains("
Label Text", $html);
+ }
+}
diff --git a/dev/tests/unit/testsuite/Magento/Framework/Data/Form/Element/LinkTest.php b/dev/tests/unit/testsuite/Magento/Framework/Data/Form/Element/LinkTest.php
new file mode 100644
index 0000000000000..25760cabb5dda
--- /dev/null
+++ b/dev/tests/unit/testsuite/Magento/Framework/Data/Form/Element/LinkTest.php
@@ -0,0 +1,134 @@
+getMock('\Magento\Framework\Data\Form\Element\Factory', array(), array(), '', false);
+ $collectionFactoryMock = $this->getMock(
+ '\Magento\Framework\Data\Form\Element\CollectionFactory',
+ array(),
+ array(),
+ '',
+ false
+ );
+ $escaperMock = $this->getMock('\Magento\Framework\Escaper', array(), array(), '', false);
+ $this->_link = new \Magento\Framework\Data\Form\Element\Link(
+ $factoryMock,
+ $collectionFactoryMock,
+ $escaperMock
+ );
+ $formMock = new \Magento\Framework\Object();
+ $formMock->getHtmlIdPrefix('id_prefix');
+ $formMock->getHtmlIdPrefix('id_suffix');
+ $this->_link->setForm($formMock);
+ }
+
+ /**
+ * @covers \Magento\Framework\Data\Form\Element\Link::__construct
+ */
+ public function testConstruct()
+ {
+ $this->assertEquals('link', $this->_link->getType());
+ }
+
+ /**
+ * @covers \Magento\Framework\Data\Form\Element\Link::getElementHtml
+ */
+ public function testGetElementHtml()
+ {
+ $this->_link->setBeforeElementHtml('link_before');
+ $this->_link->setAfterElementHtml('link_after');
+ $this->_link->setId('link_id');
+ $this->_link->setData('ui_id', 'ui_id');
+ $this->_link->setValue('Link Text');
+ $html = $this->_link->getElementHtml();
+ $this->assertEquals(
+ "link_before
Link Text\nlink_after",
+ $html
+ );
+ }
+
+ /**
+ * @covers \Magento\Framework\Data\Form\Element\Link::getHtmlAttributes
+ */
+ public function testGetHtmlAttributes()
+ {
+ $this->assertEmpty(
+ array_diff(
+ array(
+ 'charset',
+ 'coords',
+ 'href',
+ 'hreflang',
+ 'rel',
+ 'rev',
+ 'name',
+ 'shape',
+ 'target',
+ 'accesskey',
+ 'class',
+ 'dir',
+ 'lang',
+ 'style',
+ 'tabindex',
+ 'title',
+ 'xml:lang',
+ 'onblur',
+ 'onclick',
+ 'ondblclick',
+ 'onfocus',
+ 'onmousedown',
+ 'onmousemove',
+ 'onmouseout',
+ 'onmouseover',
+ 'onmouseup',
+ 'onkeydown',
+ 'onkeypress',
+ 'onkeyup'
+ ),
+ $this->_link->getHtmlAttributes()
+ )
+ );
+ }
+}
diff --git a/dev/tests/unit/testsuite/Magento/Framework/Data/Form/Element/NoteTest.php b/dev/tests/unit/testsuite/Magento/Framework/Data/Form/Element/NoteTest.php
new file mode 100644
index 0000000000000..0375358e9f258
--- /dev/null
+++ b/dev/tests/unit/testsuite/Magento/Framework/Data/Form/Element/NoteTest.php
@@ -0,0 +1,91 @@
+getMock('\Magento\Framework\Data\Form\Element\Factory', array(), array(), '', false);
+ $collectionFactoryMock = $this->getMock(
+ '\Magento\Framework\Data\Form\Element\CollectionFactory',
+ array(),
+ array(),
+ '',
+ false
+ );
+ $escaperMock = $this->getMock('\Magento\Framework\Escaper', array(), array(), '', false);
+ $this->_model = new \Magento\Framework\Data\Form\Element\Note(
+ $factoryMock,
+ $collectionFactoryMock,
+ $escaperMock
+ );
+ $formMock = new \Magento\Framework\Object();
+ $formMock->getHtmlIdPrefix('id_prefix');
+ $formMock->getHtmlIdPrefix('id_suffix');
+ $this->_model->setForm($formMock);
+ }
+
+ /**
+ * @covers \Magento\Framework\Data\Form\Element\Note::__construct
+ */
+ public function testConstruct()
+ {
+ $this->assertEquals('note', $this->_model->getType());
+ }
+
+ /**
+ * @covers \Magento\Framework\Data\Form\Element\Note::getElementHtml
+ */
+ public function testGetElementHtml()
+ {
+ $this->_model->setBeforeElementHtml('note_before');
+ $this->_model->setAfterElementHtml('note_after');
+ $this->_model->setId('note_id');
+ $this->_model->setData('ui_id', 'ui_id');
+ $this->_model->setValue('Note Text');
+ $html = $this->_model->getElementHtml();
+ $this->assertEquals(
+ "note_before
note_after",
+ $html
+ );
+ }
+}
diff --git a/dev/tests/unit/testsuite/Magento/Framework/Data/Form/Element/ObscureTest.php b/dev/tests/unit/testsuite/Magento/Framework/Data/Form/Element/ObscureTest.php
new file mode 100644
index 0000000000000..222a99818236f
--- /dev/null
+++ b/dev/tests/unit/testsuite/Magento/Framework/Data/Form/Element/ObscureTest.php
@@ -0,0 +1,111 @@
+getMock('\Magento\Framework\Data\Form\Element\Factory', array(), array(), '', false);
+ $collectionFactoryMock = $this->getMock(
+ '\Magento\Framework\Data\Form\Element\CollectionFactory',
+ array(),
+ array(),
+ '',
+ false
+ );
+ $escaperMock = $this->getMock('\Magento\Framework\Escaper', array(), array(), '', false);
+ $this->_model = new \Magento\Framework\Data\Form\Element\Obscure(
+ $factoryMock,
+ $collectionFactoryMock,
+ $escaperMock
+ );
+ $formMock = new \Magento\Framework\Object();
+ $formMock->getHtmlIdPrefix('id_prefix');
+ $formMock->getHtmlIdPrefix('id_suffix');
+ $this->_model->setForm($formMock);
+ }
+
+ /**
+ * @covers \Magento\Framework\Data\Form\Element\Obscure::__construct
+ */
+ public function testConstruct()
+ {
+ $this->assertEquals('password', $this->_model->getType());
+ $this->assertEquals('textfield', $this->_model->getExtType());
+ }
+
+ /**
+ * @covers \Magento\Framework\Data\Form\Element\Obscure::getEscapedValue
+ */
+ public function testGetEscapedValue()
+ {
+ $this->_model->setValue('Obscure Text');
+ $this->assertContains('value="******"', $this->_model->getElementHtml());
+ $this->_model->setValue('');
+ $this->assertContains('value=""', $this->_model->getElementHtml());
+ }
+
+ /**
+ * @covers \Magento\Framework\Data\Form\Element\Obscure::getHtmlAttributes
+ */
+ public function testGetHtmlAttributes()
+ {
+ $this->assertEmpty(
+ array_diff(
+ array(
+ 'type',
+ 'title',
+ 'class',
+ 'style',
+ 'onclick',
+ 'onchange',
+ 'onkeyup',
+ 'disabled',
+ 'readonly',
+ 'maxlength',
+ 'tabindex'
+ ),
+ $this->_model->getHtmlAttributes()
+ )
+ );
+ }
+}
diff --git a/dev/tests/unit/testsuite/Magento/Framework/Data/Form/Element/PasswordTest.php b/dev/tests/unit/testsuite/Magento/Framework/Data/Form/Element/PasswordTest.php
new file mode 100644
index 0000000000000..4656dea84408a
--- /dev/null
+++ b/dev/tests/unit/testsuite/Magento/Framework/Data/Form/Element/PasswordTest.php
@@ -0,0 +1,85 @@
+getMock('\Magento\Framework\Data\Form\Element\Factory', array(), array(), '', false);
+ $collectionFactoryMock = $this->getMock(
+ '\Magento\Framework\Data\Form\Element\CollectionFactory',
+ array(),
+ array(),
+ '',
+ false
+ );
+ $escaperMock = $this->getMock('\Magento\Framework\Escaper', array(), array(), '', false);
+ $this->_model = new \Magento\Framework\Data\Form\Element\Obscure(
+ $factoryMock,
+ $collectionFactoryMock,
+ $escaperMock
+ );
+ $formMock = new \Magento\Framework\Object();
+ $formMock->getHtmlIdPrefix('id_prefix');
+ $formMock->getHtmlIdPrefix('id_suffix');
+ $this->_model->setForm($formMock);
+ }
+
+ /**
+ * @covers \Magento\Framework\Data\Form\Element\Password::__construct
+ */
+ public function testConstruct()
+ {
+ $this->assertEquals('password', $this->_model->getType());
+ $this->assertEquals('textfield', $this->_model->getExtType());
+ }
+
+ /**
+ * @covers \Magento\Framework\Data\Form\Element\Password::getHtml
+ */
+ public function testGetHtml()
+ {
+ $html = $this->_model->getHtml();
+ $this->assertContains('type="password"', $html);
+ $this->assertTrue(preg_match('/class=\".*input-text.*\"/i', $html) > 0);
+ }
+}
diff --git a/dev/tests/unit/testsuite/Magento/Framework/Data/Form/Element/RadioTest.php b/dev/tests/unit/testsuite/Magento/Framework/Data/Form/Element/RadioTest.php
new file mode 100644
index 0000000000000..a06171e64c76e
--- /dev/null
+++ b/dev/tests/unit/testsuite/Magento/Framework/Data/Form/Element/RadioTest.php
@@ -0,0 +1,75 @@
+getMock('\Magento\Framework\Data\Form\Element\Factory', array(), array(), '', false);
+ $collectionFactoryMock = $this->getMock(
+ '\Magento\Framework\Data\Form\Element\CollectionFactory',
+ array(),
+ array(),
+ '',
+ false
+ );
+ $escaperMock = $this->getMock('\Magento\Framework\Escaper', array(), array(), '', false);
+ $this->_model = new \Magento\Framework\Data\Form\Element\Radio(
+ $factoryMock,
+ $collectionFactoryMock,
+ $escaperMock
+ );
+ $formMock = new \Magento\Framework\Object();
+ $formMock->getHtmlIdPrefix('id_prefix');
+ $formMock->getHtmlIdPrefix('id_suffix');
+ $this->_model->setForm($formMock);
+ }
+
+ /**
+ * @covers \Magento\Framework\Data\Form\Element\Radio::__construct
+ */
+ public function testConstruct()
+ {
+ $this->assertEquals('radio', $this->_model->getType());
+ $this->assertEquals('radio', $this->_model->getExtType());
+ }
+}
diff --git a/dev/tests/unit/testsuite/Magento/Framework/Data/Form/Element/ResetTest.php b/dev/tests/unit/testsuite/Magento/Framework/Data/Form/Element/ResetTest.php
new file mode 100644
index 0000000000000..a4860a0302b7f
--- /dev/null
+++ b/dev/tests/unit/testsuite/Magento/Framework/Data/Form/Element/ResetTest.php
@@ -0,0 +1,75 @@
+getMock('\Magento\Framework\Data\Form\Element\Factory', array(), array(), '', false);
+ $collectionFactoryMock = $this->getMock(
+ '\Magento\Framework\Data\Form\Element\CollectionFactory',
+ array(),
+ array(),
+ '',
+ false
+ );
+ $escaperMock = $this->getMock('\Magento\Framework\Escaper', array(), array(), '', false);
+ $this->_model = new \Magento\Framework\Data\Form\Element\Reset(
+ $factoryMock,
+ $collectionFactoryMock,
+ $escaperMock
+ );
+ $formMock = new \Magento\Framework\Object();
+ $formMock->getHtmlIdPrefix('id_prefix');
+ $formMock->getHtmlIdPrefix('id_suffix');
+ $this->_model->setForm($formMock);
+ }
+
+ /**
+ * @covers \Magento\Framework\Data\Form\Element\Reset::__construct
+ */
+ public function testConstruct()
+ {
+ $this->assertEquals('text', $this->_model->getType());
+ $this->assertEquals('textfield', $this->_model->getExtType());
+ }
+}
diff --git a/dev/tests/unit/testsuite/Magento/Framework/Data/Form/Element/SubmitTest.php b/dev/tests/unit/testsuite/Magento/Framework/Data/Form/Element/SubmitTest.php
new file mode 100644
index 0000000000000..b9f84bd30716d
--- /dev/null
+++ b/dev/tests/unit/testsuite/Magento/Framework/Data/Form/Element/SubmitTest.php
@@ -0,0 +1,85 @@
+getMock('\Magento\Framework\Data\Form\Element\Factory', array(), array(), '', false);
+ $collectionFactoryMock = $this->getMock(
+ '\Magento\Framework\Data\Form\Element\CollectionFactory',
+ array(),
+ array(),
+ '',
+ false
+ );
+ $escaperMock = $this->getMock('\Magento\Framework\Escaper', array(), array(), '', false);
+ $this->_model = new \Magento\Framework\Data\Form\Element\Submit(
+ $factoryMock,
+ $collectionFactoryMock,
+ $escaperMock
+ );
+ $formMock = new \Magento\Framework\Object();
+ $formMock->getHtmlIdPrefix('id_prefix');
+ $formMock->getHtmlIdPrefix('id_suffix');
+ $this->_model->setForm($formMock);
+ }
+
+ /**
+ * @covers \Magento\Framework\Data\Form\Element\Submit::__construct
+ */
+ public function testConstruct()
+ {
+ $this->assertEquals('submit', $this->_model->getType());
+ $this->assertEquals('submit', $this->_model->getExtType());
+ }
+
+ /**
+ * @covers \Magento\Framework\Data\Form\Element\Submit::getHtml
+ */
+ public function testGetHtml()
+ {
+ $html = $this->_model->getHtml();
+ $this->assertContains('type="submit"', $html);
+ $this->assertTrue(preg_match('/class=\".*submit.*\"/i', $html) > 0);
+ }
+}
diff --git a/dev/tests/unit/testsuite/Magento/Framework/Data/Form/Element/TextTest.php b/dev/tests/unit/testsuite/Magento/Framework/Data/Form/Element/TextTest.php
new file mode 100644
index 0000000000000..0a986e750677f
--- /dev/null
+++ b/dev/tests/unit/testsuite/Magento/Framework/Data/Form/Element/TextTest.php
@@ -0,0 +1,111 @@
+getMock('\Magento\Framework\Data\Form\Element\Factory', array(), array(), '', false);
+ $collectionFactoryMock = $this->getMock(
+ '\Magento\Framework\Data\Form\Element\CollectionFactory',
+ array(),
+ array(),
+ '',
+ false
+ );
+ $escaperMock = $this->getMock('\Magento\Framework\Escaper', array(), array(), '', false);
+ $this->_model = new \Magento\Framework\Data\Form\Element\Text(
+ $factoryMock,
+ $collectionFactoryMock,
+ $escaperMock
+ );
+ $formMock = new \Magento\Framework\Object();
+ $formMock->getHtmlIdPrefix('id_prefix');
+ $formMock->getHtmlIdPrefix('id_suffix');
+ $this->_model->setForm($formMock);
+ }
+
+ /**
+ * @covers \Magento\Framework\Data\Form\Element\Text::__construct
+ */
+ public function testConstruct()
+ {
+ $this->assertEquals('text', $this->_model->getType());
+ $this->assertEquals('textfield', $this->_model->getExtType());
+ }
+
+ /**
+ * @covers \Magento\Framework\Data\Form\Element\Text::getHtml
+ */
+ public function testGetHtml()
+ {
+ $html = $this->_model->getHtml();
+ $this->assertContains('type="text"', $html);
+ $this->assertTrue(preg_match('/class=\".*input-text.*\"/i', $html) > 0);
+ }
+
+ /**
+ * @covers \Magento\Framework\Data\Form\Element\Text::getHtmlAttributes
+ */
+ public function testGetHtmlAttributes()
+ {
+ $this->assertEmpty(
+ array_diff(
+ array(
+ 'type',
+ 'title',
+ 'class',
+ 'style',
+ 'onclick',
+ 'onchange',
+ 'onkeyup',
+ 'disabled',
+ 'readonly',
+ 'maxlength',
+ 'tabindex',
+ 'placeholder'
+ ),
+ $this->_model->getHtmlAttributes()
+ )
+ );
+ }
+}
diff --git a/dev/tests/unit/testsuite/Magento/Framework/Data/Form/Element/TextareaTest.php b/dev/tests/unit/testsuite/Magento/Framework/Data/Form/Element/TextareaTest.php
new file mode 100644
index 0000000000000..f00acd6e1de92
--- /dev/null
+++ b/dev/tests/unit/testsuite/Magento/Framework/Data/Form/Element/TextareaTest.php
@@ -0,0 +1,114 @@
+getMock('\Magento\Framework\Data\Form\Element\Factory', array(), array(), '', false);
+ $collectionFactoryMock = $this->getMock(
+ '\Magento\Framework\Data\Form\Element\CollectionFactory',
+ array(),
+ array(),
+ '',
+ false
+ );
+ $escaperMock = $this->getMock('\Magento\Framework\Escaper', array(), array(), '', false);
+ $this->_model = new \Magento\Framework\Data\Form\Element\Textarea(
+ $factoryMock,
+ $collectionFactoryMock,
+ $escaperMock
+ );
+ $formMock = new \Magento\Framework\Object();
+ $formMock->getHtmlIdPrefix('id_prefix');
+ $formMock->getHtmlIdPrefix('id_suffix');
+ $this->_model->setForm($formMock);
+ }
+
+ /**
+ * @covers \Magento\Framework\Data\Form\Element\Textarea::__construct
+ */
+ public function testConstruct()
+ {
+ $this->assertEquals('textarea', $this->_model->getType());
+ $this->assertEquals('textarea', $this->_model->getExtType());
+ $this->assertEquals(2, $this->_model->getRows());
+ $this->assertEquals(15, $this->_model->getCols());
+ }
+
+ /**
+ * @covers \Magento\Framework\Data\Form\Element\Textarea::getElementHtml
+ */
+ public function testGetElementHtml()
+ {
+ $html = $this->_model->getElementHtml();
+ $this->assertContains('', $html);
+ $this->assertContains('rows="2"', $html);
+ $this->assertContains('cols="15"', $html);
+ $this->assertTrue(preg_match('/class=\".*textarea.*\"/i', $html) > 0);
+ }
+
+ /**
+ * @covers \Magento\Framework\Data\Form\Element\Textarea::getHtmlAttributes
+ */
+ public function testGetHtmlAttributes()
+ {
+ $this->assertEmpty(
+ array_diff(
+ array(
+ 'title',
+ 'class',
+ 'style',
+ 'onclick',
+ 'onchange',
+ 'rows',
+ 'cols',
+ 'readonly',
+ 'disabled',
+ 'onkeyup',
+ 'tabindex'
+ ),
+ $this->_model->getHtmlAttributes()
+ )
+ );
+ }
+}
diff --git a/dev/tests/unit/testsuite/Magento/Framework/Pricing/Adjustment/CalculatorTest.php b/dev/tests/unit/testsuite/Magento/Framework/Pricing/Adjustment/CalculatorTest.php
index 0b48e4bb7eda5..f5a00d6421363 100644
--- a/dev/tests/unit/testsuite/Magento/Framework/Pricing/Adjustment/CalculatorTest.php
+++ b/dev/tests/unit/testsuite/Magento/Framework/Pricing/Adjustment/CalculatorTest.php
@@ -18,6 +18,9 @@
* versions in the future. If you wish to customize Magento for your
* needs please refer to http://www.magentocommerce.com for more information.
*
+ * @category Magento
+ * @package Magento_Pricing
+ * @subpackage unit_tests
* @copyright Copyright (c) 2014 X.commerce, Inc. (http://www.magentocommerce.com)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/
@@ -48,6 +51,12 @@ public function setUp()
$this->model = new \Magento\Framework\Pricing\Adjustment\Calculator($this->amountFactoryMock);
}
+ public function tearDown()
+ {
+ $this->model = null;
+ $this->amountFactoryMock = null;
+ }
+
/**
* Test getAmount()
*/
@@ -58,10 +67,10 @@ public function testGetAmount()
$newAmount = 15;
$taxAdjustmentCode = 'tax';
$weeeAdjustmentCode = 'weee';
- $adjust = 5;
+ $adjustment = 5;
$expectedAdjustments = [
- $taxAdjustmentCode => $adjust,
- $weeeAdjustmentCode => $adjust
+ $taxAdjustmentCode => $adjustment,
+ $weeeAdjustmentCode => $adjustment
];
$productMock = $this->getMockBuilder('Magento\Catalog\Model\Product')
@@ -81,7 +90,7 @@ public function testGetAmount()
$taxAdjustmentMock->expects($this->once())
->method('extractAdjustment')
->with($this->equalTo($amount), $this->equalTo($productMock))
- ->will($this->returnValue($adjust));
+ ->will($this->returnValue($adjustment));
$weeeAdjustmentMock = $this->getMockBuilder('Magento\Weee\Pricing\Adjustment')
->disableOriginalConstructor()
@@ -126,4 +135,73 @@ public function testGetAmount()
$result = $this->model->getAmount($amount, $productMock);
$this->assertInstanceOf('Magento\Framework\Pricing\Amount\AmountInterface', $result);
}
+
+ public function testGetAmountExclude()
+ {
+ $amount = 10;
+ $taxAdjustmentCode = 'tax';
+ $weeeAdjustmentCode = 'weee';
+ $adjustment = 5;
+ $expectedAdjustments = [];
+
+ $productMock = $this->getMockBuilder('Magento\Catalog\Model\Product')
+ ->disableOriginalConstructor()
+ ->setMethods(['getPriceInfo', '__wakeup'])
+ ->getMock();
+
+ $taxAdjustmentMock = $this->getMockBuilder('Magento\Tax\Pricing\Adjustment')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $taxAdjustmentMock->expects($this->once())
+ ->method('getAdjustmentCode')
+ ->will($this->returnValue($taxAdjustmentCode));
+ $taxAdjustmentMock->expects($this->once())
+ ->method('isIncludedInBasePrice')
+ ->will($this->returnValue(true));
+ $taxAdjustmentMock->expects($this->once())
+ ->method('extractAdjustment')
+ ->with($this->equalTo($amount), $this->equalTo($productMock))
+ ->will($this->returnValue($adjustment));
+
+ $weeeAdjustmentMock = $this->getMockBuilder('Magento\Weee\Pricing\Adjustment')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $weeeAdjustmentMock->expects($this->once())
+ ->method('getAdjustmentCode')
+ ->will($this->returnValue($weeeAdjustmentCode));
+ $weeeAdjustmentMock->expects($this->once())
+ ->method('isIncludedInBasePrice')
+ ->will($this->returnValue(false));
+ $weeeAdjustmentMock->expects($this->once())
+ ->method('isIncludedInDisplayPrice')
+ ->with($this->equalTo($productMock))
+ ->will($this->returnValue(true));
+ $weeeAdjustmentMock->expects($this->never())
+ ->method('applyAdjustment');
+
+ $adjustments = [$taxAdjustmentMock, $weeeAdjustmentMock];
+
+ $priceInfoMock = $this->getMockBuilder('\Magento\Framework\Pricing\PriceInfoInterface')
+ ->disableOriginalConstructor()
+ //->setMethods(['getPriceInfo'])
+ ->getMock();
+ $priceInfoMock->expects($this->any())
+ ->method('getAdjustments')
+ ->will($this->returnValue($adjustments));
+
+ $productMock->expects($this->any())
+ ->method('getPriceInfo')
+ ->will($this->returnValue($priceInfoMock));
+
+ $amountBaseMock = $this->getMockBuilder('Magento\Framework\Pricing\Amount\Base')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $this->amountFactoryMock->expects($this->once())
+ ->method('create')
+ ->with($this->equalTo($amount), $this->equalTo($expectedAdjustments))
+ ->will($this->returnValue($amountBaseMock));
+ $result = $this->model->getAmount($amount, $productMock, true);
+ $this->assertInstanceOf('Magento\Framework\Pricing\Amount\AmountInterface', $result);
+ }
}
diff --git a/dev/tests/unit/testsuite/Magento/Framework/Pricing/Adjustment/CollectionTest.php b/dev/tests/unit/testsuite/Magento/Framework/Pricing/Adjustment/CollectionTest.php
index 0ed7b9423a5e5..53b12cafda2ec 100644
--- a/dev/tests/unit/testsuite/Magento/Framework/Pricing/Adjustment/CollectionTest.php
+++ b/dev/tests/unit/testsuite/Magento/Framework/Pricing/Adjustment/CollectionTest.php
@@ -18,6 +18,9 @@
* versions in the future. If you wish to customize Magento for your
* needs please refer to http://www.magentocommerce.com for more information.
*
+ * @category Magento
+ * @package Magento_Pricing
+ * @subpackage unit_tests
* @copyright Copyright (c) 2014 X.commerce, Inc. (http://www.magentocommerce.com)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/
diff --git a/dev/tests/unit/testsuite/Magento/Framework/Pricing/Adjustment/FactoryTest.php b/dev/tests/unit/testsuite/Magento/Framework/Pricing/Adjustment/FactoryTest.php
index 147567a255242..93bfb30ad02e8 100644
--- a/dev/tests/unit/testsuite/Magento/Framework/Pricing/Adjustment/FactoryTest.php
+++ b/dev/tests/unit/testsuite/Magento/Framework/Pricing/Adjustment/FactoryTest.php
@@ -18,6 +18,9 @@
* versions in the future. If you wish to customize Magento for your
* needs please refer to http://www.magentocommerce.com for more information.
*
+ * @category Magento
+ * @package Magento_Pricing
+ * @subpackage unit_tests
* @copyright Copyright (c) 2014 X.commerce, Inc. (http://www.magentocommerce.com)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/
@@ -69,8 +72,8 @@ protected function prepareObjectManager($adjustmentInterface)
{
$objectManager = $this->getMock(
'Magento\Framework\ObjectManager\ObjectManager',
- array('create'),
- array(),
+ ['create'],
+ [],
'',
false
);
diff --git a/dev/tests/unit/testsuite/Magento/Framework/Pricing/Adjustment/PoolTest.php b/dev/tests/unit/testsuite/Magento/Framework/Pricing/Adjustment/PoolTest.php
index 9bfe424bbb63f..00d2b79593ecf 100644
--- a/dev/tests/unit/testsuite/Magento/Framework/Pricing/Adjustment/PoolTest.php
+++ b/dev/tests/unit/testsuite/Magento/Framework/Pricing/Adjustment/PoolTest.php
@@ -18,6 +18,9 @@
* versions in the future. If you wish to customize Magento for your
* needs please refer to http://www.magentocommerce.com for more information.
*
+ * @category Magento
+ * @package Magento_Pricing
+ * @subpackage unit_tests
* @copyright Copyright (c) 2014 X.commerce, Inc. (http://www.magentocommerce.com)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/
@@ -40,7 +43,7 @@ public function setUp()
'adj5' => ['className' => 'adj5_class'],
];
- /** @var $adjustmentFactory \Magento\Framework\Pricing\Adjustment\Factory */
+ /** @var Factory|\PHPUnit_Framework_MockObject_MockObject $adjustmentFactory */
$adjustmentFactory = $this->getMockBuilder('Magento\Framework\Pricing\Adjustment\Factory')
->disableOriginalConstructor()
->setMethods(['create'])
diff --git a/dev/tests/unit/testsuite/Magento/Framework/Pricing/Amount/BaseTest.php b/dev/tests/unit/testsuite/Magento/Framework/Pricing/Amount/BaseTest.php
index ab82450311845..9adc6ec6b044b 100644
--- a/dev/tests/unit/testsuite/Magento/Framework/Pricing/Amount/BaseTest.php
+++ b/dev/tests/unit/testsuite/Magento/Framework/Pricing/Amount/BaseTest.php
@@ -18,6 +18,9 @@
* versions in the future. If you wish to customize Magento for your
* needs please refer to http://www.magentocommerce.com for more information.
*
+ * @category Magento
+ * @package Magento_Pricing
+ * @subpackage unit_tests
* @copyright Copyright (c) 2014 X.commerce, Inc. (http://www.magentocommerce.com)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/
diff --git a/dev/tests/unit/testsuite/Magento/Framework/Pricing/Price/AbstractPriceTest.php b/dev/tests/unit/testsuite/Magento/Framework/Pricing/Price/AbstractPriceTest.php
new file mode 100644
index 0000000000000..d478d29d4a905
--- /dev/null
+++ b/dev/tests/unit/testsuite/Magento/Framework/Pricing/Price/AbstractPriceTest.php
@@ -0,0 +1,127 @@
+saleableItemMock = $this->getMock('Magento\Catalog\Model\Product', [], [], '', false);
+ $this->priceInfoMock = $this->getMock('Magento\Framework\Pricing\PriceInfo\Base', [], [], '', false);
+ $this->amountMock = $this->getMock('Magento\Framework\Pricing\Amount', [], [], '', false);
+ $this->calculatorMock = $this->getMock('Magento\Framework\Pricing\Adjustment\Calculator', [], [], '', false);
+
+ $this->saleableItemMock->expects($this->once())
+ ->method('getPriceInfo')
+ ->will($this->returnValue($this->priceInfoMock));
+ $objectManager = new \Magento\TestFramework\Helper\ObjectManager($this);
+ $this->price = $objectManager->getObject(
+ 'Magento\Framework\Pricing\Price\Stub',
+ [
+ 'saleableItem' => $this->saleableItemMock,
+ 'quantity' => $qty,
+ 'calculator' => $this->calculatorMock
+ ]
+ );
+ }
+
+ /**
+ * Test method testGetDisplayValue
+ */
+ public function testGetAmount()
+ {
+ $priceValue = $this->price->getValue();
+ $amountValue = 88;
+ $this->calculatorMock->expects($this->once())
+ ->method('getAmount')
+ ->with($this->equalTo($priceValue))
+ ->will($this->returnValue($amountValue));
+ $this->assertEquals($amountValue, $this->price->getAmount());
+ }
+
+ /**
+ * Test method getPriceType
+ */
+ public function testGetPriceCode()
+ {
+ $this->assertEquals(AbstractPrice::PRICE_CODE, $this->price->getPriceCode());
+ }
+
+ public function testGetCustomAmount()
+ {
+ $exclude = false;
+ $amount = 21.0;
+ $customAmount = 42.0;
+ $this->calculatorMock->expects($this->once())
+ ->method('getAmount')
+ ->with($amount, $this->saleableItemMock, $exclude)
+ ->will($this->returnValue($customAmount));
+
+ $this->assertEquals($customAmount, $this->price->getCustomAmount($amount, $exclude));
+ }
+
+ public function testGetCustomAmountDefault()
+ {
+ $customAmount = 42.0;
+ $this->calculatorMock->expects($this->once())
+ ->method('getAmount')
+ ->with($this->price->getValue(), $this->saleableItemMock, null)
+ ->will($this->returnValue($customAmount));
+
+ $this->assertEquals($customAmount, $this->price->getCustomAmount());
+ }
+}
diff --git a/dev/tests/unit/testsuite/Magento/Framework/Pricing/Price/CollectionTest.php b/dev/tests/unit/testsuite/Magento/Framework/Pricing/Price/CollectionTest.php
new file mode 100644
index 0000000000000..e1252270c6fc8
--- /dev/null
+++ b/dev/tests/unit/testsuite/Magento/Framework/Pricing/Price/CollectionTest.php
@@ -0,0 +1,121 @@
+pool = new Pool(
+ [
+ 'regular_price' => 'RegularPrice',
+ 'special_price' => 'SpecialPrice',
+ 'group_price' => 'GroupPrice'
+ ]
+ );
+
+ $this->saleableItemMock = $this->getMockForAbstractClass('Magento\Framework\Pricing\Object\SaleableInterface');
+ $this->priceMock = $this->getMockForAbstractClass('Magento\Framework\Pricing\Price\PriceInterface');
+ $this->factoryMock = $this->getMock('Magento\Framework\Pricing\Price\Factory', [], [], '', false);
+
+ $this->collection = new Collection(
+ $this->saleableItemMock,
+ $this->factoryMock,
+ $this->pool,
+ $this->quantity
+ );
+ }
+
+ /**
+ * Test get method
+ */
+ public function testGet()
+ {
+ $this->factoryMock->expects($this->once())
+ ->method('create')
+ ->with(
+ $this->equalTo($this->saleableItemMock),
+ $this->equalTo('RegularPrice'),
+ $this->quantity
+ )
+ ->will($this->returnValue($this->priceMock));
+ $this->assertEquals($this->priceMock, $this->collection->get('regular_price'));
+ }
+
+ /**
+ * Test current method
+ */
+ public function testCurrent()
+ {
+ $this->factoryMock->expects($this->once())
+ ->method('create')
+ ->with(
+ $this->equalTo($this->saleableItemMock),
+ $this->equalTo($this->pool->current()),
+ $this->quantity
+ )
+ ->will($this->returnValue($this->priceMock));
+ $this->assertEquals($this->priceMock, $this->collection->current());
+ }
+}
diff --git a/dev/tests/unit/testsuite/Magento/Framework/Pricing/Price/FactoryTest.php b/dev/tests/unit/testsuite/Magento/Framework/Pricing/Price/FactoryTest.php
index 382c8e23835e4..89a315563bf8e 100644
--- a/dev/tests/unit/testsuite/Magento/Framework/Pricing/Price/FactoryTest.php
+++ b/dev/tests/unit/testsuite/Magento/Framework/Pricing/Price/FactoryTest.php
@@ -18,6 +18,9 @@
* versions in the future. If you wish to customize Magento for your
* needs please refer to http://www.magentocommerce.com for more information.
*
+ * @category Magento
+ * @package Magento_Pricing
+ * @subpackage unit_tests
* @copyright Copyright (c) 2014 X.commerce, Inc. (http://www.magentocommerce.com)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/
@@ -56,41 +59,40 @@ public function testCreate()
$quantity = 2.2;
$className = 'Magento\Framework\Pricing\Price\PriceInterface';
$priceMock = $this->getMock($className);
- $salableItem = $this->getMock('Magento\Framework\Pricing\Object\SaleableInterface');
+ $saleableItem = $this->getMock('Magento\Framework\Pricing\Object\SaleableInterface');
$arguments = [];
- $argumentsResult = array_merge($arguments, ['salableItem' => $salableItem, 'quantity' => $quantity]);
+ $argumentsResult = array_merge($arguments, ['saleableItem' => $saleableItem, 'quantity' => $quantity]);
$this->objectManagerMock->expects($this->once())
->method('create')
->with($className, $argumentsResult)
->will($this->returnValue($priceMock));
- $this->assertEquals($priceMock, $this->model->create($salableItem, $className, $quantity, $arguments));
+ $this->assertEquals($priceMock, $this->model->create($saleableItem, $className, $quantity, $arguments));
}
+ /**
+ * @codingStandardsIgnoreStart
+ * @expectedException \InvalidArgumentException
+ * @expectedExceptionMessage Magento\Framework\Pricing\PriceInfo\Base doesn't implement \Magento\Framework\Pricing\Price\PriceInterface
+ * @codingStandardsIgnoreEnd
+ */
public function testCreateWithException()
{
- $this->setExpectedException(
- 'InvalidArgumentException',
- sprintf(
- 'Magento\Framework\Pricing\PriceInfo\Base doesn\'t implement %s',
- '\Magento\Framework\Pricing\Price\PriceInterface'
- )
- );
$quantity = 2.2;
$className = 'Magento\Framework\Pricing\PriceInfo\Base';
$priceMock = $this->getMockBuilder($className)->disableOriginalConstructor()->getMock();
- $salableItem = $this->getMock('Magento\Framework\Pricing\Object\SaleableInterface');
+ $saleableItem = $this->getMock('Magento\Framework\Pricing\Object\SaleableInterface');
$arguments = [];
- $argumentsResult = array_merge($arguments, ['salableItem' => $salableItem, 'quantity' => $quantity]);
+ $argumentsResult = array_merge($arguments, ['saleableItem' => $saleableItem, 'quantity' => $quantity]);
$this->objectManagerMock->expects($this->once())
->method('create')
->with($className, $argumentsResult)
->will($this->returnValue($priceMock));
- $this->model->create($salableItem, $className, $quantity, $arguments);
+ $this->model->create($saleableItem, $className, $quantity, $arguments);
}
}
diff --git a/dev/tests/unit/testsuite/Magento/Framework/Pricing/Price/PoolTest.php b/dev/tests/unit/testsuite/Magento/Framework/Pricing/Price/PoolTest.php
new file mode 100644
index 0000000000000..6858599eac02d
--- /dev/null
+++ b/dev/tests/unit/testsuite/Magento/Framework/Pricing/Price/PoolTest.php
@@ -0,0 +1,120 @@
+prices = [
+ 'regular_price' => 'RegularPrice',
+ 'special_price' => 'SpecialPrice'
+ ];
+ $this->target = [
+ 'group_price' => 'TargetGroupPrice',
+ 'regular_price' => 'TargetRegularPrice'
+ ];
+ $this->targetPool = new Pool($this->target);
+ $this->pool = new Pool($this->prices, $this->targetPool);
+ }
+
+ /**
+ * test mergedConfiguration
+ */
+ public function testMergedConfiguration()
+ {
+ $expected = new Pool([
+ 'regular_price' => 'RegularPrice',
+ 'special_price' => 'SpecialPrice',
+ 'group_price' => 'TargetGroupPrice'
+ ]);
+ $this->assertEquals($expected, $this->pool);
+ }
+
+ /**
+ * Test get method
+ */
+ public function testGet()
+ {
+ $this->assertEquals('RegularPrice', $this->pool->get('regular_price'));
+ $this->assertEquals('SpecialPrice', $this->pool->get('special_price'));
+ $this->assertEquals('TargetGroupPrice', $this->pool->get('group_price'));
+ }
+
+ /**
+ * Test abilities of ArrayAccess interface
+ */
+ public function testArrayAccess()
+ {
+ $this->assertEquals('RegularPrice', $this->pool['regular_price']);
+ $this->assertEquals('SpecialPrice', $this->pool['special_price']);
+ $this->assertEquals('TargetGroupPrice', $this->pool['group_price']);
+ $this->pool['fake_price'] = 'FakePrice';
+ $this->assertEquals('FakePrice', $this->pool['fake_price']);
+ $this->assertTrue(isset($this->pool['fake_price']));
+ unset($this->pool['fake_price']);
+ $this->assertFalse(isset($this->pool['fake_price']));
+ $this->assertNull($this->pool['fake_price']);
+ }
+
+ /**
+ * Test abilities of Iterator interface
+ */
+ public function testIterator()
+ {
+ foreach ($this->pool as $code => $class) {
+ $this->assertEquals($this->pool[$code], $class);
+ }
+ }
+}
diff --git a/dev/tests/unit/testsuite/Magento/Framework/Pricing/Price/Stub.php b/dev/tests/unit/testsuite/Magento/Framework/Pricing/Price/Stub.php
new file mode 100644
index 0000000000000..2be7d1988ea57
--- /dev/null
+++ b/dev/tests/unit/testsuite/Magento/Framework/Pricing/Price/Stub.php
@@ -0,0 +1,46 @@
+priceFactory = $this->getMockBuilder('Magento\Framework\Pricing\Price\Factory')
- ->disableOriginalConstructor()
- ->getMock();
-
- $this->metadata = array(
- FinalPriceInterface::PRICE_TYPE_FINAL => ['class' => 'Class\For\FinalPrice'],
- GroupPriceInterface::PRICE_TYPE_GROUP => ['class' => 'Class\For\GroupPrice'],
- SpecialPriceInterface::PRICE_TYPE_SPECIAL => ['class' => 'Class\For\SpecialPrice']
- );
-
- $objectManager = new \Magento\TestFramework\Helper\ObjectManager($this);
- $this->model = $objectManager->getObject('Magento\Framework\Pricing\PriceComposite', array(
- 'priceFactory' => $this->priceFactory,
- 'metadata' => $this->metadata
- ));
- }
-
- public function testGetPriceCodes()
- {
- $expectedCodes = [
- FinalPriceInterface::PRICE_TYPE_FINAL,
- GroupPriceInterface::PRICE_TYPE_GROUP,
- SpecialPriceInterface::PRICE_TYPE_SPECIAL
- ];
- $this->assertEquals($expectedCodes, $this->model->getPriceCodes());
- }
-
- public function testGetMetadata()
- {
- $this->assertEquals($this->metadata, $this->model->getMetadata());
- }
-
- public function testCreatePriceObject()
- {
- $saleable = $this->getMock('Magento\Framework\Pricing\Object\SaleableInterface');
- $priceCode = FinalPriceInterface::PRICE_TYPE_FINAL;
- $quantity = 2.4;
-
- $price = $this->getMock('Magento\Framework\Pricing\Price\PriceInterface');
-
- $this->priceFactory->expects($this->once())
- ->method('create')
- ->with($saleable, $this->metadata[$priceCode]['class'], $quantity)
- ->will($this->returnValue($price));
-
- $this->assertEquals($price, $this->model->createPriceObject($saleable, $priceCode, $quantity));
- }
-
- /**
- * @expectedException \InvalidArgumentException
- * @expectedExceptionMessage wrong_price is not registered in prices list
- */
- public function testCreatePriceObjectWithException()
- {
- $saleable = $this->getMock('Magento\Framework\Pricing\Object\SaleableInterface');
- $priceCode = 'wrong_price';
- $quantity = 2.4;
-
- $this->model->createPriceObject($saleable, $priceCode, $quantity);
- }
-}
diff --git a/dev/tests/unit/testsuite/Magento/Framework/Pricing/PriceInfo/BaseTest.php b/dev/tests/unit/testsuite/Magento/Framework/Pricing/PriceInfo/BaseTest.php
index 5491e1780b0c0..10af59566adb4 100644
--- a/dev/tests/unit/testsuite/Magento/Framework/Pricing/PriceInfo/BaseTest.php
+++ b/dev/tests/unit/testsuite/Magento/Framework/Pricing/PriceInfo/BaseTest.php
@@ -18,6 +18,9 @@
* versions in the future. If you wish to customize Magento for your
* needs please refer to http://www.magentocommerce.com for more information.
*
+ * @category Magento
+ * @package Magento_Pricing
+ * @subpackage unit_tests
* @copyright Copyright (c) 2014 X.commerce, Inc. (http://www.magentocommerce.com)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/
@@ -30,14 +33,9 @@
class BaseTest extends \PHPUnit_Framework_TestCase
{
/**
- * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\Pricing\Object\SaleableInterface
+ * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\Pricing\Price\Collection
*/
- protected $saleableItem;
-
- /**
- * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\Pricing\PriceComposite
- */
- protected $prices;
+ protected $priceCollection;
/**
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\Pricing\Adjustment\Collection
@@ -45,24 +43,13 @@ class BaseTest extends \PHPUnit_Framework_TestCase
protected $adjustmentCollection;
/**
- * @var float
- */
- protected $quantity;
-
- /**
- * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\Pricing\Amount\AmountFactory
- */
- protected $amountFactory;
-
- /**
- * @var \PHPUnit_Framework_MockObject_MockObject|Base
+ * @var Base
*/
protected $model;
public function setUp()
{
- $this->saleableItem = $this->getMock('Magento\Framework\Pricing\Object\SaleableInterface', [], [], '', false);
- $this->prices = $this->getMock('Magento\Framework\Pricing\PriceComposite', [], [], '', false);
+ $this->priceCollection = $this->getMock('Magento\Framework\Pricing\Price\Collection', [], [], '', false);
$this->adjustmentCollection = $this->getMock(
'Magento\Framework\Pricing\Adjustment\Collection',
[],
@@ -70,50 +57,35 @@ public function setUp()
'',
false
);
- $this->amountFactory = $this->getMock('Magento\Framework\Pricing\Amount\AmountFactory', [], [], '', false);
- $this->quantity = 3.;
- $this->model = new Base(
- $this->saleableItem,
- $this->prices,
- $this->adjustmentCollection,
- $this->amountFactory,
- $this->quantity
- );
+ $this->model = new Base($this->priceCollection, $this->adjustmentCollection);
}
/**
- * @covers \Magento\Framework\Pricing\PriceInfo\Base::__construct
- * @covers \Magento\Framework\Pricing\PriceInfo\Base::initPrices
- * @covers \Magento\Framework\Pricing\PriceInfo\Base::getPrices
+ * test method getPrices()
*/
public function testGetPrices()
{
- $this->prices->expects($this->once())
- ->method('getPriceCodes')
- ->will($this->returnValue(['test1', 'test2']));
- $this->prices->expects($this->at(1))->method('createPriceObject')
- ->with($this->saleableItem, 'test1', $this->quantity)->will($this->returnValue('1'));
- $this->prices->expects($this->at(2))->method('createPriceObject')
- ->with($this->saleableItem, 'test2', $this->quantity)->will($this->returnValue('2'));
- $this->assertEquals(['test1' => '1', 'test2' => '2'], $this->model->getPrices());
+ $this->assertEquals($this->priceCollection, $this->model->getPrices());
}
/**
- * @covers \Magento\Framework\Pricing\PriceInfo\Base::__construct
- * @covers \Magento\Framework\Pricing\PriceInfo\Base::getPrice
+ * @param $entryParams
+ * @param $createCount
* @dataProvider providerGetPrice
*/
public function testGetPrice($entryParams, $createCount)
{
- list($priceCode, $quantity) = array_values(reset($entryParams));
- $this->prices->expects($this->exactly($createCount))->method('createPriceObject')
- ->with($this->saleableItem, $priceCode, $quantity ? : $this->quantity)->will(
- $this->returnValue('basePrice')
- );
+ $priceCode = current(array_values(reset($entryParams)));
+
+ $this->priceCollection
+ ->expects($this->exactly($createCount))
+ ->method('get')
+ ->with($this->equalTo($priceCode))
+ ->will($this->returnValue('basePrice'));
foreach ($entryParams as $params) {
- list($priceCode, $quantity) = array_values($params);
- $this->assertEquals('basePrice', $this->model->getPrice($priceCode, $quantity));
+ list($priceCode) = array_values($params);
+ $this->assertEquals('basePrice', $this->model->getPrice($priceCode));
}
}
@@ -127,20 +99,20 @@ public function providerGetPrice()
return [
'case with empty quantity' => [
'entryParams' => [
- ['priceCode' => 'testCode', 'quantity' => null]
+ ['priceCode' => 'testCode']
],
'createCount' => 1
],
'case with existing price' => [
'entryParams' => [
- ['priceCode' => 'testCode', 'quantity' => null],
- ['priceCode' => 'testCode', 'quantity' => null]
+ ['priceCode' => 'testCode'],
+ ['priceCode' => 'testCode']
],
- 'createCount' => 1
+ 'createCount' => 2
],
'case with quantity' => [
'entryParams' => [
- ['priceCode' => 'testCode', 'quantity' => 2.]
+ ['priceCode' => 'testCode']
],
'createCount' => 1
],
@@ -166,28 +138,4 @@ public function testGetAdjustment()
->will($this->returnValue('adjustment'));
$this->assertEquals('adjustment', $this->model->getAdjustment('test1'));
}
-
- /**
- * @covers \Magento\Framework\Pricing\PriceInfo\Base::getPricesIncludedInBase
- */
- public function testGetPricesIncludedInBase()
- {
- $this->prices->expects($this->once())
- ->method('getMetadata')
- ->will(
- $this->returnValue(
- [
- 'test1' => ['class' => 'class1', 'include_in_base_price' => false],
- 'test2' => ['class' => 'class2', 'include_in_base_price' => true]
- ]
- )
- );
-
- $priceModelMock = $this->getMock('Magento\Catalog\Pricing\Price\SpecialPrice', [], [], '', false);
- $priceModelMock->expects($this->once())->method('getValue')->will($this->returnValue(2.5));
- $this->prices->expects($this->at(1))->method('createPriceObject')
- ->with($this->saleableItem, 'test2', $this->quantity)->will($this->returnValue($priceModelMock));
-
- $this->assertSame([$priceModelMock], $this->model->getPricesIncludedInBase());
- }
}
diff --git a/dev/tests/unit/testsuite/Magento/Framework/Pricing/PriceInfo/FactoryTest.php b/dev/tests/unit/testsuite/Magento/Framework/Pricing/PriceInfo/FactoryTest.php
index 47c03f501aa2e..3952b8f797515 100644
--- a/dev/tests/unit/testsuite/Magento/Framework/Pricing/PriceInfo/FactoryTest.php
+++ b/dev/tests/unit/testsuite/Magento/Framework/Pricing/PriceInfo/FactoryTest.php
@@ -18,115 +18,158 @@
* versions in the future. If you wish to customize Magento for your
* needs please refer to http://www.magentocommerce.com for more information.
*
+ * @category Magento
+ * @package Magento_Pricing
+ * @subpackage unit_tests
* @copyright Copyright (c) 2014 X.commerce, Inc. (http://www.magentocommerce.com)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/
namespace Magento\Framework\Pricing\PriceInfo;
+use Magento\Framework\Pricing\PriceInfo\Factory;
+
/**
* Test class for \Magento\Framework\Pricing\PriceInfo\Factory
*/
class FactoryTest extends \PHPUnit_Framework_TestCase
{
/**
- * @var \Magento\TestFramework\Helper\ObjectManager
+ * @var \Magento\Framework\ObjectManager\ObjectManager|\PHPUnit_Framework_MockObject_MockObject
*/
- protected $objectManager;
-
- public function setUp()
- {
- $this->objectManager = new \Magento\TestFramework\Helper\ObjectManager($this);
- }
+ protected $objectManagerMock;
/**
- * @dataProvider priceInfoClassesProvider
+ * @var array
*/
- public function testCreate($types, $type, $expected)
- {
- $priceInfoFactory = $this->preparePriceInfoFactory(
- $expected,
- $types
- );
+ protected $types;
- $productMock = $this->getMock(
- 'Magento\Catalog\Model\Product',
- ['getTypeId', 'getQty', '__wakeup'],
- [],
- '',
- false
- );
-
- $productMock->expects($this->any())
- ->method('getTypeId')
- ->will($this->returnValue($type));
+ /**
+ * @var \Magento\Framework\Pricing\PriceInfo\Factory
+ */
+ protected $factory;
- $productMock->expects($this->any())
- ->method('getQty')
- ->will($this->returnValue(1));
+ /**
+ * @var \Magento\Framework\Pricing\Price\Collection|\PHPUnit_Framework_MockObject_MockObject
+ */
+ protected $pricesMock;
- $this->assertInstanceOf(
- $expected,
- $priceInfoFactory->create($productMock)
- );
- }
+ /**
+ * @var \Magento\Framework\Pricing\Object\SaleableInterface|\PHPUnit_Framework_MockObject_MockObject
+ */
+ protected $saleableItemMock;
/**
- * @param string $priceInfoInterface
- * @param array $types
- * @return object
+ * @var \Magento\Framework\Pricing\PriceInfoInterface|\PHPUnit_Framework_MockObject_MockObject
*/
- protected function preparePriceInfoFactory($priceInfoInterface, $types = [])
- {
- return $this->objectManager->getObject(
- 'Magento\Framework\Pricing\PriceInfo\Factory',
- [
- 'types' => $types,
- 'objectManager' => $this->prepareObjectManager($priceInfoInterface)
- ]
- );
- }
+ protected $priceInfoMock;
/**
- * @param string $priceInfoInterface
- * @return \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\ObjectManager\ObjectManager
+ * SetUp test
*/
- protected function prepareObjectManager($priceInfoInterface)
+ public function setUp()
{
- $objectManager = $this->getMock('Magento\Framework\ObjectManager\ObjectManager', ['create'], [], '', false);
- $objectManager->expects($this->any())
- ->method('create')
- ->will($this->returnValue($this->getMockForAbstractClass($priceInfoInterface)));
- return $objectManager;
+ $this->objectManagerMock = $this->getMock(
+ 'Magento\Framework\ObjectManager\ObjectManager',
+ [],
+ [],
+ '',
+ false
+ );
+ $this->pricesMock = $this->getMock(
+ 'Magento\Framework\Pricing\Price\Collection',
+ [],
+ [],
+ '',
+ false
+ );
+ $this->saleableItemMock = $this->getMockForAbstractClass(
+ 'Magento\Framework\Pricing\Object\SaleableInterface',
+ [],
+ '',
+ false,
+ true,
+ true,
+ ['getQty']
+ );
+ $this->priceInfoMock = $this->getMockForAbstractClass(
+ 'Magento\Framework\Pricing\PriceInfoInterface',
+ [],
+ '',
+ false,
+ true,
+ true,
+ []
+ );
+ $this->types = [
+ 'default' => [
+ 'infoClass' => 'Price\PriceInfo\Default',
+ 'prices' => 'Price\Collection\Default'
+ ],
+ 'configurable' => [
+ 'infoClass' => 'Price\PriceInfo\Configurable',
+ 'prices' => 'Price\Collection\Configurable'
+ ],
+ ];
+ $this->factory = new Factory($this->types, $this->objectManagerMock);
}
- /**
- * @return array
- */
- public function priceInfoClassesProvider()
+ public function createPriceInfoDataProvider()
{
return [
[
- ['new_type' => 'Magento\Framework\Pricing\PriceInfo\Base'],
- 'new_type',
- 'Magento\Framework\Pricing\PriceInfoInterface'
+ 'simple',
+ 1,
+ 'Price\PriceInfo\Default',
+ 'Price\Collection\Default'
],
[
- [],
- 'unknown',
- 'Magento\Framework\Pricing\PriceInfoInterface'
+ 'configurable',
+ 2,
+ 'Price\PriceInfo\Configurable',
+ 'Price\Collection\Configurable'
]
];
}
/**
- * @expectedException \InvalidArgumentException
+ * @param $typeId
+ * @param $quantity
+ * @param $infoClass
+ * @param $prices
+ * @dataProvider createPriceInfoDataProvider
*/
- public function testCreateWithException()
+ public function testCreate($typeId, $quantity, $infoClass, $prices)
{
- $invalidPriceInfoInterface = 'Magento\Framework\Object';
- $priceInfoFactory = $this->preparePriceInfoFactory($invalidPriceInfoInterface);
- $priceInfoFactory->create(
- $this->getMock('Magento\Catalog\Model\Product', ['__wakeup'], [], '', false)
- );
+ $this->saleableItemMock->expects($this->once())
+ ->method('getTypeId')
+ ->will($this->returnValue($typeId));
+ $this->saleableItemMock->expects($this->once())
+ ->method('getQty')
+ ->will($this->returnValue($quantity));
+
+ $this->objectManagerMock->expects($this->exactly(2))
+ ->method('create')
+ ->will($this->returnValueMap(
+ [
+ [
+ $prices,
+ [
+ 'saleableItem' => $this->saleableItemMock,
+ 'quantity' => $quantity
+ ],
+ $this->pricesMock
+ ],
+ [
+ $infoClass,
+ [
+ 'saleableItem' => $this->saleableItemMock,
+ 'quantity' => $quantity,
+ 'prices' => $this->pricesMock
+ ],
+ $this->priceInfoMock
+ ]
+ ]
+ ));
+ $this->assertEquals($this->priceInfoMock, $this->factory->create($this->saleableItemMock, []));
}
}
diff --git a/dev/tests/unit/testsuite/Magento/Framework/Pricing/Render/AbstractAdjustmentTest.php b/dev/tests/unit/testsuite/Magento/Framework/Pricing/Render/AbstractAdjustmentTest.php
index 8d2319099a380..2ab2ea9ca0209 100644
--- a/dev/tests/unit/testsuite/Magento/Framework/Pricing/Render/AbstractAdjustmentTest.php
+++ b/dev/tests/unit/testsuite/Magento/Framework/Pricing/Render/AbstractAdjustmentTest.php
@@ -18,6 +18,9 @@
* versions in the future. If you wish to customize Magento for your
* needs please refer to http://www.magentocommerce.com for more information.
*
+ * @category Magento
+ * @package Magento_Pricing
+ * @subpackage unit_tests
* @copyright Copyright (c) 2014 X.commerce, Inc. (http://www.magentocommerce.com)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/
@@ -29,26 +32,36 @@
class AbstractAdjustmentTest extends \PHPUnit_Framework_TestCase
{
/**
- * @var Amount
+ * @var AbstractAdjustment | \PHPUnit_Framework_MockObject_MockObject
*/
protected $model;
/**
- * @var \Magento\Framework\Pricing\PriceCurrencyInterface|\PHPUnit_Framework_MockObject_MockObject
+ * @var \Magento\Framework\Pricing\PriceCurrencyInterface | \PHPUnit_Framework_MockObject_MockObject
*/
protected $priceCurrency;
+ /**
+ * @var array
+ */
+ protected $data;
+
public function setUp()
{
$this->priceCurrency = $this->getMock('Magento\Framework\Pricing\PriceCurrencyInterface');
+ $this->data = ['argument_one' => 1];
$objectManager = new \Magento\TestFramework\Helper\ObjectManager($this);
$constructorArgs = $objectManager->getConstructArguments(
'Magento\Framework\Pricing\Render\AbstractAdjustment',
- array('priceCurrency' => $this->priceCurrency)
+ array(
+ 'priceCurrency' => $this->priceCurrency,
+ 'data' => $this->data
+ )
);
$this->model = $this->getMockBuilder('Magento\Framework\Pricing\Render\AbstractAdjustment')
->setConstructorArgs($constructorArgs)
+ ->setMethods(['getData', 'setData', 'apply'])
->getMockForAbstractClass();
}
@@ -67,4 +80,122 @@ public function testConvertAndFormatCurrency()
$this->assertEquals($result, $this->model->convertAndFormatCurrency($amount, $includeContainer, $precision));
}
+
+ public function testRender()
+ {
+ $amountRender = $this->getMock('Magento\Framework\Pricing\Render\Amount', [], [], '', false);
+ $arguments = ['argument_two' => 2];
+ $mergedArguments = ['argument_one' => 1, 'argument_two' => 2];
+
+ $this->model->expects($this->at(0))
+ ->method('getData')
+ ->will($this->returnValue($this->data));
+ $this->model->expects($this->at(1))
+ ->method('setData')
+ ->with($mergedArguments);
+ $this->model->expects($this->at(2))
+ ->method('apply');
+ $this->model->expects($this->at(3))
+ ->method('setData')
+ ->with($this->data);
+
+ $this->model->render($amountRender, $arguments);
+ }
+
+ public function testGetAmountRender()
+ {
+ $amountRender = $this->getMock('Magento\Framework\Pricing\Render\Amount', [], [], '', false);
+ $this->model->expects($this->at(0))
+ ->method('getData')
+ ->will($this->returnValue($this->data));
+ $this->model->render($amountRender);
+ $this->assertEquals($amountRender, $this->model->getAmountRender());
+ }
+
+ public function testGetPriceType()
+ {
+ $amountRender = $this->getMock('Magento\Framework\Pricing\Render\Amount', [], [], '', false);
+ $price = $this->getMockForAbstractClass('Magento\Framework\Pricing\Price\PriceInterface');
+ $sealableItem = $this->getMockForAbstractClass('Magento\Framework\Pricing\Object\SaleableInterface');
+ $priceInfo = $this->getMock('Magento\Framework\Pricing\PriceInfo\Base', [], [], '', false);
+ $priceCode = 'regular_price';
+
+ $amountRender->expects($this->once())
+ ->method('getSaleableItem')
+ ->will($this->returnValue($sealableItem));
+ $sealableItem->expects($this->once())
+ ->method('getPriceInfo')
+ ->will($this->returnValue($priceInfo));
+ $priceInfo->expects($this->once())
+ ->method('getPrice')
+ ->with($priceCode)
+ ->will($this->returnValue($price));
+
+ $this->model->expects($this->at(0))
+ ->method('getData')
+ ->will($this->returnValue($this->data));
+ $this->model->render($amountRender);
+ $this->assertEquals($price, $this->model->getPriceType($priceCode));
+ }
+
+ public function testGetPrice()
+ {
+ $price = 100;
+ $amountRender = $this->getMock('Magento\Framework\Pricing\Render\Amount', [], [], '', false);
+ $amountRender->expects($this->once())
+ ->method('getPrice')
+ ->with()
+ ->will($this->returnValue($price));
+
+ $this->model->expects($this->at(0))
+ ->method('getData')
+ ->will($this->returnValue($this->data));
+ $this->model->render($amountRender);
+ $this->assertEquals($price, $this->model->getPrice());
+ }
+
+ public function testGetSealableItem()
+ {
+ $sealableItem = $this->getMockForAbstractClass('Magento\Framework\Pricing\Object\SaleableInterface');
+ $amountRender = $this->getMock('Magento\Framework\Pricing\Render\Amount', [], [], '', false);
+ $amountRender->expects($this->once())
+ ->method('getSaleableItem')
+ ->with()
+ ->will($this->returnValue($sealableItem));
+
+ $this->model->expects($this->at(0))
+ ->method('getData')
+ ->will($this->returnValue($this->data));
+ $this->model->render($amountRender);
+ $this->assertEquals($sealableItem, $this->model->getSaleableItem());
+ }
+
+ public function testGetAdjustment()
+ {
+ $amountRender = $this->getMock('Magento\Framework\Pricing\Render\Amount', [], [], '', false);
+ $adjustment = $this->getMockForAbstractClass('Magento\Framework\Pricing\Adjustment\AdjustmentInterface');
+ $sealableItem = $this->getMockForAbstractClass('Magento\Framework\Pricing\Object\SaleableInterface');
+ $priceInfo = $this->getMock('Magento\Framework\Pricing\PriceInfo\Base', [], [], '', false);
+ $adjustmentCode = 'tax';
+
+ $amountRender->expects($this->once())
+ ->method('getSaleableItem')
+ ->will($this->returnValue($sealableItem));
+ $sealableItem->expects($this->once())
+ ->method('getPriceInfo')
+ ->will($this->returnValue($priceInfo));
+ $priceInfo->expects($this->once())
+ ->method('getAdjustment')
+ ->with($adjustmentCode)
+ ->will($this->returnValue($adjustment));
+
+ $this->model->expects($this->at(0))
+ ->method('getData')
+ ->will($this->returnValue($this->data));
+ $this->model->expects($this->once())
+ ->method('getAdjustmentCode')
+ ->will($this->returnValue($adjustmentCode));
+ $this->model->render($amountRender);
+ $this->assertEquals($adjustment, $this->model->getAdjustment());
+ }
}
diff --git a/dev/tests/unit/testsuite/Magento/Framework/Pricing/Render/AmountTest.php b/dev/tests/unit/testsuite/Magento/Framework/Pricing/Render/AmountTest.php
index 949c0c05588c9..fc6ac2d63ee91 100644
--- a/dev/tests/unit/testsuite/Magento/Framework/Pricing/Render/AmountTest.php
+++ b/dev/tests/unit/testsuite/Magento/Framework/Pricing/Render/AmountTest.php
@@ -18,6 +18,9 @@
* versions in the future. If you wish to customize Magento for your
* needs please refer to http://www.magentocommerce.com for more information.
*
+ * @category Magento
+ * @package Magento_Pricing
+ * @subpackage unit_tests
* @copyright Copyright (c) 2014 X.commerce, Inc. (http://www.magentocommerce.com)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/
@@ -56,6 +59,11 @@ class AmountTest extends \PHPUnit_Framework_TestCase
*/
protected $saleableItemMock;
+ /**
+ * @var \Magento\Framework\Pricing\Amount\AmountInterface | \PHPUnit_Framework_MockObject_MockObject
+ */
+ protected $amount;
+
/**
* @var PriceInterface|\PHPUnit_Framework_MockObject_MockObject
*/
@@ -87,6 +95,9 @@ public function setUp()
);
$this->layout = $this->getMock('Magento\Framework\View\Layout', [], [], '', false);
+ $this->amount = $this->getMockForAbstractClass('Magento\Framework\Pricing\Amount\AmountInterface');
+ $this->saleableItemMock = $this->getMockForAbstractClass('Magento\Framework\Pricing\Object\SaleableInterface');
+ $this->priceMock = $this->getMockForAbstractClass('Magento\Framework\Pricing\Price\PriceInterface');
$eventManager = $this->getMock('Magento\Framework\Event\ManagerStub', [], [], '', false);
$config = $this->getMock('Magento\Store\Model\Store\Config', [], [], '', false);
@@ -112,7 +123,10 @@ public function setUp()
[
'context' => $context,
'priceCurrency' => $this->priceCurrency,
- 'rendererPool' => $this->rendererPool
+ 'rendererPool' => $this->rendererPool,
+ 'amount' => $this->amount,
+ 'saleableItem' => $this->saleableItemMock,
+ 'price' => $this->priceMock
]
);
}
@@ -133,16 +147,116 @@ public function testConvertAndFormatCurrency()
$this->assertEquals($result, $this->model->convertAndFormatCurrency($amount, $includeContainer, $precision));
}
+ /**
+ * Test case for getAdjustmentRenders method through toHtml()
+ */
+ public function testToHtmlSkipAdjustments()
+ {
+ $this->model->setData('skip_adjustments', true);
+ $this->rendererPool->expects($this->never())
+ ->method('getAdjustmentRenders');
+
+ $this->model->toHtml();
+ }
+
/**
* Test case for getAdjustmentRenders method through toHtml()
*/
public function testToHtmlGetAdjustmentRenders()
{
- $adjustmentRender = [];
+ $data = ['key1' => 'data1', 'css_classes' => 'class1 class2'];
+ $expectedData = [
+ 'key1' => 'data1',
+ 'css_classes' => 'class1 class2',
+ 'module_name' => null,
+ 'adjustment_css_classes' => 'class1 class2 render1 render2'
+ ];
+
+ $this->model->setData($data);
+
+ $adjustmentRender1 = $this->getAdjustmentRenderMock($expectedData);
+ $adjustmentRender2 = $this->getAdjustmentRenderMock($expectedData);
+ $adjustmentRenders = ['render1' => $adjustmentRender1, 'render2' => $adjustmentRender2];
+ $this->rendererPool->expects($this->once())
+ ->method('getAdjustmentRenders')
+ ->will($this->returnValue($adjustmentRenders));
+
+ $this->model->toHtml();
+ }
+
+ public function testGetDisplayValueExiting()
+ {
+ $displayValue = 5.99;
+ $this->model->setDisplayValue($displayValue);
+ $this->assertEquals($displayValue, $this->model->getDisplayValue());
+ }
+
+ public function testGetDisplayValue()
+ {
+ $amountValue = 100.99;
+ $this->amount->expects($this->once())
+ ->method('getValue')
+ ->will($this->returnValue($amountValue));
+ $this->assertEquals($amountValue, $this->model->getDisplayValue());
+ }
+
+ public function testGetAmount()
+ {
+ $this->assertEquals($this->amount, $this->model->getAmount());
+ }
+
+ public function testGetSealableItem()
+ {
+ $this->assertEquals($this->saleableItemMock, $this->model->getSaleableItem());
+ }
+
+ public function testGetPrice()
+ {
+ $this->assertEquals($this->priceMock, $this->model->getPrice());
+ }
+
+ public function testAdjustmentsHtml()
+ {
+ $adjustmentHtml1 = 'adjustment_1_html';
+ $adjustmentHtml2 = 'adjustment_2_html';
+ $data = ['key1' => 'data1', 'css_classes' => 'class1 class2'];
+ $expectedData = [
+ 'key1' => 'data1',
+ 'css_classes' => 'class1 class2',
+ 'module_name' => null,
+ 'adjustment_css_classes' => 'class1 class2 render1 render2'
+ ];
+
+ $this->model->setData($data);
+
+ $this->assertFalse($this->model->hasAdjustmentsHtml());
+
+ $adjustmentRender1 = $this->getAdjustmentRenderMock($expectedData, $adjustmentHtml1, 'adjustment_code1');
+ $adjustmentRender2 = $this->getAdjustmentRenderMock($expectedData, $adjustmentHtml2, 'adjustment_code2');
+ $adjustmentRenders = ['render1' => $adjustmentRender1, 'render2' => $adjustmentRender2];
$this->rendererPool->expects($this->once())
->method('getAdjustmentRenders')
- ->will($this->returnValue($adjustmentRender));
+ ->will($this->returnValue($adjustmentRenders));
$this->model->toHtml();
+
+ $this->assertTrue($this->model->hasAdjustmentsHtml());
+
+ $this->assertEquals($adjustmentHtml1 . $adjustmentHtml2, $this->model->getAdjustmentsHtml());
+ }
+
+ protected function getAdjustmentRenderMock($data = [], $html = '', $code = 'adjustment_code')
+ {
+ $adjustmentRender = $this->getMockForAbstractClass(
+ 'Magento\Framework\Pricing\Render\AdjustmentRenderInterface'
+ );
+ $adjustmentRender->expects($this->once())
+ ->method('render')
+ ->with($this->model, $data)
+ ->will($this->returnValue($html));
+ $adjustmentRender->expects($this->any())
+ ->method('getAdjustmentCode')
+ ->will($this->returnValue($code));
+ return $adjustmentRender;
}
}
diff --git a/dev/tests/unit/testsuite/Magento/Framework/Pricing/Render/LayoutTest.php b/dev/tests/unit/testsuite/Magento/Framework/Pricing/Render/LayoutTest.php
index f209c01f15918..4174071558f4f 100644
--- a/dev/tests/unit/testsuite/Magento/Framework/Pricing/Render/LayoutTest.php
+++ b/dev/tests/unit/testsuite/Magento/Framework/Pricing/Render/LayoutTest.php
@@ -18,6 +18,9 @@
* versions in the future. If you wish to customize Magento for your
* needs please refer to http://www.magentocommerce.com for more information.
*
+ * @category Magento
+ * @package Magento_Pricing
+ * @subpackage unit_tests
* @copyright Copyright (c) 2014 X.commerce, Inc. (http://www.magentocommerce.com)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/
diff --git a/dev/tests/unit/testsuite/Magento/Framework/Pricing/Render/PriceBoxTest.php b/dev/tests/unit/testsuite/Magento/Framework/Pricing/Render/PriceBoxTest.php
index 0a5371a40a862..b754207575375 100644
--- a/dev/tests/unit/testsuite/Magento/Framework/Pricing/Render/PriceBoxTest.php
+++ b/dev/tests/unit/testsuite/Magento/Framework/Pricing/Render/PriceBoxTest.php
@@ -18,6 +18,9 @@
* versions in the future. If you wish to customize Magento for your
* needs please refer to http://www.magentocommerce.com for more information.
*
+ * @category Magento
+ * @package Magento_Pricing
+ * @subpackage unit_tests
* @copyright Copyright (c) 2014 X.commerce, Inc. (http://www.magentocommerce.com)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/
@@ -103,15 +106,15 @@ public function setUp()
/**
* @param array $data
- * @param string $priceType
+ * @param string $priceCode
* @param array $cssClasses
* @dataProvider toHtmlDataProvider
*/
- public function testToHtml($data, $priceType, $cssClasses)
+ public function testToHtml($data, $priceCode, $cssClasses)
{
$this->price->expects($this->once())
- ->method('getPriceType')
- ->will($this->returnValue($priceType));
+ ->method('getPriceCode')
+ ->will($this->returnValue($priceCode));
$priceBox = $this->objectManager->getObject('Magento\Framework\Pricing\Render\PriceBox', array(
'context' => $this->context,
@@ -129,12 +132,12 @@ public function toHtmlDataProvider()
return array(
array(
'data' => [],
- 'price_type' => 'test_price',
+ 'price_code' => 'test_price',
'css_classes' => 'price-test_price'
),
array(
'data' => ['css_classes' => 'some_css_class'],
- 'price_type' => 'test_price',
+ 'price_code' => 'test_price',
'css_classes' => 'some_css_class price-test_price'
));
}
@@ -152,21 +155,20 @@ public function testGetPrice()
public function testGetPriceType()
{
$priceCode = 'test_price';
- $quantity = 1.;
$price = $this->getMock('Magento\Framework\Pricing\Price\PriceInterface');
$priceInfo = $this->getMock('Magento\Framework\Pricing\PriceInfoInterface');
$priceInfo->expects($this->once())
->method('getPrice')
- ->with($priceCode, $quantity)
+ ->with($priceCode)
->will($this->returnValue($price));
$this->saleable->expects($this->once())
->method('getPriceInfo')
->will($this->returnValue($priceInfo));
- $this->assertEquals($price, $this->model->getPriceType($priceCode, $quantity));
+ $this->assertEquals($price, $this->model->getPriceType($priceCode));
}
public function testRenderAmount()
@@ -190,4 +192,59 @@ public function testRenderAmount()
$this->assertEquals($resultHtml, $this->model->renderAmount($amount, $arguments));
}
+
+ public function testGetPriceIdHasDataPriceId()
+ {
+ $priceId = 'data_price_id';
+ $this->model->setData('price_id', $priceId);
+ $this->assertEquals($priceId, $this->model->getPriceId());
+ }
+
+ /**
+ * @dataProvider getPriceIdProvider
+ * @param string $prefix
+ * @param string $suffix
+ * @param string $defaultPrefix
+ * @param string $defaultSuffix
+ */
+ public function testGetPriceId($prefix, $suffix, $defaultPrefix, $defaultSuffix)
+ {
+ $priceId = 'price_id';
+ $this->saleable->expects($this->once())
+ ->method('getId')
+ ->will($this->returnValue($priceId));
+
+ if (!empty($prefix)) {
+ $this->model->setData('price_id_prefix', $prefix);
+ $expectedPriceId = $prefix . $priceId;
+ } else {
+ $expectedPriceId = $defaultPrefix . $priceId;
+ }
+ if (!empty($suffix)) {
+ $this->model->setData('price_id_suffix', $suffix);
+ $expectedPriceId = $expectedPriceId . $suffix;
+ } else {
+ $expectedPriceId = $expectedPriceId . $defaultSuffix;
+ }
+
+ $this->assertEquals($expectedPriceId, $this->model->getPriceId($defaultPrefix, $defaultSuffix));
+ }
+
+ public function getPriceIdProvider()
+ {
+ return [
+ ['prefix', 'suffix', 'default_prefix', 'default_suffix'],
+ ['prefix', 'suffix', 'default_prefix', ''],
+ ['prefix', 'suffix', '', 'default_suffix'],
+ ['prefix', '', 'default_prefix', 'default_suffix'],
+ ['', 'suffix', 'default_prefix', 'default_suffix'],
+ ['', '', 'default_prefix', 'default_suffix'],
+ ['prefix', 'suffix', '', '']
+ ];
+ }
+
+ public function testGetRendererPool()
+ {
+ $this->assertEquals($this->rendererPool, $this->model->getRendererPool());
+ }
}
diff --git a/dev/tests/unit/testsuite/Magento/Framework/Pricing/Render/RendererPoolTest.php b/dev/tests/unit/testsuite/Magento/Framework/Pricing/Render/RendererPoolTest.php
index e066f510368a1..5d584727f4909 100644
--- a/dev/tests/unit/testsuite/Magento/Framework/Pricing/Render/RendererPoolTest.php
+++ b/dev/tests/unit/testsuite/Magento/Framework/Pricing/Render/RendererPoolTest.php
@@ -18,6 +18,9 @@
* versions in the future. If you wish to customize Magento for your
* needs please refer to http://www.magentocommerce.com for more information.
*
+ * @category Magento
+ * @package Magento_Pricing
+ * @subpackage unit_tests
* @copyright Copyright (c) 2014 X.commerce, Inc. (http://www.magentocommerce.com)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/
@@ -273,7 +276,7 @@ public function testCreateAmountRenderNoAmountClass()
->method('getTypeId')
->will($this->returnValue($type));
$this->priceMock->expects($this->once())
- ->method('getPriceType')
+ ->method('getPriceCode')
->will($this->returnValue($priceCode));
$testedClass = $this->createTestedEntity($data);
@@ -311,7 +314,7 @@ public function testCreateAmountRenderNotAmountInterface()
->method('getTypeId')
->will($this->returnValue($type));
$this->priceMock->expects($this->once())
- ->method('getPriceType')
+ ->method('getPriceCode')
->will($this->returnValue($priceCode));
$contextMock = $this->getMockBuilder('Magento\Framework\View\Element\Template\Context')
@@ -366,7 +369,7 @@ public function testCreateAmountRender()
->method('getTypeId')
->will($this->returnValue($type));
$this->priceMock->expects($this->once())
- ->method('getPriceType')
+ ->method('getPriceCode')
->will($this->returnValue($priceCode));
$blockMock = $this->getMockBuilder('Magento\Framework\Pricing\Render\Amount')
@@ -407,7 +410,7 @@ public function testGetAdjustmentRendersNoRenderClass()
->method('getTypeId')
->will($this->returnValue($typeId));
$this->priceMock->expects($this->once())
- ->method('getPriceType')
+ ->method('getPriceCode')
->will($this->returnValue($priceCode));
$code = 'test_code';
@@ -433,7 +436,7 @@ public function testGetAdjustmentRendersNoRenderTemplate()
->method('getTypeId')
->will($this->returnValue($typeId));
$this->priceMock->expects($this->once())
- ->method('getPriceType')
+ ->method('getPriceCode')
->will($this->returnValue($priceCode));
$code = 'test_code';
@@ -482,7 +485,7 @@ public function testGetAdjustmentRenders()
->method('getTypeId')
->will($this->returnValue($typeId));
$this->priceMock->expects($this->once())
- ->method('getPriceType')
+ ->method('getPriceCode')
->will($this->returnValue($priceCode));
$blockMock = $this->getMockBuilder('Magento\Framework\View\Element\Template')
@@ -535,7 +538,7 @@ public function testGetAmountRenderBlockTemplateNoTemplate()
->method('getTypeId')
->will($this->returnValue($type));
$this->priceMock->expects($this->once())
- ->method('getPriceType')
+ ->method('getPriceCode')
->will($this->returnValue($priceCode));
$blockMock = $this->getMockBuilder('Magento\Framework\Pricing\Render\Amount')
diff --git a/dev/tests/unit/testsuite/Magento/Framework/Pricing/RenderTest.php b/dev/tests/unit/testsuite/Magento/Framework/Pricing/RenderTest.php
index 5bcae14ab0b03..49f234f22efa9 100644
--- a/dev/tests/unit/testsuite/Magento/Framework/Pricing/RenderTest.php
+++ b/dev/tests/unit/testsuite/Magento/Framework/Pricing/RenderTest.php
@@ -18,6 +18,9 @@
* versions in the future. If you wish to customize Magento for your
* needs please refer to http://www.magentocommerce.com for more information.
*
+ * @category Magento
+ * @package Magento_Pricing
+ * @subpackage unit_tests
* @copyright Copyright (c) 2014 X.commerce, Inc. (http://www.magentocommerce.com)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/
@@ -218,4 +221,18 @@ public function testAmountRender()
$result = $this->model->renderAmount($this->amount, $this->price, $this->saleableItem, $arguments);
$this->assertEquals($expectedResult, $result);
}
+
+ /**
+ * @expectedException \RuntimeException
+ * @expectedExceptionMessage Wrong Price Rendering layout configuration. Factory block is missed
+ */
+ public function testAmountRenderNoRenderPool()
+ {
+ $this->priceLayout->expects($this->once())
+ ->method('getBlock')
+ ->with('render.product.prices')
+ ->will($this->returnValue(false));
+
+ $this->model->renderAmount($this->amount, $this->price, $this->saleableItem);
+ }
}
diff --git a/dev/tests/unit/testsuite/Magento/Framework/ProfilerTest.php b/dev/tests/unit/testsuite/Magento/Framework/ProfilerTest.php
index c3f65d50af350..e965ede1037c7 100644
--- a/dev/tests/unit/testsuite/Magento/Framework/ProfilerTest.php
+++ b/dev/tests/unit/testsuite/Magento/Framework/ProfilerTest.php
@@ -217,7 +217,7 @@ public function testTags()
public function testClearTimer()
{
$driver = $this->_getDriverMock();
- $driver->expects($this->once())->method('clear')->with('timer');
+ $driver->expects($this->at(0))->method('clear')->with('timer');
\Magento\Framework\Profiler::add($driver);
\Magento\Framework\Profiler::clear('timer');
diff --git a/dev/tests/unit/testsuite/Magento/Framework/View/Design/Fallback/FactoryTest.php b/dev/tests/unit/testsuite/Magento/Framework/View/Design/Fallback/FactoryTest.php
index e4a76de7c7cd1..6d82b49df06c1 100644
--- a/dev/tests/unit/testsuite/Magento/Framework/View/Design/Fallback/FactoryTest.php
+++ b/dev/tests/unit/testsuite/Magento/Framework/View/Design/Fallback/FactoryTest.php
@@ -161,7 +161,8 @@ public function createFileRuleGetPatternDirsDataProvider()
array(
'/area/current_theme_path/namespace_module',
'/area/parent_theme_path/namespace_module',
- '/namespace/module/view/area'
+ '/namespace/module/view/area',
+ '/namespace/module/view/base'
)
),
'non-modular' => array(
@@ -214,7 +215,8 @@ public function createViewFileRuleGetPatternDirsDataProvider()
'/area/parent_theme_path/i18n/en_US/namespace_module',
'/area/parent_theme_path/namespace_module',
'/namespace/module/view/area/i18n/en_US',
- '/namespace/module/view/area'
+ '/namespace/module/view/area',
+ '/namespace/module/view/base'
)
),
'modular non-localized' => array(
@@ -222,7 +224,8 @@ public function createViewFileRuleGetPatternDirsDataProvider()
array(
'/area/current_theme_path/namespace_module',
'/area/parent_theme_path/namespace_module',
- '/namespace/module/view/area'
+ '/namespace/module/view/area',
+ '/namespace/module/view/base'
)
),
'non-modular localized' => array(
diff --git a/dev/tests/unit/testsuite/Magento/Framework/View/Design/FileResolution/Strategy/Fallback/CachingProxyTest.php b/dev/tests/unit/testsuite/Magento/Framework/View/Design/FileResolution/Strategy/Fallback/CachingProxyTest.php
index b3a532f370f01..372c5b1c378db 100644
--- a/dev/tests/unit/testsuite/Magento/Framework/View/Design/FileResolution/Strategy/Fallback/CachingProxyTest.php
+++ b/dev/tests/unit/testsuite/Magento/Framework/View/Design/FileResolution/Strategy/Fallback/CachingProxyTest.php
@@ -87,7 +87,7 @@ protected function setUp()
false
);
- $this->themeModel = \PHPUnit_Framework_MockObject_Generator::getMock(
+ $this->themeModel = $this->getMock(
'Magento\Core\Model\Theme',
array(),
array(),
@@ -206,9 +206,9 @@ public function testProxyMethods($method, $params, $expectedResult)
*
* @return array
*/
- public static function proxyMethodsDataProvider()
+ public function proxyMethodsDataProvider()
{
- $themeModel = \PHPUnit_Framework_MockObject_Generator::getMock(
+ $themeModel = $this->getMock(
'Magento\Core\Model\Theme',
array(),
array(),
diff --git a/dev/tests/unit/testsuite/Magento/Framework/View/Layout/File/FactoryTest.php b/dev/tests/unit/testsuite/Magento/Framework/View/Layout/File/FactoryTest.php
index 873f336384ebd..ce8e6177f68f8 100644
--- a/dev/tests/unit/testsuite/Magento/Framework/View/Layout/File/FactoryTest.php
+++ b/dev/tests/unit/testsuite/Magento/Framework/View/Layout/File/FactoryTest.php
@@ -45,16 +45,21 @@ public function testCreate()
{
$theme = $this->getMockForAbstractClass('Magento\Framework\View\Design\ThemeInterface');
$file = new \Magento\Framework\View\Layout\File(__FILE__, 'Fixture_Module', $theme);
- $this->_objectManager->expects(
- $this->once()
- )->method(
- 'create'
- )->with(
- 'Magento\Framework\View\Layout\File',
- $this->identicalTo(array('filename' => __FILE__, 'module' => 'Fixture_Module', 'theme' => $theme))
- )->will(
- $this->returnValue($file)
- );
- $this->assertSame($file, $this->_model->create(__FILE__, 'Fixture_Module', $theme));
+ $isBase = true;
+ $this->_objectManager->expects($this->once())
+ ->method('create')
+ ->with(
+ 'Magento\Framework\View\Layout\File',
+ $this->identicalTo(
+ array(
+ 'filename' => __FILE__,
+ 'module' => 'Fixture_Module',
+ 'theme' => $theme,
+ 'isBase' => $isBase
+ )
+ )
+ )
+ ->will($this->returnValue($file));
+ $this->assertSame($file, $this->_model->create(__FILE__, 'Fixture_Module', $theme, $isBase));
}
}
diff --git a/dev/tests/unit/testsuite/Magento/Framework/View/Layout/File/Source/BaseTest.php b/dev/tests/unit/testsuite/Magento/Framework/View/Layout/File/Source/BaseTest.php
index 070735b2fdc3d..2857d02078d86 100644
--- a/dev/tests/unit/testsuite/Magento/Framework/View/Layout/File/Source/BaseTest.php
+++ b/dev/tests/unit/testsuite/Magento/Framework/View/Layout/File/Source/BaseTest.php
@@ -21,107 +21,111 @@
* @copyright Copyright (c) 2014 X.commerce, Inc. (http://www.magentocommerce.com)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/
-namespace Magento\Framework\View\Layout\File\Source;
-use Magento\Framework\Filesystem\Directory\Read;
-use Magento\Framework\View\Layout\File\Factory;
+namespace Magento\Framework\View\Layout\File\Source;
+/**
+ * Class for testing Magento\View\Layout\File\Source\Base
+ */
class BaseTest extends \PHPUnit_Framework_TestCase
{
/**
- * @var Base
+ * @var \Magento\Framework\View\Layout\File\Source\Base|\PHPUnit_Framework_MockObject_MockObject
*/
- private $model;
+ protected $class;
/**
- * @var Read | \PHPUnit_Framework_MockObject_MockObject
+ * @var \Magento\Framework\Filesystem\Directory\ReadInterface|\PHPUnit_Framework_MockObject_MockObject
*/
- private $directory;
+ protected $modulesDirectoryMock;
/**
- * @var Factory | \PHPUnit_Framework_MockObject_MockObject
+ * @var \Magento\Framework\View\Layout\File\Factory|\PHPUnit_Framework_MockObject_MockObject
*/
- private $fileFactory;
+ protected $fileFactoryMock;
- protected function setUp()
+ /**
+ * Set up mocks
+ */
+ public function setUp()
{
- $this->directory = $this->getMock('Magento\Framework\Filesystem\Directory\Read', array(), array(), '', false);
- $filesystem = $this->getMock(
+ $filesystemMock = $this->getMock(
'Magento\Framework\App\Filesystem',
- array('getDirectoryRead', '__wakeup'),
- array(),
+ ['getDirectoryRead', 'getAbsolutePath'],
+ [],
'',
false
);
- $filesystem->expects(
- $this->once()
- )->method(
- 'getDirectoryRead'
- )->with(
- \Magento\Framework\App\Filesystem::MODULES_DIR
- )->will(
- $this->returnValue($this->directory)
+ $this->fileFactoryMock = $this->getMock('Magento\Framework\View\Layout\File\Factory', [], [], '', false);
+ $this->modulesDirectoryMock = $this->getMock(
+ 'Magento\Framework\Filesystem\Directory\ReadInterface',
+ [],
+ [],
+ '',
+ false
);
- $this->fileFactory = $this->getMock('Magento\Framework\View\Layout\File\Factory', array(), array(), '', false);
- $this->model = new Base($filesystem, $this->fileFactory);
+ $filesystemMock->expects($this->once())
+ ->method('getDirectoryRead')
+ ->will($this->returnValue($this->modulesDirectoryMock));
+
+ $objectManager = new \Magento\TestFramework\Helper\ObjectManager($this);
+ $this->class = $objectManager->getObject(
+ 'Magento\Framework\View\Layout\File\Source\Base',
+ [
+ 'filesystem' => $filesystemMock,
+ 'fileFactory' => $this->fileFactoryMock
+ ]
+ );
}
/**
- * @param array $files
- * @param string $filePath
- *
- * @dataProvider dataProvider
+ * Test for method getFiles
*/
- public function testGetFiles($files, $filePath)
+ public function testGetFiles()
{
- $theme = $this->getMockForAbstractClass('Magento\Framework\View\Design\ThemeInterface');
- $theme->expects($this->once())->method('getArea')->will($this->returnValue('area'));
+ $fileName = 'somefile.xml';
+ $fileRightPath = '/namespace/module/view/base/layout/' . $fileName;
+ $themeFileRightPath = '/namespace/module/view/area_code/layout/' . $fileName;
+ $fileWrongPath = '/namespace/module/view/' . $fileName;
+ $themeFileWrongPath = '/namespace/module/view/area_code/' . $fileName;
+ $areaCode = 'area_code';
+ $sharedFiles = [
+ $fileRightPath,
+ $fileWrongPath,
+ ];
+ $themeFiles = [
+ $themeFileRightPath,
+ $themeFileWrongPath,
+ ];
+ $themeMock = $this->getMock('Magento\Framework\View\Design\ThemeInterface', [], [], '', false);
- $handlePath = 'code/Module/%s/view/area/layout/%s.xml';
- $returnKeys = array();
- foreach ($files as $file) {
- $returnKeys[] = sprintf($handlePath, $file['module'], $file['handle']);
- }
+ $this->modulesDirectoryMock->expects($this->any())
+ ->method('search')
+ ->will($this->returnValueMap(
+ [
+ ["*/*/view/base/layout/*.xml", null, $sharedFiles],
+ ["*/*/view/$areaCode/layout/*.xml", null, $themeFiles],
+ ]
+ ));
+ $this->modulesDirectoryMock->expects($this->any())
+ ->method('getAbsolutePath')
+ ->will($this->returnArgument(0));
+ $themeMock->expects($this->once())
+ ->method('getArea')
+ ->will($this->returnValue($areaCode));
- $this->directory->expects($this->once())->method('search')->will($this->returnValue($returnKeys));
- $this->directory->expects($this->any())->method('getAbsolutePath')->will($this->returnArgument(0));
+ $this->fileFactoryMock->expects($this->at(0))
+ ->method('create')
+ ->with($this->equalTo($fileRightPath), $this->equalTo('namespace_module'))
+ ->will($this->returnValue($fileRightPath));
+ $this->fileFactoryMock->expects($this->at(1))
+ ->method('create')
+ ->with($this->equalTo($themeFileRightPath), $this->equalTo('namespace_module'))
+ ->will($this->returnValue($themeFileRightPath));
- $checkResult = array();
- foreach ($files as $key => $file) {
- $moduleName = 'Module_' . $file['module'];
- $checkResult[$key] = new \Magento\Framework\View\Layout\File($file['handle'] . '.xml', $moduleName, $theme);
-
- $this->fileFactory->expects(
- $this->at($key)
- )->method(
- 'create'
- )->with(
- sprintf($handlePath, $file['module'], $file['handle']),
- $moduleName
- )->will(
- $this->returnValue($checkResult[$key])
- );
- }
-
- $this->assertSame($checkResult, $this->model->getFiles($theme, $filePath));
- }
-
- /**
- * @return array
- */
- public function dataProvider()
- {
- return array(
- array(
- array(
- array('handle' => '1', 'module' => 'One'),
- array('handle' => '2', 'module' => 'One'),
- array('handle' => '3', 'module' => 'Two')
- ),
- '*'
- ),
- array(array(array('handle' => 'preset/4', 'module' => 'Four')), 'preset/4')
- );
+ $expected = [$fileRightPath, $themeFileRightPath];
+ $result = $this->class->getFiles($themeMock);
+ $this->assertEquals($expected, $result);
}
}
diff --git a/dev/tests/unit/testsuite/Magento/Framework/View/Layout/File/Source/Override/BaseTest.php b/dev/tests/unit/testsuite/Magento/Framework/View/Layout/File/Source/Override/BaseTest.php
index da3be7dd3ed42..f1bb3872e3610 100644
--- a/dev/tests/unit/testsuite/Magento/Framework/View/Layout/File/Source/Override/BaseTest.php
+++ b/dev/tests/unit/testsuite/Magento/Framework/View/Layout/File/Source/Override/BaseTest.php
@@ -89,16 +89,10 @@ public function testGetFiles($files, $filePath)
$checkResult = array();
foreach ($files as $key => $file) {
$checkResult[$key] = new \Magento\Framework\View\Layout\File($file['handle'] . '.xml', $file['module']);
- $this->fileFactory->expects(
- $this->at($key)
- )->method(
- 'create'
- )->with(
- sprintf($handlePath, $file['module'], $file['handle']),
- $file['module']
- )->will(
- $this->returnValue($checkResult[$key])
- );
+ $this->fileFactory->expects($this->at($key))
+ ->method('create')
+ ->with(sprintf($handlePath, $file['module'], $file['handle']), $file['module'])
+ ->will($this->returnValue($checkResult[$key]));
}
$this->assertSame($checkResult, $this->model->getFiles($theme, $filePath));
diff --git a/dev/tests/unit/testsuite/Magento/Framework/View/Layout/File/Source/Override/ThemeTest.php b/dev/tests/unit/testsuite/Magento/Framework/View/Layout/File/Source/Override/ThemeTest.php
index e43c5e86708d4..660b29e300724 100644
--- a/dev/tests/unit/testsuite/Magento/Framework/View/Layout/File/Source/Override/ThemeTest.php
+++ b/dev/tests/unit/testsuite/Magento/Framework/View/Layout/File/Source/Override/ThemeTest.php
@@ -86,18 +86,16 @@ public function testGetFiles()
$fileOne = new \Magento\Framework\View\Layout\File('1.xml', 'Module_One', $parentTheme);
$fileTwo = new \Magento\Framework\View\Layout\File('2.xml', 'Module_Two', $grandparentTheme);
- $this->_fileFactory->expects(
- $this->exactly(2)
- )->method(
- 'create'
- )->will(
- $this->returnValueMap(
- array(
- array($filePathOne, 'Module_One', $parentTheme, $fileOne),
- array($filePathTwo, 'Module_Two', $grandparentTheme, $fileTwo)
+ $this->_fileFactory->expects($this->exactly(2))
+ ->method('create')
+ ->will(
+ $this->returnValueMap(
+ array(
+ array($filePathOne, 'Module_One', $parentTheme, false, $fileOne),
+ array($filePathTwo, 'Module_Two', $grandparentTheme, false, $fileTwo)
+ )
)
- )
- );
+ );
$this->assertSame(array($fileOne, $fileTwo), $this->_model->getFiles($theme));
}
diff --git a/dev/tests/unit/testsuite/Magento/Framework/View/Layout/FileTest.php b/dev/tests/unit/testsuite/Magento/Framework/View/Layout/FileTest.php
index 008f9a4f389e7..88ff925e86358 100644
--- a/dev/tests/unit/testsuite/Magento/Framework/View/Layout/FileTest.php
+++ b/dev/tests/unit/testsuite/Magento/Framework/View/Layout/FileTest.php
@@ -38,7 +38,7 @@ class FileTest extends \PHPUnit_Framework_TestCase
protected function setUp()
{
$this->_theme = $this->getMockForAbstractClass('Magento\Framework\View\Design\ThemeInterface');
- $this->_model = new \Magento\Framework\View\Layout\File(__FILE__, 'Fixture_TestModule', $this->_theme);
+ $this->_model = new \Magento\Framework\View\Layout\File(__FILE__, 'Fixture_TestModule', $this->_theme, true);
}
public function testGetFilename()
@@ -65,7 +65,7 @@ public function testGetFileIdentifier()
{
$this->_theme->expects($this->once())->method('getFullPath')->will($this->returnValue('theme_name'));
$this->assertSame(
- 'theme:theme_name|module:Fixture_TestModule|file:FileTest.php',
+ 'base|theme:theme_name|module:Fixture_TestModule|file:FileTest.php',
$this->_model->getFileIdentifier()
);
}
diff --git a/dev/tests/unit/testsuite/Magento/Framework/View/UrlTest.php b/dev/tests/unit/testsuite/Magento/Framework/View/UrlTest.php
index afab68b1f2336..94d43aa651729 100644
--- a/dev/tests/unit/testsuite/Magento/Framework/View/UrlTest.php
+++ b/dev/tests/unit/testsuite/Magento/Framework/View/UrlTest.php
@@ -119,9 +119,9 @@ public function testGetViewFileUrlProductionMode($themeModel)
/**
* @return array
*/
- public static function getViewFileUrlProductionModeDataProvider()
+ public function getViewFileUrlProductionModeDataProvider()
{
- $usualTheme = \PHPUnit_Framework_MockObject_Generator::getMock(
+ $usualTheme = $this->getMock(
'Magento\Framework\View\Design\ThemeInterface',
array(),
array(),
diff --git a/dev/tests/unit/testsuite/Magento/GoogleAdwords/Model/Config/Source/LanguageTest.php b/dev/tests/unit/testsuite/Magento/GoogleAdwords/Model/Config/Source/LanguageTest.php
deleted file mode 100644
index fb03364a428cc..0000000000000
--- a/dev/tests/unit/testsuite/Magento/GoogleAdwords/Model/Config/Source/LanguageTest.php
+++ /dev/null
@@ -1,190 +0,0 @@
-_helperMock = $this->getMock('Magento\GoogleAdwords\Helper\Data', array(), array(), '', false);
- $this->_localeMock = $this->getMock('Zend_Locale', array(), array(), '', false);
- $this->_localeModelMock = $this->getMock(
- 'Magento\Framework\Locale\ResolverInterface',
- array(),
- array(),
- '',
- false
- );
- $this->_localeModelMock->expects(
- $this->once()
- )->method(
- 'getLocale'
- )->will(
- $this->returnValue($this->_localeMock)
- );
- $this->_uppercaseFilterMock = $this->getMock(
- 'Magento\GoogleAdwords\Model\Filter\UppercaseTitle',
- array(),
- array(),
- '',
- false
- );
-
- $objectManager = new \Magento\TestFramework\Helper\ObjectManager($this);
- $this->_model = $objectManager->getObject(
- 'Magento\GoogleAdwords\Model\Config\Source\Language',
- array(
- 'localeResolver' => $this->_localeModelMock,
- 'helper' => $this->_helperMock,
- 'uppercaseFilter' => $this->_uppercaseFilterMock
- )
- );
- }
-
- public function testToOptionArray()
- {
- $languageCodes = array('languageCode1', 'languageCode2');
- $langToLocalesMap = array('languageCode1' => 'localeCode1', 'languageCode2' => 'localeCode2');
- $expectedLanguages = array(
- array(
- 'value' => 'languageCode1',
- 'label' => 'TranslationForSpecifiedLanguage1 / translationForDefaultLanguage1 (languageCode1)'
- ),
- array(
- 'value' => 'languageCode2',
- 'label' => 'TranslationForSpecifiedLanguage2 / translationForDefaultLanguage2 (languageCode2)'
- )
- );
-
- $this->_helperMock->expects(
- $this->once()
- )->method(
- 'getLanguageCodes'
- )->will(
- $this->returnValue($languageCodes)
- );
- $this->_helperMock->expects($this->atLeastOnce())->method('convertLanguageCodeToLocaleCode')->will(
- $this->returnCallback(
- function ($languageCode) use ($langToLocalesMap) {
- return $langToLocalesMap[$languageCode];
- }
- )
- );
-
- $localeMock = $this->_localeMock;
- $localeMock::staticExpects(
- $this->at(0)
- )->method(
- 'getTranslation'
- )->with(
- 'localeCode1',
- 'language',
- 'languageCode1'
- )->will(
- $this->returnValue('translationForSpecifiedLanguage1')
- );
-
- $localeMock::staticExpects(
- $this->at(1)
- )->method(
- 'getTranslation'
- )->with(
- 'localeCode1',
- 'language'
- )->will(
- $this->returnValue('translationForDefaultLanguage1')
- );
-
- $localeMock::staticExpects(
- $this->at(2)
- )->method(
- 'getTranslation'
- )->with(
- 'localeCode2',
- 'language',
- 'languageCode2'
- )->will(
- $this->returnValue('translationForSpecifiedLanguage2')
- );
-
- $localeMock::staticExpects(
- $this->at(3)
- )->method(
- 'getTranslation'
- )->with(
- 'localeCode2',
- 'language'
- )->will(
- $this->returnValue('translationForDefaultLanguage2')
- );
-
- $this->_uppercaseFilterMock->expects(
- $this->at(0)
- )->method(
- 'filter'
- )->with(
- 'translationForSpecifiedLanguage1'
- )->will(
- $this->returnValue('TranslationForSpecifiedLanguage1')
- );
-
- $this->_uppercaseFilterMock->expects(
- $this->at(1)
- )->method(
- 'filter'
- )->with(
- 'translationForSpecifiedLanguage2'
- )->will(
- $this->returnValue('TranslationForSpecifiedLanguage2')
- );
-
- $this->assertEquals($expectedLanguages, $this->_model->toOptionArray());
- }
-}
diff --git a/dev/tests/unit/testsuite/Magento/GroupedProduct/Block/Product/View/Type/GroupedTest.php b/dev/tests/unit/testsuite/Magento/GroupedProduct/Block/Product/View/Type/GroupedTest.php
index 34f79e375a1c5..9beb7e0ff88bc 100644
--- a/dev/tests/unit/testsuite/Magento/GroupedProduct/Block/Product/View/Type/GroupedTest.php
+++ b/dev/tests/unit/testsuite/Magento/GroupedProduct/Block/Product/View/Type/GroupedTest.php
@@ -45,16 +45,6 @@ class GroupedTest extends \PHPUnit_Framework_TestCase
*/
protected $configuredValueMock;
- /**
- * @var \PHPUnit_Framework_MockObject_MockObject
- */
- protected $blockMock;
-
- /**
- * @var string
- */
- protected $defaultTemplate = 'product/view/tierprices.phtml';
-
protected function setUp()
{
$helper = new \Magento\TestFramework\Helper\ObjectManager($this);
@@ -88,23 +78,11 @@ protected function setUp()
'',
false
);
- // mocks for getTierPriceHtml method
- $methods = array(
- 'setTemplate',
- 'setProduct',
- 'setListClass',
- 'setShowDetailedPrice',
- 'setCanDisplayQty',
- 'toHtml'
- );
- $this->blockMock = $this->getMock('Magento\Catalog\Block\Product\Price', $methods, array(), '', false);
$layout = $this->getMock('Magento\Framework\View\LayoutInterface');
- $layout->expects($this->any())->method('createBlock')->will($this->returnValue($this->blockMock));
$this->groupedView = $helper->getObject(
'Magento\GroupedProduct\Block\Product\View\Type\Grouped',
array(
- 'data' => array('product' => $this->productMock, 'tier_price_template' => $this->defaultTemplate),
- 'priceBlockTypes' => array('product_id' => array('block' => $this->blockMock)),
+ 'data' => array('product' => $this->productMock),
'layout' => $layout
)
);
@@ -184,64 +162,4 @@ public function testSetPreconfiguredValueIfSuperGroupNotExist()
$this->groupedView->setPreconfiguredValue();
}
- /**
- * @param null|PHPUnit_Framework_MockObject_MockObject $price
- * @dataProvider getTierPriceHtmlDataProvider
- */
- public function testGetTierPriceHtml($price)
- {
- $this->productMock->expects($this->any())->method('getTypeId')->will($this->returnValue('product_id'));
- $this->blockMock->expects(
- $this->once()
- )->method(
- 'setTemplate'
- )->with(
- $this->defaultTemplate
- )->will(
- $this->returnValue($this->blockMock)
- );
- $this->blockMock->expects(
- $this->once()
- )->method(
- 'setProduct'
- )->with(
- $this->productMock
- )->will(
- $this->returnValue($this->blockMock)
- );
- $this->blockMock->expects(
- $this->once()
- )->method(
- 'setListClass'
- )->with(
- 'tier prices grouped items'
- )->will(
- $this->returnValue($this->blockMock)
- );
- $this->blockMock->expects(
- $this->once()
- )->method(
- 'setShowDetailedPrice'
- )->with(
- false
- )->will(
- $this->returnValue($this->blockMock)
- );
- $this->blockMock->expects(
- $this->once()
- )->method(
- 'setCanDisplayQty'
- )->with(
- false
- )->will(
- $this->returnValue($this->blockMock)
- );
- $this->blockMock->expects($this->once())->method('toHtml')->will($this->returnValue('expected'));
- $this->assertEquals('expected', $this->groupedView->getTierPriceHtml($price));
- }
-
- public function getTierPriceHtmlDataProvider()
- {
- return array('if_use_default_value_for_method' => array(null), 'if_pice_exist' => array($this->productMock));
- }
}
diff --git a/dev/tests/unit/testsuite/Magento/GroupedProduct/Pricing/Price/FinalPriceTest.php b/dev/tests/unit/testsuite/Magento/GroupedProduct/Pricing/Price/FinalPriceTest.php
index a0d8f021457bf..59e72c8710e23 100644
--- a/dev/tests/unit/testsuite/Magento/GroupedProduct/Pricing/Price/FinalPriceTest.php
+++ b/dev/tests/unit/testsuite/Magento/GroupedProduct/Pricing/Price/FinalPriceTest.php
@@ -34,93 +34,101 @@ class FinalPriceTest extends \PHPUnit_Framework_TestCase
*/
protected $finalPrice;
- /**
- * @var \Magento\GroupedProduct\Model\Product\Type\Grouped|\PHPUnit_Framework_MockObject_MockObject
- */
- protected $typeInstanceMock;
-
/**
* @var \Magento\Catalog\Model\Product|\PHPUnit_Framework_MockObject_MockObject
*/
- protected $salableItemMock;
+ protected $saleableItemMock;
/**
* @var \Magento\Framework\Pricing\Adjustment\Calculator|\PHPUnit_Framework_MockObject_MockObject
*/
protected $calculatorMock;
- /**
- * @var \Magento\Framework\Pricing\PriceInfo\Base|\PHPUnit_Framework_MockObject_MockObject
- */
- protected $priceInfoMock;
-
- /**
- * @var \Magento\Catalog\Model\Product|\PHPUnit_Framework_MockObject_MockObject
- */
- protected $productMock;
-
- /**
- * @var \Magento\Framework\Pricing\Amount\AmountInterface|\PHPUnit_Framework_MockObject_MockObject
- */
- protected $amountMock;
-
- /**
- * @var \Magento\Catalog\Pricing\Price\FinalPrice|\PHPUnit_Framework_MockObject_MockObject
- */
- protected $priceTypeMock;
-
/**
* Setup
*/
public function setUp()
{
- $this->salableItemMock = $this->getMock('Magento\Catalog\Model\Product', [], [], '', false);
- $this->productMock = $this->getMock('Magento\Catalog\Model\Product', [], [], '', false);
- $this->amountMock = $this->getMock('Magento\Framework\Pricing\Amount\Base', [], [], '', false);
+ $this->saleableItemMock = $this->getMock('Magento\Catalog\Model\Product', [], [], '', false);
$this->calculatorMock = $this->getMock('Magento\Framework\Pricing\Adjustment\Calculator', [], [], '', false);
- $this->priceInfoMock = $this->getMock('Magento\Framework\Pricing\PriceInfo\Base', [], [], '', false);
- $this->typeInstanceMock = $this->getMock('Magento\GroupedProduct\Model\Product\Type\Grouped',
- [], [], '', false);
- $this->priceTypeMock = $this->getMock('Magento\Catalog\Pricing\Price\FinalPrice', [], [], '', false);
$this->finalPrice = new \Magento\GroupedProduct\Pricing\Price\FinalPrice
(
- $this->salableItemMock,
+ $this->saleableItemMock,
+ null,
$this->calculatorMock
);
}
public function testGetMinProduct()
{
- $valueMap = [
- [90],
- [70]
- ];
- $this->salableItemMock->expects($this->once())
+ $product1 = $this->getProductMock(10);
+ $product2 = $this->getProductMock(20);
+
+ $typeInstanceMock = $this->getMock(
+ 'Magento\GroupedProduct\Model\Product\Type\Grouped',
+ [],
+ [],
+ '',
+ false
+ );
+ $typeInstanceMock->expects($this->once())
+ ->method('getAssociatedProducts')
+ ->with($this->equalTo($this->saleableItemMock))
+ ->will($this->returnValue([$product1, $product2]));
+
+ $this->saleableItemMock->expects($this->once())
->method('getTypeInstance')
- ->will($this->returnValue($this->typeInstanceMock));
+ ->will($this->returnValue($typeInstanceMock));
+
+ $this->assertEquals($product1, $this->finalPrice->getMinProduct());
+ }
- $this->typeInstanceMock->expects($this->once())
+ public function testGetValue()
+ {
+ $product1 = $this->getProductMock(10);
+ $product2 = $this->getProductMock(20);
+
+ $typeInstanceMock = $this->getMock(
+ 'Magento\GroupedProduct\Model\Product\Type\Grouped',
+ [],
+ [],
+ '',
+ false
+ );
+ $typeInstanceMock->expects($this->once())
->method('getAssociatedProducts')
- ->with($this->equalTo($this->salableItemMock))
- ->will($this->returnValue([$this->productMock, $this->productMock]));
+ ->with($this->equalTo($this->saleableItemMock))
+ ->will($this->returnValue([$product1, $product2]));
- $this->productMock->expects($this->exactly(2))
- ->method('setQty')
- ->with($this->equalTo(\Magento\Framework\Pricing\PriceInfoInterface::PRODUCT_QUANTITY_DEFAULT));
+ $this->saleableItemMock->expects($this->once())
+ ->method('getTypeInstance')
+ ->will($this->returnValue($typeInstanceMock));
- $this->productMock->expects($this->exactly(2))
- ->method('getPriceInfo')
- ->will($this->returnValue($this->priceInfoMock));
+ $this->assertEquals(10, $this->finalPrice->getValue());
+ }
- $this->priceInfoMock->expects($this->exactly(2))
+ protected function getProductMock($price)
+ {
+ $priceTypeMock = $this->getMock('Magento\Catalog\Pricing\Price\FinalPrice', [], [], '', false);
+ $priceTypeMock->expects($this->any())
+ ->method('getValue')
+ ->will($this->returnValue($price));
+
+ $priceInfoMock = $this->getMock('Magento\Framework\Pricing\PriceInfo\Base', [], [], '', false);
+ $priceInfoMock->expects($this->any())
->method('getPrice')
- ->with($this->equalTo(\Magento\Catalog\Pricing\Price\FinalPriceInterface::PRICE_TYPE_FINAL))
- ->will($this->returnValue($this->priceTypeMock));
+ ->with($this->equalTo(\Magento\Catalog\Pricing\Price\FinalPrice::PRICE_CODE))
+ ->will($this->returnValue($priceTypeMock));
- $this->priceTypeMock->expects($this->exactly(2))
- ->method('getValue')
- ->will($this->returnValueMap($valueMap));
- $this->assertEquals($this->finalPrice->getMinProduct(), $this->productMock);
+ $productMock = $this->getMock('Magento\Catalog\Model\Product', [], [], '', false);
+ $productMock->expects($this->any())
+ ->method('setQty')
+ ->with($this->equalTo(\Magento\Framework\Pricing\PriceInfoInterface::PRODUCT_QUANTITY_DEFAULT));
+ $productMock->expects($this->any())
+ ->method('getPriceInfo')
+ ->will($this->returnValue($priceInfoMock));
+
+ return $productMock;
}
}
diff --git a/dev/tests/unit/testsuite/Magento/PageCache/Model/ObserverTest.php b/dev/tests/unit/testsuite/Magento/PageCache/Model/ObserverTest.php
index ea6301b5cf1d8..a24398ce6f406 100644
--- a/dev/tests/unit/testsuite/Magento/PageCache/Model/ObserverTest.php
+++ b/dev/tests/unit/testsuite/Magento/PageCache/Model/ObserverTest.php
@@ -110,7 +110,7 @@ public function setUp()
false,
true,
true,
- array('getTtl', 'isScopePrivate', 'getNameInLayout', 'getUrl')
+ array('getData', 'isScopePrivate', 'getNameInLayout', 'getUrl')
);
$this->_transport = new \Magento\Framework\Object(array('output' => 'test output html'));
$this->_observerObject = $this->getMock('\Magento\Store\Model\Store', array(), array(), '', false);
@@ -158,14 +158,13 @@ public function testProcessLayoutRenderElement(
);
if ($varnishIsEnabled) {
- $this->_blockMock->setTtl($blockTtl);
- $this->_blockMock->expects(
- $this->any()
- )->method(
- 'getUrl'
- )->will(
- $this->returnValue('page_cache/block/wrapesi/with/handles/and/other/stuff')
- );
+ $this->_blockMock->expects($this->once())
+ ->method('getData')
+ ->with('ttl')
+ ->will($this->returnValue($blockTtl));
+ $this->_blockMock->expects($this->any())
+ ->method('getUrl')
+ ->will($this->returnValue('page_cache/block/wrapesi/with/handles/and/other/stuff'));
}
if ($scopeIsPrivate) {
$this->_blockMock->expects(
diff --git a/dev/tests/unit/testsuite/Magento/Paypal/Model/IpnTest.php b/dev/tests/unit/testsuite/Magento/Paypal/Model/IpnTest.php
index 5fd842f57db4e..4f34b2077d6c3 100644
--- a/dev/tests/unit/testsuite/Magento/Paypal/Model/IpnTest.php
+++ b/dev/tests/unit/testsuite/Magento/Paypal/Model/IpnTest.php
@@ -96,6 +96,9 @@ public function testLegacyRegisterPaymentAuthorization()
$testMethod = new \ReflectionMethod('Magento\Paypal\Model\Ipn', '_registerPaymentAuthorization');
$testMethod->setAccessible(true);
+ $this->markTestIncomplete(
+ 'MAGETWO-23755: "Fatal error: Using $this when not in object context" is observed under PHPUnit4'
+ );
$testMethod->invoke($this->_ipn);
}
diff --git a/dev/tests/unit/testsuite/Magento/Rss/Block/Catalog/CategoryTest.php b/dev/tests/unit/testsuite/Magento/Rss/Block/Catalog/CategoryTest.php
new file mode 100644
index 0000000000000..4ecf1663791d8
--- /dev/null
+++ b/dev/tests/unit/testsuite/Magento/Rss/Block/Catalog/CategoryTest.php
@@ -0,0 +1,147 @@
+getMock('Magento\Framework\View\Element\Template\Context', [], [], '', false);
+ $this->imageHelperMock = $this->getMock('Magento\Catalog\Helper\Image', [], [], '', false);
+ $eventManagerMock = $this->getMock('Magento\Framework\Event\ManagerInterface', [], [], '', false);
+ $requestMock = $this->getMock('Magento\Framework\App\RequestInterface', [], [], '', false);
+
+ $templateContextMock->expects($this->once())
+ ->method('getEventManager')
+ ->will($this->returnValue($eventManagerMock));
+ $templateContextMock->expects($this->once())
+ ->method('getRequest')
+ ->will($this->returnValue($requestMock));
+
+ $objectManager = new \Magento\TestFramework\Helper\ObjectManager($this);
+ $this->block = $objectManager->getObject(
+ 'Magento\Rss\Block\Catalog\Category',
+ [
+ 'context' => $templateContextMock,
+ 'imageHelper' => $this->imageHelperMock,
+ ]
+ );
+ }
+
+ /**
+ * Test for method addNewItemXmlCallback
+ */
+ public function testAddNewItemXmlCallback()
+ {
+ $priceHtmlForTest = '
Price is 10 for example
';
+ $productMock = $this->getMock(
+ 'Magento\Catalog\Model\Product',
+ ['getProductUrl', 'getDescription', 'getAllowedInRss', 'getName', '__wakeup'],
+ [],
+ '',
+ false
+ );
+ $rssObjMock = $this->getMock('Magento\Rss\Model\Rss', [], [], '', false);
+ $layoutMock = $this->getMockForAbstractClass(
+ 'Magento\Framework\View\LayoutInterface',
+ [],
+ '',
+ true,
+ true,
+ true,
+ ['getBlock']
+ );
+ $priceRendererMock = $this->getMock('Magento\Framework\Pricing\Render', ['render'], [], '', false);
+ $productTitle = 'Product title';
+ $productUrl = '
Product Url';
+ $imgThumbSrc = 'http://source-for-thumbnail';
+ $productDescription = 'Product description';
+ $description = '
![](' . $imgThumbSrc .
+ ') | ' .
+ $productDescription . $priceHtmlForTest . ' |
';
+
+ $productMock->expects($this->exactly(2))
+ ->method('getProductUrl')
+ ->will($this->returnValue($productUrl));
+ $productMock->expects($this->once())
+ ->method('getDescription')
+ ->will($this->returnValue($productDescription));
+ $productMock->expects($this->any())
+ ->method('getAllowedInRss')
+ ->will($this->returnValue(true));
+ $productMock->expects($this->once())
+ ->method('getName')
+ ->will($this->returnValue($productTitle));
+ $this->imageHelperMock->expects($this->once())
+ ->method('init')
+ ->will($this->returnSelf());
+ $this->imageHelperMock->expects($this->once())
+ ->method('resize')
+ ->will($this->returnValue($imgThumbSrc));
+ $layoutMock->expects($this->once())
+ ->method('getBlock')
+ ->will($this->returnValue($priceRendererMock));
+ $priceRendererMock->expects($this->once())
+ ->method('render')
+ ->will($this->returnValue($priceHtmlForTest));
+
+ $expectedData = [
+ 'title' => $productTitle,
+ 'link' => $productUrl,
+ 'description' => $description
+ ];
+ $rssObjMock->expects($this->once())
+ ->method('_addEntry')
+ ->with($expectedData)
+ ->will($this->returnSelf());
+
+
+ $args = [
+ 'product' => $productMock,
+ 'rssObj' => $rssObjMock
+ ];
+
+ $this->block->setLayout($layoutMock);
+ $this->assertNull($this->block->addNewItemXmlCallback($args));
+ }
+}
diff --git a/dev/tests/unit/testsuite/Magento/Rss/Block/Catalog/NewCatalogTest.php b/dev/tests/unit/testsuite/Magento/Rss/Block/Catalog/NewCatalogTest.php
new file mode 100644
index 0000000000000..bb580235022a2
--- /dev/null
+++ b/dev/tests/unit/testsuite/Magento/Rss/Block/Catalog/NewCatalogTest.php
@@ -0,0 +1,149 @@
+getMock('Magento\Framework\View\Element\Template\Context', [], [], '', false);
+ $this->imageHelperMock = $this->getMock('Magento\Catalog\Helper\Image', [], [], '', false);
+
+ $eventManagerMock = $this->getMock('Magento\Framework\Event\ManagerInterface', [], [], '', false);
+ $requestMock = $this->getMock('Magento\Framework\App\RequestInterface', [], [], '', false);
+
+ $templateContextMock->expects($this->once())
+ ->method('getEventManager')
+ ->will($this->returnValue($eventManagerMock));
+ $templateContextMock->expects($this->once())
+ ->method('getRequest')
+ ->will($this->returnValue($requestMock));
+
+ $objectManager = new \Magento\TestFramework\Helper\ObjectManager($this);
+ $this->block = $objectManager->getObject(
+ 'Magento\Rss\Block\Catalog\NewCatalog',
+ [
+ 'context' => $templateContextMock,
+ 'imageHelper' => $this->imageHelperMock,
+ ]
+ );
+ }
+
+ /**
+ * Test for method addNewItemXmlCallback
+ */
+ public function testAddNewItemXmlCallback()
+ {
+ $priceHtmlForTest = '
Price is 10 for example
';
+ $productMock = $this->getMock(
+ 'Magento\Catalog\Model\Product',
+ ['getProductUrl', 'getDescription', 'getAllowedInRss', 'getName', '__wakeup'],
+ [],
+ '',
+ false
+ );
+ $rssObjMock = $this->getMock('Magento\Rss\Model\Rss', [], [], '', false);
+ $layoutMock = $this->getMockForAbstractClass(
+ 'Magento\Framework\View\LayoutInterface',
+ [],
+ '',
+ true,
+ true,
+ true,
+ ['getBlock']
+ );
+ $priceRendererMock = $this->getMock('Magento\Framework\Pricing\Render', ['render'], [], '', false);
+ $productTitle = 'Product title';
+ $productUrl = '
Product Url';
+ $imgThumbSrc = 'http://source-for-thumbnail';
+ $productDescription = 'Product description';
+ $description = '
![](' . $imgThumbSrc .
+ ') | ' .
+ $productDescription . $priceHtmlForTest . ' |
';
+
+ $productMock->expects($this->exactly(2))
+ ->method('getProductUrl')
+ ->will($this->returnValue($productUrl));
+ $productMock->expects($this->once())
+ ->method('getDescription')
+ ->will($this->returnValue($productDescription));
+ $productMock->expects($this->any())
+ ->method('getAllowedInRss')
+ ->will($this->returnValue(true));
+ $productMock->expects($this->once())
+ ->method('getName')
+ ->will($this->returnValue($productTitle));
+ $this->imageHelperMock->expects($this->once())
+ ->method('init')
+ ->will($this->returnSelf());
+ $this->imageHelperMock->expects($this->once())
+ ->method('resize')
+ ->will($this->returnValue($imgThumbSrc));
+ $layoutMock->expects($this->once())
+ ->method('getBlock')
+ ->will($this->returnValue($priceRendererMock));
+ $priceRendererMock->expects($this->once())
+ ->method('render')
+ ->will($this->returnValue($priceHtmlForTest));
+
+ $expectedData = [
+ 'title' => $productTitle,
+ 'link' => $productUrl,
+ 'description' => $description
+ ];
+ $rssObjMock->expects($this->once())
+ ->method('_addEntry')
+ ->with($expectedData)
+ ->will($this->returnSelf());
+
+
+ $args = [
+ 'product' => $productMock,
+ 'rssObj' => $rssObjMock,
+ 'row' => ''
+ ];
+
+ $this->block->setLayout($layoutMock);
+ $this->assertNull($this->block->addNewItemXmlCallback($args));
+ }
+}
diff --git a/dev/tests/unit/testsuite/Magento/Rss/Block/Catalog/SpecialTest.php b/dev/tests/unit/testsuite/Magento/Rss/Block/Catalog/SpecialTest.php
new file mode 100644
index 0000000000000..bb3d6b308a7c7
--- /dev/null
+++ b/dev/tests/unit/testsuite/Magento/Rss/Block/Catalog/SpecialTest.php
@@ -0,0 +1,271 @@
+getMock('Magento\Framework\View\Element\Template\Context', [], [], '', false);
+ $this->catalogHelperMock = $this->getMock('Magento\Catalog\Helper\Data', [], [], '', false);
+ $this->priceCurrencyMock = $this->getMockForAbstractClass(
+ 'Magento\Framework\Pricing\PriceCurrencyInterface',
+ [],
+ '',
+ true,
+ true,
+ true,
+ ['convertAndFormat']
+ );
+ $this->rssFactoryMock = $this->getMock('Magento\Rss\Model\RssFactory', ['create'], [], '', false);
+ $this->productFactoryMock = $this->getMock('Magento\Catalog\Model\ProductFactory', ['create'], [], '', false);
+ $this->resourceIteratorMock = $this->getMock('Magento\Framework\Model\Resource\Iterator', [], [], '', false);
+ $this->imageHelperMock = $this->getMock('Magento\Catalog\Helper\Image', [], [], '', false);
+
+ $eventManagerMock = $this->getMock('Magento\Framework\Event\ManagerInterface', [], [], '', false);
+ $requestMock = $this->getMock('Magento\Framework\App\RequestInterface', [], [], '', false);
+ $storeManagerMock = $this->getMock('Magento\Store\Model\StoreManagerInterface');
+ $urlBuilderMock = $this->getMock('Magento\Framework\UrlInterface', [], [], '', false);
+ $this->storeMock = $this->getMock('Magento\Store\Model\Store', [], [], '', false);
+ $scopeConfigMock = $this->getMock('Magento\Framework\App\Config\ScopeConfigInterface', [], [], '', false);
+ $cacheStateMock = $this->getMock('Magento\Framework\App\Cache\StateInterface', [], [], '', false);
+
+ $templateContextMock->expects($this->any())
+ ->method('getRequest')
+ ->will($this->returnValue($requestMock));
+ $templateContextMock->expects($this->any())
+ ->method('getScopeConfig')
+ ->will($this->returnValue($scopeConfigMock));
+ $templateContextMock->expects($this->any())
+ ->method('getCacheState')
+ ->will($this->returnValue($cacheStateMock));
+ $templateContextMock->expects($this->any())
+ ->method('getEventManager')
+ ->will($this->returnValue($eventManagerMock));
+ $templateContextMock->expects($this->any())
+ ->method('getUrlBuilder')
+ ->will($this->returnValue($urlBuilderMock));
+ $templateContextMock->expects($this->any())
+ ->method('getStoreManager')
+ ->will($this->returnValue($storeManagerMock));
+ $storeManagerMock->expects($this->any())
+ ->method('getStore')
+ ->will($this->returnValue($this->storeMock));
+ $this->storeMock->expects($this->any())
+ ->method('getId')
+ ->will($this->returnValue(0));
+
+ $objectManager = new \Magento\TestFramework\Helper\ObjectManager($this);
+ $this->block = $objectManager->getObject(
+ 'Magento\Rss\Block\Catalog\Special',
+ [
+ 'context' => $templateContextMock,
+ 'catalogData' => $this->catalogHelperMock,
+ 'priceCurrency' => $this->priceCurrencyMock,
+ 'productFactory' => $this->productFactoryMock,
+ 'rssFactory' => $this->rssFactoryMock,
+ 'resourceIterator' => $this->resourceIteratorMock,
+ 'imageHelper' => $this->imageHelperMock,
+ ]
+ );
+ }
+
+ /**
+ * Test for method _toHtml
+ *
+ * @return void
+ */
+ public function testToHtml()
+ {
+ $productMock = $this->getMock(
+ 'Magento\Catalog\Model\Product',
+ ['getProductUrl', 'getDescription', 'getAllowedPriceInRss', 'getName', '__wakeup', 'getResourceCollection'],
+ [],
+ '',
+ false
+ );
+ $productCollectionMock = $this->getMock(
+ 'Magento\Catalog\Model\Resource\Product\CollectionFactory',
+ ['addPriceDataFieldFilter', 'addPriceData', 'addAttributeToSelect', 'addAttributeToSort', 'getSelect'],
+ [],
+ '',
+ false
+ );
+ $rssObjMock = $this->getMock('Magento\Rss\Model\Rss', [], [], '', false);
+ $productUrl = '
Product Url';
+ $imgThumbSrc = 'http://source-for-thumbnail';
+ $productTitle = 'Product title';
+ $basePriceFormatted = '
$10.00';
+ $finalPriceFormatted = '
$20.00';
+ $productDescription = '
' .
+ '![](' . $imgThumbSrc .
+ ') | ' .
+ 'Price: ' . $basePriceFormatted . ' Special Price: ' .
+ $finalPriceFormatted . ' |
';
+ $expectedData = [
+ 'title' => $productTitle,
+ 'link' => $productUrl,
+ 'description' => $productDescription
+ ];
+ $expectedResult = new \Magento\Framework\Object(['rss_feed' => '
Feed of the rss']);
+
+ $this->addMocks();
+ $this->productFactoryMock->expects($this->once())
+ ->method('create')
+ ->will($this->returnValue($productMock));
+ $productMock->expects($this->once())
+ ->method('getResourceCollection')
+ ->will($this->returnValue($productCollectionMock));
+ $productCollectionMock->expects($this->once())
+ ->method('addPriceDataFieldFilter')
+ ->will($this->returnSelf());
+ $productCollectionMock->expects($this->once())
+ ->method('addPriceData')
+ ->will($this->returnSelf());
+ $productCollectionMock->expects($this->once())
+ ->method('addAttributeToSelect')
+ ->will($this->returnSelf());
+ $productCollectionMock->expects($this->once())
+ ->method('addAttributeToSort')
+ ->will($this->returnSelf());
+ $this->rssFactoryMock->expects($this->once())
+ ->method('create')
+ ->will($this->returnValue($rssObjMock));
+ $productMock->expects($this->exactly(2))
+ ->method('getProductUrl')
+ ->will($this->returnValue($productUrl));
+ $this->imageHelperMock->expects($this->once())
+ ->method('resize')
+ ->will($this->returnValue($imgThumbSrc));
+ $productMock->expects($this->any())
+ ->method('getAllowedPriceInRss')
+ ->will($this->returnValue(true));
+ $productMock->expects($this->once())
+ ->method('getName')
+ ->will($this->returnValue($productTitle));
+ $this->priceCurrencyMock->expects($this->exactly(2))
+ ->method('convertAndFormat')
+ ->will($this->returnValueMap(
+ [
+ [10, true, PriceCurrencyInterface::DEFAULT_PRECISION, null, null, $basePriceFormatted],
+ [20, true, PriceCurrencyInterface::DEFAULT_PRECISION, null, null, $finalPriceFormatted],
+ ]
+ )
+ );
+ $rssObjMock->expects($this->once())
+ ->method('_addEntry')
+ ->with($expectedData)
+ ->will($this->returnSelf());
+ $rssObjMock->expects($this->once())
+ ->method('createRssXml')
+ ->will($this->returnValue($expectedResult));
+ $this->assertEquals($expectedResult, $this->block->toHtml());
+ }
+
+ /**
+ * Additional function to break up mocks initialization
+ *
+ * @return void
+ */
+ protected function addMocks()
+ {
+
+ $resIteratorcallback = function () {
+ $arguments = func_get_args();
+ $arguments[2]['results'] = [
+ ['use_special' => false, 'price' => 10, 'final_price' => 20]
+ ];
+ };
+
+ $this->storeMock->expects($this->once())
+ ->method('getWebsiteId')
+ ->will($this->returnValue(0));
+ $this->storeMock->expects($this->once())
+ ->method('getFrontendName')
+ ->will($this->returnValue('store name'));
+
+ $this->catalogHelperMock->expects($this->once())
+ ->method('canApplyMsrp')
+ ->will($this->returnValue(false));
+ $this->resourceIteratorMock->expects($this->once())
+ ->method('walk')
+ ->will($this->returnCallback($resIteratorcallback));
+ $this->imageHelperMock->expects($this->once())
+ ->method('init')
+ ->will($this->returnSelf());
+ }
+}
diff --git a/dev/tests/unit/testsuite/Magento/Rss/Block/WishlistTest.php b/dev/tests/unit/testsuite/Magento/Rss/Block/WishlistTest.php
new file mode 100644
index 0000000000000..55fc7279aaef6
--- /dev/null
+++ b/dev/tests/unit/testsuite/Magento/Rss/Block/WishlistTest.php
@@ -0,0 +1,404 @@
+getMock('Magento\Catalog\Block\Product\Context', [], [], '', false);
+ $this->coreHelperMock = $this->getMock('Magento\Core\Helper\Data', [], [], '', false);
+ $this->catalogOutputMock = $this->getMock('Magento\Catalog\Helper\Output', [], [], '', false);
+ $wishlistFactoryMock = $this->getMock('Magento\Wishlist\Model\WishlistFactory', [], [], '', false);
+ $this->rssFactoryMock = $this->getMock('Magento\Rss\Model\RssFactory', ['create'], [], '', false);
+ $eventManagerMock = $this->getMock('Magento\Framework\Event\ManagerInterface', [], [], '', false);
+ $cacheStateMock = $this->getMock('Magento\Framework\App\Cache\StateInterface', [], [], '', false);
+ $this->productFactoryMock = $this->getMock(
+ 'Magento\Catalog\Model\ProductFactory',
+ ['create', '__wakeup'],
+ [],
+ '',
+ false
+ );
+ $this->wishlistHelperMock = $this->getMock(
+ 'Magento\Wishlist\Helper\Data',
+ ['getWishlist', 'getCustomer', 'getCustomerName'],
+ [],
+ '',
+ false
+ );
+ $this->urlBuilderMock = $this->getMockForAbstractClass(
+ 'Magento\Framework\UrlInterface',
+ [],
+ '',
+ true,
+ true,
+ true,
+ ['getUrl']
+ );
+ $this->storeConfigMock = $this->getMockForAbstractClass(
+ 'Magento\Framework\App\Config\ScopeConfigInterface',
+ [],
+ '',
+ true,
+ true,
+ true,
+ ['getConfig']
+ );
+ $this->imageHelperMock = $this->getMock('Magento\Catalog\Helper\Image', [], [], '', false);
+
+ $templateContextMock->expects($this->once())
+ ->method('getEventManager')
+ ->will($this->returnValue($eventManagerMock));
+ $templateContextMock->expects($this->once())
+ ->method('getCacheState')
+ ->will($this->returnValue($cacheStateMock));
+ $templateContextMock->expects($this->once())
+ ->method('getImageHelper')
+ ->will($this->returnValue($this->imageHelperMock));
+ $templateContextMock->expects($this->once())
+ ->method('getWishlistHelper')
+ ->will($this->returnValue($this->wishlistHelperMock));
+ $templateContextMock->expects($this->once())
+ ->method('getScopeConfig')
+ ->will($this->returnValue($this->storeConfigMock));
+ $templateContextMock->expects($this->once())
+ ->method('getUrlBuilder')
+ ->will($this->returnValue($this->urlBuilderMock));
+
+ $objectManager = new \Magento\TestFramework\Helper\ObjectManager($this);
+ $this->block = $objectManager->getObject(
+ 'Magento\Rss\Block\Wishlist',
+ [
+ 'context' => $templateContextMock,
+ 'productFactory' => $this->productFactoryMock,
+ 'coreData' => $this->coreHelperMock,
+ 'wishlistFactory' => $wishlistFactoryMock,
+ 'rssFactory' => $this->rssFactoryMock,
+ 'outputHelper' => $this->catalogOutputMock
+ ]
+ );
+ }
+
+ /**
+ * Test for method _toHtml
+ */
+ public function testToHtml()
+ {
+ $wishlistId = 1;
+ $customerName = 'Customer Name';
+ $title = "$customerName's Wishlist";
+ $rssObjMock = $this->getMock('Magento\Rss\Model\Rss', [], [], '', false);
+ $wishlistModelMock = $this->getMock(
+ 'Magento\Wishlist\Model\Wishlist',
+ ['getId', '__wakeup', 'getCustomerId', 'getItemCollection'],
+ [],
+ '',
+ false
+ );
+ $customerServiceMock = $this->getMock('Magento\Customer\Service\V1\Data\Customer', [], [], '', false);
+ $wishlistSharingUrl = 'wishlist/shared/index/1';
+ $locale = 'en_US';
+ $productUrl = 'http://product.url/';
+ $productName = 'Product name';
+ $expectedHeaders = [
+ 'title' => $title,
+ 'description' => $title,
+ 'link' => $wishlistSharingUrl,
+ 'charset' => 'UTF-8',
+ 'language' => $locale
+ ];
+
+
+ $this->rssFactoryMock->expects($this->once())
+ ->method('create')
+ ->will($this->returnValue($rssObjMock));
+ $this->wishlistHelperMock->expects($this->once())
+ ->method('getWishlist')
+ ->will($this->returnValue($wishlistModelMock));
+ $this->wishlistHelperMock->expects($this->once())
+ ->method('getCustomer')
+ ->will($this->returnValue($customerServiceMock));
+ $this->wishlistHelperMock->expects($this->once())
+ ->method('getCustomerName')
+ ->will($this->returnValue($customerName));
+ $wishlistModelMock->expects($this->once())
+ ->method('getId')
+ ->will($this->returnValue($wishlistId));
+ $this->urlBuilderMock->expects($this->once())
+ ->method('getUrl')
+ ->will($this->returnValue($wishlistSharingUrl));
+ $this->storeConfigMock->expects($this->any())
+ ->method('getValue')
+ ->will($this->returnValueMap(
+ [
+ [
+ 'advanced/modules_disable_output/Magento_Rss',
+ \Magento\Store\Model\ScopeInterface::SCOPE_STORE,
+ null,
+ null
+ ],
+ [
+ 'general/locale/code',
+ \Magento\Store\Model\ScopeInterface::SCOPE_STORE,
+ null,
+ $locale
+ ]
+ ]
+ )
+ );
+
+ $staticArgs = [
+ 'productName' => $productName,
+ 'productUrl' => $productUrl
+ ];
+ $description = $this->processWishlistItemDescription($wishlistModelMock, $staticArgs);
+ $expectedEntry = [
+ 'title' => $productName,
+ 'link' => $productUrl,
+ 'description' => $description
+ ];
+ $rssString = '';
+
+ $rssObjMock->expects($this->once())
+ ->method('_addHeader')
+ ->with($expectedHeaders)
+ ->will($this->returnSelf());
+ $rssObjMock->expects($this->once())
+ ->method('_addEntry')
+ ->with($expectedEntry);
+ $rssObjMock->expects($this->once())
+ ->method('createRssXml')
+ ->will($this->returnValue($rssString));
+
+ $this->assertEquals($rssString, $this->block->toHtml());
+ }
+
+ /**
+ * Additional function to process forming description for wishlist item
+ *
+ * @param \Magento\Wishlist\Model\Wishlist $wishlistModelMock
+ * @param array $staticArgs
+ * @return string
+ */
+ protected function processWishlistItemDescription($wishlistModelMock, $staticArgs)
+ {
+ $imgThumbSrc = 'http://source-for-thumbnail';
+ $priceHtmlForTest = '
Price is 10 for example
';
+ $productDescription = 'Product description';
+ $productShortDescription = 'Product short description';
+
+ $wishlistItem = $this->getMock('Magento\Wishlist\Model\Item', [], [], '', false);
+ $wishlistItemsCollection = [
+ $wishlistItem
+ ];
+ $productMock = $this->getMock(
+ 'Magento\Catalog\Model\Product',
+ [
+ 'getAllowedInRss',
+ 'getAllowedPriceInRss',
+ 'getDescription',
+ 'getShortDescription',
+ 'getName',
+ 'getVisibleInSiteVisibilities',
+ 'getUrlModel',
+ '__wakeup'
+ ],
+ [],
+ '',
+ false
+ );
+ $urlModelMock = $this->getMock('Magento\Catalog\Model\Product\Url', [], [], '', false);
+ $layoutMock = $this->getMockForAbstractClass(
+ 'Magento\Framework\View\LayoutInterface',
+ [],
+ '',
+ true,
+ true,
+ true,
+ ['getBlock']
+ );
+
+ $wishlistModelMock->expects($this->once())
+ ->method('getItemCollection')
+ ->will($this->returnValue($wishlistItemsCollection));
+ $wishlistItem->expects($this->once())
+ ->method('getProduct')
+ ->will($this->returnValue($productMock));
+ $productMock->expects($this->once())
+ ->method('getUrlModel')
+ ->will($this->returnValue($urlModelMock));
+ $productMock->expects($this->once())
+ ->method('getAllowedPriceInRss')
+ ->will($this->returnValue($urlModelMock));
+ $urlModelMock->expects($this->once())
+ ->method('getUrl')
+ ->will($this->returnValue($staticArgs['productUrl']));
+ $productMock->expects($this->once())
+ ->method('getName')
+ ->will($this->returnValue($staticArgs['productName']));
+ $productMock->expects($this->once())
+ ->method('getAllowedInRss')
+ ->will($this->returnValue(true));
+ $productMock->expects($this->once())
+ ->method('getVisibleInSiteVisibilities')
+ ->will($this->returnValue(true));
+ $this->imageHelperMock->expects($this->once())
+ ->method('init')
+ ->will($this->returnSelf());
+ $this->imageHelperMock->expects($this->once())
+ ->method('resize')
+ ->will($this->returnValue($imgThumbSrc));
+ $priceRendererMock = $this->getMock('Magento\Framework\Pricing\Render', ['render'], [], '', false);
+
+ $layoutMock->expects($this->once())
+ ->method('getBlock')
+ ->will($this->returnValue($priceRendererMock));
+ $priceRendererMock->expects($this->once())
+ ->method('render')
+ ->will($this->returnValue($priceHtmlForTest));
+ $productMock->expects($this->any())
+ ->method('getDescription')
+ ->will($this->returnValue($productDescription));
+ $productMock->expects($this->any())
+ ->method('getShortDescription')
+ ->will($this->returnValue($productShortDescription));
+ $this->catalogOutputMock->expects($this->any())
+ ->method('productAttribute')
+ ->will($this->returnArgument(1));
+
+ $this->block->setLayout($layoutMock);
+ $description = '
![](' . $imgThumbSrc .
+ ') | ' .
+ $productShortDescription . ' ' . $priceHtmlForTest . ' Comment: ' . $productDescription . ' ' .
+ ' |
';
+
+ return $description;
+ }
+
+ /**
+ * Test for method _toHtml for the case, when wishlist is absent
+ */
+ public function testToHtmlWithoutWishlist()
+ {
+ $url = 'http://base.url/index';
+ $rssString = '
Some empty xml';
+ $rssObjMock = $this->getMock('Magento\Rss\Model\Rss', [], [], '', false);
+ $customerServiceMock = $this->getMock('Magento\Customer\Service\V1\Data\Customer', [], [], '', false);
+ $wishlistModelMock = $this->getMock(
+ 'Magento\Wishlist\Model\Wishlist',
+ ['getId', '__wakeup', 'getCustomerId'],
+ [],
+ '',
+ false
+ );
+ $expectedHeaders = [
+ 'title' => __('We cannot retrieve the wish list.'),
+ 'description' => __('We cannot retrieve the wish list.'),
+ 'link' => $url,
+ 'charset' => 'UTF-8'
+ ];
+
+ $this->rssFactoryMock->expects($this->once())
+ ->method('create')
+ ->will($this->returnValue($rssObjMock));
+ $this->wishlistHelperMock->expects($this->once())
+ ->method('getWishlist')
+ ->will($this->returnValue($wishlistModelMock));
+ $wishlistModelMock->expects($this->once())
+ ->method('getId')
+ ->will($this->returnValue(false));
+ $this->urlBuilderMock->expects($this->once())
+ ->method('getUrl')
+ ->will($this->returnValue($url));
+ $this->wishlistHelperMock->expects($this->once())
+ ->method('getCustomer')
+ ->will($this->returnValue($customerServiceMock));
+ $rssObjMock->expects($this->once())
+ ->method('_addHeader')
+ ->with($expectedHeaders)
+ ->will($this->returnSelf());
+ $rssObjMock->expects($this->once())
+ ->method('createRssXml')
+ ->will($this->returnValue($rssString));
+
+ $this->assertEquals($rssString, $this->block->toHtml());
+ }
+}
diff --git a/dev/tests/unit/testsuite/Magento/Sales/Controller/Adminhtml/OrderTest.php b/dev/tests/unit/testsuite/Magento/Sales/Controller/Adminhtml/OrderTest.php
index db247adb1ffb6..afb5d98498f7e 100644
--- a/dev/tests/unit/testsuite/Magento/Sales/Controller/Adminhtml/OrderTest.php
+++ b/dev/tests/unit/testsuite/Magento/Sales/Controller/Adminhtml/OrderTest.php
@@ -79,16 +79,32 @@ public function setUp()
$this->getMock('\Magento\Framework\App\Action\Title', array('__wakeup', 'add'), array(), '', false);
$viewMock = $this->getMockForAbstractClass('\Magento\Framework\App\ViewInterface');
+ /**
+ * @TODO:
+ * - Methods of object under test MUST NOT be mocked
+ * - Protected properties MUST NOT be set from outside, inject via context passed to constructor instead
+ */
$this->_controllerMock = $this->getMockBuilder(
- '\Magento\Sales\Controller\Adminhtml\Stub\Order'
+ '\Magento\Sales\Controller\Adminhtml\Order'
)->disableOriginalConstructor()->setMethods(
array('__wakeup', '_initOrder', '_initAction', '__', 'renderLayout', '_redirect')
)->getMock();
$this->_controllerMock->expects($this->any())->method('__')->will($this->returnArgument(0));
- $this->_controllerMock->_title = $titleMock;
- $this->_controllerMock->_view = $viewMock;
- $this->_controllerMock->messageManager = $this->_messageMock;
+ $reflectionProperty = new \ReflectionProperty('\Magento\Sales\Controller\Adminhtml\Order', '_title');
+ $reflectionProperty->setAccessible(true);
+ $reflectionProperty->setValue($this->_controllerMock, $titleMock);
+ $reflectionProperty->setAccessible(false);
+
+ $reflectionProperty = new \ReflectionProperty('\Magento\Sales\Controller\Adminhtml\Order', '_view');
+ $reflectionProperty->setAccessible(true);
+ $reflectionProperty->setValue($this->_controllerMock, $viewMock);
+ $reflectionProperty->setAccessible(false);
+
+ $reflectionProperty = new \ReflectionProperty('\Magento\Sales\Controller\Adminhtml\Order', 'messageManager');
+ $reflectionProperty->setAccessible(true);
+ $reflectionProperty->setValue($this->_controllerMock, $this->_messageMock);
+ $reflectionProperty->setAccessible(false);
}
/**
diff --git a/dev/tests/unit/testsuite/Magento/Sales/Model/Quote/ItemTest.php b/dev/tests/unit/testsuite/Magento/Sales/Model/Quote/ItemTest.php
index 73bc9bc7ab8b0..c9e41f6ce4b4c 100644
--- a/dev/tests/unit/testsuite/Magento/Sales/Model/Quote/ItemTest.php
+++ b/dev/tests/unit/testsuite/Magento/Sales/Model/Quote/ItemTest.php
@@ -36,12 +36,12 @@ class ItemTest extends \PHPUnit_Framework_TestCase
private $localeFormat;
/**
- * @var \Magento\Model\Context
+ * @var \Magento\Framework\Model\Context
*/
private $modelContext;
/**
- * @var \Magento\Event\ManagerInterface
+ * @var \Magento\Framework\Event\ManagerInterface
*/
private $eventDispatcher;
@@ -81,7 +81,7 @@ protected function setUp()
->setMethods(['getEventDispatcher'])
->getMock();
- $this->eventDispatcher = $this->getMockBuilder('Magento\Event\ManagerInterface')
+ $this->eventDispatcher = $this->getMockBuilder('Magento\Framework\Event\ManagerInterface')
->disableOriginalConstructor()
->setMethods(['dispatch'])
->getMock();
diff --git a/dev/tests/unit/testsuite/Magento/Store/Model/Storage/DbTest.php b/dev/tests/unit/testsuite/Magento/Store/Model/Storage/DbTest.php
index 01ffe65308f64..5afae729e73fc 100644
--- a/dev/tests/unit/testsuite/Magento/Store/Model/Storage/DbTest.php
+++ b/dev/tests/unit/testsuite/Magento/Store/Model/Storage/DbTest.php
@@ -190,7 +190,7 @@ protected function prepareMockForReinit()
$websiteCode = 'website_code';
$groupId = 1;
$storeId = 1;
- $storeCode = \Magento\Store\Model\Store::DEFAULT_CODE;
+ $storeCode = 'store_code';
$websiteCollection =
$this->getMock('\Magento\Store\Model\Resource\Website\Collection', array(), array(), '', false, false);
$websiteCollection->expects($this->any())->method('setLoadDefault')->with(true);
@@ -266,7 +266,6 @@ public function testGetStoreGetDefaulStore()
$this->prepareMockForReinit();
$this->_model->reinitStores();
$this->assertSame($this->_storeMock, $this->_model->getStore(true));
-
}
public function testReinitStores()
@@ -294,7 +293,7 @@ public function testGetStores()
$this->_model->reinitStores();
$this->assertSame($expected, $this->_model->getStores());
- $expected = array(\Magento\Store\Model\Store::DEFAULT_CODE => $this->_storeMock);
+ $expected = array('store_code' => $this->_storeMock);
$this->assertSame($expected, $this->_model->getStores(false, true));
}
diff --git a/dev/tests/unit/testsuite/Magento/Tax/Pricing/AdjustmentTest.php b/dev/tests/unit/testsuite/Magento/Tax/Pricing/AdjustmentTest.php
index ff9dd0242fd2e..74ea74b8a9059 100644
--- a/dev/tests/unit/testsuite/Magento/Tax/Pricing/AdjustmentTest.php
+++ b/dev/tests/unit/testsuite/Magento/Tax/Pricing/AdjustmentTest.php
@@ -24,49 +24,46 @@
namespace Magento\Tax\Pricing;
-use Magento\Tax\Helper\Data as TaxHelper;
use Magento\Framework\Pricing\Object\SaleableInterface;
class AdjustmentTest extends \PHPUnit_Framework_TestCase
{
+ /**
+ * @var Adjustment
+ */
+ protected $adjustment;
+
+ /**
+ * @var \Magento\Tax\Helper\Data | \PHPUnit_Framework_MockObject_MockObject
+ */
+ protected $taxHelper;
+
+ /**
+ * @var int
+ */
+ protected $sortOrder = 5;
+
+ public function setUp()
+ {
+ $this->taxHelper = $this->getMock('Magento\Tax\Helper\Data', [], [], '', false);
+ $this->adjustment = new Adjustment($this->taxHelper, $this->sortOrder);
+ }
+
public function testGetAdjustmentCode()
{
- // Instantiate/mock objects
- /** @var TaxHelper $taxHelper */
- $taxHelper = $this->getMockBuilder('Magento\Tax\Helper\Data')->disableOriginalConstructor()
- ->setMethods(array())
- ->getMock();
- $model = new Adjustment($taxHelper);
-
- // Run tested method
- $code = $model->getAdjustmentCode();
-
- // Check expectations
- $this->assertNotEmpty($code);
+ $this->assertEquals(Adjustment::ADJUSTMENT_CODE, $this->adjustment->getAdjustmentCode());
}
/**
- * @param bool $isPriceIncludesTax
+ * @param bool $expectedResult
* @dataProvider isIncludedInBasePriceDataProvider
*/
- public function testIsIncludedInBasePrice($isPriceIncludesTax)
+ public function testIsIncludedInBasePrice($expectedResult)
{
- // Instantiate/mock objects
- /** @var TaxHelper|\PHPUnit_Framework_MockObject_MockObject $taxHelper */
- $taxHelper = $this->getMockBuilder('Magento\Tax\Helper\Data')->disableOriginalConstructor()
- ->setMethods(array('priceIncludesTax'))
- ->getMock();
- $model = new Adjustment($taxHelper);
-
- // Avoid execution of irrelevant functionality
- $taxHelper->expects($this->any())->method('priceIncludesTax')->will($this->returnValue($isPriceIncludesTax));
-
- // Run tested method
- $result = $model->isIncludedInBasePrice();
-
- // Check expectations
- $this->assertInternalType('bool', $result);
- $this->assertEquals($isPriceIncludesTax, $result);
+ $this->taxHelper->expects($this->once())
+ ->method('priceIncludesTax')
+ ->will($this->returnValue($expectedResult));
+ $this->assertEquals($expectedResult, $this->adjustment->isIncludedInBasePrice());
}
public function isIncludedInBasePriceDataProvider()
@@ -79,27 +76,16 @@ public function isIncludedInBasePriceDataProvider()
*/
public function testIsIncludedInDisplayPrice($displayPriceIncludingTax, $displayBothPrices, $expectedResult)
{
- // Instantiate/mock objects
- /** @var TaxHelper|\PHPUnit_Framework_MockObject_MockObject $taxHelper */
- $taxHelper = $this->getMockBuilder('Magento\Tax\Helper\Data')->disableOriginalConstructor()
- ->setMethods(array('displayPriceIncludingTax', 'displayBothPrices'))
- ->getMock();
-
- // Avoid execution of irrelevant functionality
- $taxHelper->expects($this->any())
+ $this->taxHelper->expects($this->once())
->method('displayPriceIncludingTax')
->will($this->returnValue($displayPriceIncludingTax));
- $taxHelper->expects($this->any())
- ->method('displayBothPrices')
- ->will($this->returnValue($displayBothPrices));
+ if (!$displayPriceIncludingTax) {
+ $this->taxHelper->expects($this->once())
+ ->method('displayBothPrices')
+ ->will($this->returnValue($displayBothPrices));
+ }
- $model = new Adjustment($taxHelper);
- // Run tested method
- $result = $model->isIncludedInDisplayPrice();
-
- // Check expectations
- $this->assertInternalType('bool', $result);
- $this->assertEquals($expectedResult, $result);
+ $this->assertEquals($expectedResult, $this->adjustment->isIncludedInDisplayPrice());
}
/**
@@ -124,30 +110,17 @@ public function isIncludedInDisplayPriceDataProvider()
*/
public function testExtractAdjustment($isPriceIncludesTax, $amount, $price, $expectedResult)
{
- // Instantiate/mock objects
- /** @var TaxHelper|\PHPUnit_Framework_MockObject_MockObject $taxHelper */
- $taxHelper = $this->getMockBuilder('Magento\Tax\Helper\Data')->disableOriginalConstructor()
- ->setMethods(array('priceIncludesTax', 'getPrice'))
- ->getMock();
- /** @var SaleableInterface|\PHPUnit_Framework_MockObject_MockObject $taxHelper */
- $object = $this->getMockBuilder('Magento\Framework\Pricing\Object\SaleableInterface')->getMock();
- $model = new Adjustment($taxHelper);
+ $object = $this->getMockForAbstractClass('Magento\Framework\Pricing\Object\SaleableInterface');
- // Avoid execution of irrelevant functionality
- $taxHelper->expects($this->any())
+ $this->taxHelper->expects($this->any())
->method('priceIncludesTax')
->will($this->returnValue($isPriceIncludesTax));
- $taxHelper->expects($this->any())
+ $this->taxHelper->expects($this->any())
->method('getPrice')
->with($object, $amount)
->will($this->returnValue($price));
- // Run tested method
- $result = $model->extractAdjustment($amount, $object);
-
- // Check expectations
- $this->assertInternalType('float', $result);
- $this->assertEquals($expectedResult, $result);
+ $this->assertEquals($expectedResult, $this->adjustment->extractAdjustment($amount, $object));
}
public function extractAdjustmentDataProvider()
@@ -169,30 +142,17 @@ public function extractAdjustmentDataProvider()
*/
public function testApplyAdjustment($isPriceIncludesTax, $amount, $price, $expectedResult)
{
- // Instantiate/mock objects
- /** @var TaxHelper|\PHPUnit_Framework_MockObject_MockObject $taxHelper */
- $taxHelper = $this->getMockBuilder('Magento\Tax\Helper\Data')->disableOriginalConstructor()
- ->setMethods(array('priceIncludesTax', 'getPrice'))
- ->getMock();
- /** @var SaleableInterface|\PHPUnit_Framework_MockObject_MockObject $taxHelper */
$object = $this->getMockBuilder('Magento\Framework\Pricing\Object\SaleableInterface')->getMock();
- $model = new Adjustment($taxHelper);
- // Avoid execution of irrelevant functionality
- $taxHelper->expects($this->any())
+ $this->taxHelper->expects($this->any())
->method('priceIncludesTax')
->will($this->returnValue($isPriceIncludesTax));
- $taxHelper->expects($this->any())
+ $this->taxHelper->expects($this->any())
->method('getPrice')
->with($object, $amount, !$isPriceIncludesTax)
->will($this->returnValue($price));
- // Run tested method
- $result = $model->applyAdjustment($amount, $object);
-
- // Check expectations
- $this->assertInternalType('float', $result);
- $this->assertEquals($expectedResult, $result);
+ $this->assertEquals($expectedResult, $this->adjustment->applyAdjustment($amount, $object));
}
/**
@@ -207,20 +167,26 @@ public function applyAdjustmentDataProvider()
];
}
- public function testIsExcludedWith()
+ /**
+ * @dataProvider isExcludedWithDataProvider
+ * @param string $adjustmentCode
+ * @param bool $expectedResult
+ */
+ public function testIsExcludedWith($adjustmentCode, $expectedResult)
{
- $adjustmentCode = 'some_random_adjustment_code123';
-
- // Instantiate/mock objects
- /** @var TaxHelper|\PHPUnit_Framework_MockObject_MockObject $taxHelper */
- $taxHelper = $this->getMockBuilder('Magento\Tax\Helper\Data')->disableOriginalConstructor()->getMock();
- $model = new Adjustment($taxHelper);
+ $this->assertEquals($expectedResult, $this->adjustment->isExcludedWith($adjustmentCode));
+ }
- // Run tested method
- $result = $model->isExcludedWith($adjustmentCode);
+ public function isExcludedWithDataProvider()
+ {
+ return [
+ [Adjustment::ADJUSTMENT_CODE, true],
+ ['not_tax', false]
+ ];
+ }
- // Check expectations
- $this->assertInternalType('bool', $result);
- $this->assertFalse($result);
+ public function testGetSortOrder()
+ {
+ $this->assertEquals($this->sortOrder, $this->adjustment->getSortOrder());
}
}
diff --git a/dev/tests/unit/testsuite/Magento/Tax/Pricing/Price/Plugin/AttributePriceTest.php b/dev/tests/unit/testsuite/Magento/Tax/Pricing/Price/Plugin/AttributePriceTest.php
new file mode 100644
index 0000000000000..106743426db35
--- /dev/null
+++ b/dev/tests/unit/testsuite/Magento/Tax/Pricing/Price/Plugin/AttributePriceTest.php
@@ -0,0 +1,175 @@
+taxHelperMock = $this->getMock(
+ 'Magento\Tax\Helper\Data',
+ ['displayPriceIncludingTax', 'displayBothPrices'],
+ [],
+ '',
+ false,
+ false
+ );
+ $this->calculationMock = $this->getMock(
+ 'Magento\Tax\Model\Calculation',
+ ['getRate', 'getRateRequest', '__wakeup'],
+ [],
+ '',
+ false,
+ false
+ );
+ $this->productMock = $this->getMock(
+ 'Magento\Catalog\Model\Product',
+ ['__wakeup', 'getTaxClassId', 'getPriceInfo'],
+ [],
+ '',
+ false,
+ false
+ );
+ $this->priceInfoMock = $this->getMock(
+ 'Magento\Framework\Pricing\PriceInfo\Base',
+ ['getAdjustment'],
+ [],
+ '',
+ false,
+ false
+ );
+ $this->adjustmentMock = $this->getMock(
+ 'Magento\Tax\Pricing\Adjustment',
+ ['isIncludedInBasePrice'],
+ [],
+ '',
+ false,
+ false
+ );
+ $this->rateRequestMock = $this->getMock(
+ 'Magento\Object',
+ ['setProductClassId', '__wakeup'],
+ [],
+ '',
+ false,
+ false
+ );
+ $this->attributePriceMock = $this->getMock(
+ 'Magento\ConfigurableProduct\Pricing\Price\AttributePrice',
+ [],
+ [],
+ '',
+ false,
+ false
+ );
+
+ $this->plugin = new \Magento\Tax\Pricing\Price\Plugin\AttributePrice(
+ $this->taxHelperMock,
+ $this->calculationMock
+ );
+
+
+ }
+
+ /**
+ * test for method afterPrepareAdjustmentConfig
+ */
+ public function testAfterPrepareAdjustmentConfig()
+ {
+ $this->productMock->expects($this->once())
+ ->method('getTaxClassId')
+ ->will($this->returnValue('tax-class-id'));
+ $this->calculationMock->expects($this->exactly(2))
+ ->method('getRateRequest')
+ ->will($this->returnValue($this->rateRequestMock));
+ $this->calculationMock->expects($this->exactly(2))
+ ->method('getRate')
+ ->with($this->equalTo($this->rateRequestMock))
+ ->will($this->returnValue(99.10));
+ $this->productMock->expects($this->once())
+ ->method('getPriceInfo')
+ ->will($this->returnValue($this->priceInfoMock));
+ $this->priceInfoMock->expects($this->once())
+ ->method('getAdjustment')
+ ->with($this->equalTo(\Magento\Tax\Pricing\Adjustment::ADJUSTMENT_CODE))
+ ->will($this->returnValue($this->adjustmentMock));
+ $this->adjustmentMock->expects($this->once())
+ ->method('isIncludedInBasePrice')
+ ->will($this->returnValue(true));
+ $this->taxHelperMock->expects($this->once())
+ ->method('displayPriceIncludingTax')
+ ->will($this->returnValue(true));
+ $this->taxHelperMock->expects($this->once())
+ ->method('displayBothPrices')
+ ->will($this->returnValue(true));
+
+ $expected = [
+ 'product' => $this->productMock,
+ 'defaultTax' => 99.10,
+ 'currentTax' => 99.10,
+ 'includeTax' => true,
+ 'showIncludeTax' => true,
+ 'showBothPrices' => true
+ ];
+
+ $this->assertEquals($expected, $this->plugin->afterPrepareAdjustmentConfig($this->attributePriceMock, [
+ 'product' => $this->productMock,
+ 'defaultTax' => 0,
+ 'currentTax' => 0
+ ]));
+ }
+}
diff --git a/dev/tests/unit/testsuite/Magento/Tax/Pricing/Render/AdjustmentTest.php b/dev/tests/unit/testsuite/Magento/Tax/Pricing/Render/AdjustmentTest.php
index 1050a4d333398..34febddc00268 100644
--- a/dev/tests/unit/testsuite/Magento/Tax/Pricing/Render/AdjustmentTest.php
+++ b/dev/tests/unit/testsuite/Magento/Tax/Pricing/Render/AdjustmentTest.php
@@ -36,14 +36,14 @@ class AdjustmentTest extends \PHPUnit_Framework_TestCase
/**
* Price currency model mock
*
- * @var \Magento\Directory\Model\PriceCurrency
+ * @var \Magento\Directory\Model\PriceCurrency | \PHPUnit_Framework_MockObject_MockObject
*/
protected $priceCurrencyMock;
/**
* Price helper mock
*
- * @var \Magento\Tax\Helper\Data
+ * @var \Magento\Tax\Helper\Data | \PHPUnit_Framework_MockObject_MockObject
*/
protected $taxHelperMock;
@@ -104,7 +104,7 @@ public function setUp()
*/
public function testGetAdjustmentCode()
{
- $this->assertEquals(\Magento\Tax\Pricing\Adjustment::CODE, $this->model->getAdjustmentCode());
+ $this->assertEquals(\Magento\Tax\Pricing\Adjustment::ADJUSTMENT_CODE, $this->model->getAdjustmentCode());
}
/**
@@ -292,4 +292,93 @@ public function testDisplayPriceExcludingTax()
$this->assertEquals($expectedResult, $result);
}
+
+ public function testGetHtmlExcluding()
+ {
+ $arguments = [];
+ $totalDisplayValue = 10.0;
+ $taxAdjustment = 2.0;
+ $displayValue = 8.0;
+
+ $amountRender = $this->getMockForAbstractClass('Magento\Framework\Pricing\Render\AmountRenderInterface');
+ $amountMock = $this->getMockForAbstractClass('Magento\Framework\Pricing\Amount\AmountInterface');
+ $amountMock->expects($this->once())
+ ->method('getAdjustmentAmount')
+ ->with(\Magento\Tax\Pricing\Adjustment::ADJUSTMENT_CODE)
+ ->will($this->returnValue($taxAdjustment));
+
+ $this->taxHelperMock->expects($this->once())
+ ->method('displayBothPrices')
+ ->will($this->returnValue(false));
+ $this->taxHelperMock->expects($this->once())
+ ->method('displayPriceExcludingTax')
+ ->will($this->returnValue(true));
+
+ $amountRender->expects($this->at(0))
+ ->method('getDisplayValue')
+ ->will($this->returnValue($totalDisplayValue));
+ $amountRender->expects($this->at(1))
+ ->method('getAmount')
+ ->will($this->returnValue($amountMock));
+ $amountRender->expects($this->at(2))
+ ->method('setDisplayValue')
+ ->with($displayValue);
+
+ $this->model->render($amountRender, $arguments);
+ }
+
+ public function testGetHtmlBoth()
+ {
+ $arguments = [];
+ $totalDisplayValue = 10.0;
+ $taxAdjustment = 2.0;
+ $displayValue = 8.0;
+ $this->model->setZone(\Magento\Framework\Pricing\Render::ZONE_ITEM_VIEW);
+
+ $amountRender = $this->getMock(
+ 'Magento\Framework\Pricing\Render\Amount',
+ [
+ 'setPriceDisplayLabel',
+ 'setPriceId',
+ 'getSaleableItem',
+ 'getDisplayValue',
+ 'getAmount',
+ 'setDisplayValue'
+ ],
+ [],
+ '',
+ false
+ );
+ $amountMock = $this->getMockForAbstractClass('Magento\Framework\Pricing\Amount\AmountInterface');
+ $amountMock->expects($this->once())
+ ->method('getAdjustmentAmount')
+ ->with(\Magento\Tax\Pricing\Adjustment::ADJUSTMENT_CODE)
+ ->will($this->returnValue($taxAdjustment));
+ $product = $this->getMockForAbstractClass('Magento\Framework\Pricing\Object\SaleableInterface');
+ $product->expects($this->once())
+ ->method('getId');
+
+ $this->taxHelperMock->expects($this->once())
+ ->method('displayBothPrices')
+ ->will($this->returnValue(true));
+
+ $amountRender->expects($this->at(0))
+ ->method('setPriceDisplayLabel');
+ $amountRender->expects($this->at(1))
+ ->method('getSaleableItem')
+ ->will($this->returnValue($product));
+ $amountRender->expects($this->at(2))
+ ->method('setPriceId');
+ $amountRender->expects($this->at(3))
+ ->method('getDisplayValue')
+ ->will($this->returnValue($totalDisplayValue));
+ $amountRender->expects($this->at(4))
+ ->method('getAmount')
+ ->will($this->returnValue($amountMock));
+ $amountRender->expects($this->at(5))
+ ->method('setDisplayValue')
+ ->with($displayValue);
+
+ $this->model->render($amountRender, $arguments);
+ }
}
diff --git a/dev/tests/unit/testsuite/Magento/Usps/Model/CarrierTest.php b/dev/tests/unit/testsuite/Magento/Usps/Model/CarrierTest.php
index 442dc5377519e..3c1021d7132f5 100644
--- a/dev/tests/unit/testsuite/Magento/Usps/Model/CarrierTest.php
+++ b/dev/tests/unit/testsuite/Magento/Usps/Model/CarrierTest.php
@@ -165,8 +165,10 @@ public function testCollectRates()
$this->returnValue(file_get_contents(__DIR__ . '/_files/success_usps_response_rates.xml'))
);
// for setRequest
- $request_params = include __DIR__ . '/_files/rates_request_data.php';
- $request = $this->_helper->getObject('Magento\Sales\Model\Quote\Address\RateRequest', $request_params);
+ $request = $this->_helper->getObject(
+ 'Magento\Sales\Model\Quote\Address\RateRequest',
+ require __DIR__ . '/_files/rates_request_data.php'
+ );
$this->assertNotEmpty($this->_model->collectRates($request)->getAllRates());
}
@@ -180,8 +182,10 @@ public function testReturnOfShipment()
)->will(
$this->returnValue(file_get_contents(__DIR__ . '/_files/success_usps_response_return_shipment.xml'))
);
- $request_params = include __DIR__ . '/_files/return_shipment_request_data.php';
- $request = $this->_helper->getObject('Magento\Shipping\Model\Shipment\ReturnShipment', $request_params);
+ $request = $this->_helper->getObject(
+ 'Magento\Shipping\Model\Shipment\ReturnShipment',
+ require __DIR__ . '/_files/return_shipment_request_data.php'
+ );
$this->assertNotEmpty($this->_model->returnOfShipment($request)->getInfo()[0]['tracking_number']);
}
diff --git a/dev/tests/unit/testsuite/Magento/Weee/Pricing/AdjustmentTest.php b/dev/tests/unit/testsuite/Magento/Weee/Pricing/AdjustmentTest.php
index 0edb70d9d4e37..9e711679a93b9 100644
--- a/dev/tests/unit/testsuite/Magento/Weee/Pricing/AdjustmentTest.php
+++ b/dev/tests/unit/testsuite/Magento/Weee/Pricing/AdjustmentTest.php
@@ -29,34 +29,35 @@
class AdjustmentTest extends \PHPUnit_Framework_TestCase
{
+ /**
+ * @var Adjustment
+ */
+ protected $adjustment;
+
+ /**
+ * @var \Magento\Weee\Helper\Data | \PHPUnit_Framework_MockObject_MockObject
+ */
+ protected $weeeHelper;
+
+ /**
+ * @var int
+ */
+ protected $sortOrder = 5;
+
+ public function setUp()
+ {
+ $this->weeeHelper = $this->getMock('Magento\Weee\Helper\Data', [], [], '', false);
+ $this->adjustment = new Adjustment($this->weeeHelper, $this->sortOrder);
+ }
+
public function testGetAdjustmentCode()
{
- // Instantiate/mock objects
- /** @var WeeeHelper $weeHelper */
- $weeHelper = $this->getMockBuilder('Magento\Weee\Helper\Data')->disableOriginalConstructor()
- ->setMethods(array())
- ->getMock();
- $model = new Adjustment($weeHelper);
-
- // Run tested method
- $code = $model->getAdjustmentCode();
-
- // Check expectations
- $this->assertNotEmpty($code);
+ $this->assertEquals(Adjustment::ADJUSTMENT_CODE, $this->adjustment->getAdjustmentCode());
}
public function testIsIncludedInBasePrice()
{
- // Instantiate/mock objects
- /** @var WeeeHelper|\PHPUnit_Framework_MockObject_MockObject $weeeHelper */
- $weeeHelper = $this->getMockBuilder('Magento\Weee\Helper\Data')->disableOriginalConstructor()->getMock();
- $model = new Adjustment($weeeHelper);
-
- // Run tested method
- $result = $model->isIncludedInBasePrice();
-
- // Check expectations
- $this->assertInternalType('bool', $result);
+ $this->assertFalse($this->adjustment->isIncludedInBasePrice());
}
/**
@@ -64,34 +65,17 @@ public function testIsIncludedInBasePrice()
*/
public function testIsIncludedInDisplayPrice($expectedResult)
{
- // Instantiate/mock objects
- /** @var WeeeHelper|\PHPUnit_Framework_MockObject_MockObject $weeeHelper */
- $weeeHelper = $this->getMockBuilder('Magento\Weee\Helper\Data')->disableOriginalConstructor()
- ->setMethods(array('typeOfDisplay'))
- ->getMock();
- $model = new Adjustment($weeeHelper);
-
- // Avoid execution of irrelevant functionality
- $weeeHelper->expects($this->any())
+ $displayTypes = [
+ \Magento\Weee\Model\Tax::DISPLAY_INCL,
+ \Magento\Weee\Model\Tax::DISPLAY_INCL_DESCR,
+ \Magento\Weee\Model\Tax::DISPLAY_EXCL_DESCR_INCL
+ ];
+ $this->weeeHelper->expects($this->any())
->method('typeOfDisplay')
- ->with(
- $this->equalTo(
- [
- \Magento\Weee\Model\Tax::DISPLAY_INCL,
- \Magento\Weee\Model\Tax::DISPLAY_INCL_DESCR,
- \Magento\Weee\Model\Tax::DISPLAY_EXCL_DESCR_INCL,
- 4
- ]
- )
- )
+ ->with($displayTypes)
->will($this->returnValue($expectedResult));
- // Run tested method
- $result = $model->isIncludedInDisplayPrice();
-
- // Check expectations
- $this->assertInternalType('bool', $result);
- $this->assertEquals($expectedResult, $result);
+ $this->assertEquals($expectedResult, $this->adjustment->isIncludedInDisplayPrice());
}
/**
@@ -109,26 +93,14 @@ public function isIncludedInDisplayPriceDataProvider()
*/
public function testExtractAdjustment($amount, $expectedResult)
{
- // Instantiate/mock objects
- /** @var WeeeHelper|\PHPUnit_Framework_MockObject_MockObject $weeeHelper */
- $weeeHelper = $this->getMockBuilder('Magento\Weee\Helper\Data')->disableOriginalConstructor()
- ->setMethods(array('getAmount'))
- ->getMock();
- /** @var SaleableInterface|\PHPUnit_Framework_MockObject_MockObject $saleableItem */
- $saleableItem = $this->getMockBuilder('Magento\Framework\Pricing\Object\SaleableInterface')->getMock();
- $model = new Adjustment($weeeHelper);
-
- // Avoid execution of irrelevant functionality
- $weeeHelper->expects($this->any())
+ $saleableItem = $this->getMockForAbstractClass('Magento\Framework\Pricing\Object\SaleableInterface');
+
+ $this->weeeHelper->expects($this->any())
->method('getAmount')
+ ->with($saleableItem)
->will($this->returnValue($amount));
- // Run tested method
- $result = $model->extractAdjustment('anything_here', $saleableItem);
-
- // Check expectations
- $this->assertInternalType('float', $result);
- $this->assertEquals($expectedResult, $result);
+ $this->assertEquals($expectedResult, $this->adjustment->extractAdjustment($amount, $saleableItem));
}
/**
@@ -150,26 +122,13 @@ public function extractAdjustmentDataProvider()
*/
public function testApplyAdjustment($amount, $amountOld, $expectedResult)
{
- // Instantiate/mock objects
- /** @var WeeeHelper|\PHPUnit_Framework_MockObject_MockObject $weeeHelper */
- $weeeHelper = $this->getMockBuilder('Magento\Weee\Helper\Data')->disableOriginalConstructor()
- ->setMethods(array('getAmount'))
- ->getMock();
- /** @var SaleableInterface|\PHPUnit_Framework_MockObject_MockObject $taxHelper */
- $object = $this->getMockBuilder('Magento\Framework\Pricing\Object\SaleableInterface')->getMock();
- $model = new Adjustment($weeeHelper);
-
- // Avoid execution of irrelevant functionality
- $weeeHelper->expects($this->any())
+ $object = $this->getMockForAbstractClass('Magento\Framework\Pricing\Object\SaleableInterface');
+
+ $this->weeeHelper->expects($this->any())
->method('getAmount')
->will($this->returnValue($amountOld));
- // Run tested method
- $result = $model->applyAdjustment($amount, $object);
-
- // Check expectations
- $this->assertInternalType('float', $result);
- $this->assertEquals($expectedResult, $result);
+ $this->assertEquals($expectedResult, $this->adjustment->applyAdjustment($amount, $object));
}
/**
@@ -184,20 +143,44 @@ public function applyAdjustmentDataProvider()
];
}
- public function testIsExcludedWith()
+ /**
+ * @dataProvider isExcludedWithDataProvider
+ * @param string $adjustmentCode
+ * @param bool $expectedResult
+ */
+ public function testIsExcludedWith($adjustmentCode, $expectedResult)
{
- $adjustmentCode = 'some_random_adjustment_code123';
+ $this->assertEquals($expectedResult, $this->adjustment->isExcludedWith($adjustmentCode));
+ }
- // Instantiate/mock objects
- /** @var WeeeHelper|\PHPUnit_Framework_MockObject_MockObject $weeeHelper */
- $weeeHelper = $this->getMockBuilder('Magento\Weee\Helper\Data')->disableOriginalConstructor()->getMock();
- $model = new Adjustment($weeeHelper);
+ public function isExcludedWithDataProvider()
+ {
+ return [
+ ['weee', true],
+ ['tax', true],
+ ['not_tax_and_not_weee', false]
+ ];
+ }
- // Run tested method
- $result = $model->isExcludedWith($adjustmentCode);
+ /**
+ * @dataProvider getSortOrderProvider
+ * @param bool $isTaxable
+ * @param int $expectedResult
+ */
+ public function testGetSortOrder($isTaxable, $expectedResult)
+ {
+ $this->weeeHelper->expects($this->any())
+ ->method('isTaxable')
+ ->will($this->returnValue($isTaxable));
+
+ $this->assertEquals($expectedResult, $this->adjustment->getSortOrder());
+ }
- // Check expectations
- $this->assertInternalType('bool', $result);
- $this->assertFalse($result);
+ public function getSortOrderProvider()
+ {
+ return [
+ [true, $this->sortOrder],
+ [false, -1]
+ ];
}
}
diff --git a/dev/tests/unit/testsuite/Magento/Weee/Pricing/Render/AdjustmentTest.php b/dev/tests/unit/testsuite/Magento/Weee/Pricing/Render/AdjustmentTest.php
index 0b75a622ed690..ca5c52ed5b9f9 100644
--- a/dev/tests/unit/testsuite/Magento/Weee/Pricing/Render/AdjustmentTest.php
+++ b/dev/tests/unit/testsuite/Magento/Weee/Pricing/Render/AdjustmentTest.php
@@ -103,7 +103,7 @@ public function setUp()
*/
public function testGetAdjustmentCode()
{
- $this->assertEquals(\Magento\Weee\Pricing\Adjustment::CODE, $this->model->getAdjustmentCode());
+ $this->assertEquals(\Magento\Weee\Pricing\Adjustment::ADJUSTMENT_CODE, $this->model->getAdjustmentCode());
}
/**
diff --git a/dev/tools/Magento/Tools/Dependency/generate/bootstrap.php b/dev/tools/Magento/Tools/Dependency/generate/bootstrap.php
index feed42696b77a..88d4e6ed57b5d 100644
--- a/dev/tools/Magento/Tools/Dependency/generate/bootstrap.php
+++ b/dev/tools/Magento/Tools/Dependency/generate/bootstrap.php
@@ -25,10 +25,6 @@
define('BP', realpath(__DIR__ . '/../../../../../../') . '/');
require_once BP . 'app/autoload.php';
-\Magento\Framework\Autoload\IncludePath::addIncludePath(
- array(
- BP . 'dev/tests/static/framework',
- BP . 'dev/tools',
- BP . '/lib'
- )
+(new \Magento\Framework\Autoload\IncludePath())->addIncludePath(
+ array(BP . 'dev/tests/static/framework', BP . 'dev/tools', BP . '/lib')
);
diff --git a/dev/tools/Magento/Tools/Di/compiler.php b/dev/tools/Magento/Tools/Di/compiler.php
index 00ed524ed74fa..c9e9cfb26c423 100644
--- a/dev/tools/Magento/Tools/Di/compiler.php
+++ b/dev/tools/Magento/Tools/Di/compiler.php
@@ -49,7 +49,7 @@
$opt->parse();
$generationDir = $opt->getOption('generation') ? $opt->getOption('generation') : $rootDir . '/var/generation';
- \Magento\Framework\Autoload\IncludePath::addIncludePath($generationDir);
+ (new \Magento\Framework\Autoload\IncludePath())->addIncludePath($generationDir);
$diDir = $opt->getOption('di') ? $opt->getOption('di') : $rootDir . '/var/di';
$compiledFile = $diDir . '/definitions.php';
diff --git a/dev/tools/Magento/Tools/Di/entity_generator.php b/dev/tools/Magento/Tools/Di/entity_generator.php
index 9e04221f15668..84ab6640ec8fd 100644
--- a/dev/tools/Magento/Tools/Di/entity_generator.php
+++ b/dev/tools/Magento/Tools/Di/entity_generator.php
@@ -73,7 +73,7 @@
exit($example);
}
-\Magento\Framework\Autoload\IncludePath::addIncludePath($generationDir);
+(new \Magento\Framework\Autoload\IncludePath())->addIncludePath($generationDir);
//reinit generator with correct generation path
$io = new \Magento\Framework\Code\Generator\Io(new \Magento\Framework\Filesystem\Driver\File(), null, $generationDir);
diff --git a/dev/tools/Magento/Tools/Layout/xmlUpdater.php b/dev/tools/Magento/Tools/Layout/xmlUpdater.php
index 385577a07dd38..89c4522dd41ca 100644
--- a/dev/tools/Magento/Tools/Layout/xmlUpdater.php
+++ b/dev/tools/Magento/Tools/Layout/xmlUpdater.php
@@ -26,7 +26,7 @@
require_once $basePath . '/app/autoload.php';
require __DIR__ . '/Formatter.php';
-\Magento\Framework\Autoload\IncludePath::addIncludePath(array($basePath . '/lib'));
+(new \Magento\Framework\Autoload\IncludePath())->addIncludePath(array($basePath . '/lib'));
try {
$opt = new \Zend_Console_Getopt(
diff --git a/dev/tools/Magento/Tools/Migration/Acl/db.php b/dev/tools/Magento/Tools/Migration/Acl/db.php
index 85f3bdf94039e..abf7626b4b3cd 100644
--- a/dev/tools/Magento/Tools/Migration/Acl/db.php
+++ b/dev/tools/Magento/Tools/Migration/Acl/db.php
@@ -26,7 +26,7 @@
$rootDir = realpath(__DIR__ . '/../../../..');
require $rootDir . '/app/autoload.php';
-\Magento\Framework\Autoload\IncludePath::addIncludePath(array($rootDir . '/lib', $rootDir . '/dev'));
+(new \Magento\Framework\Autoload\IncludePath())->addIncludePath(array($rootDir . '/lib', $rootDir . '/dev'));
$defaultReportFile = 'report.log';
try {
diff --git a/dev/tools/Magento/Tools/Migration/system_config.php b/dev/tools/Magento/Tools/Migration/system_config.php
index 0229cb8465ee1..0a75b4414ad64 100644
--- a/dev/tools/Magento/Tools/Migration/system_config.php
+++ b/dev/tools/Magento/Tools/Migration/system_config.php
@@ -23,7 +23,6 @@
* @copyright Copyright (c) 2014 X.commerce, Inc. (http://www.magentocommerce.com)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/
-
use Magento\Framework\Autoload\IncludePath;
use Magento\Tools\Migration\System\Configuration\Formatter;
use Magento\Tools\Migration\System\Configuration\Generator;
@@ -40,7 +39,7 @@
$rootDir = realpath(__DIR__ . '../../../../../../');
require __DIR__ . '/../../../../../app/autoload.php';
-IncludePath::addIncludePath(array($rootDir . '/lib', $rootDir . '/dev/tools'));
+(new IncludePath())->addIncludePath(array($rootDir . '/lib', $rootDir . '/dev'));
$defaultReportFile = 'report.log';
try {
diff --git a/dev/tools/Magento/Tools/View/generator.php b/dev/tools/Magento/Tools/View/generator.php
index 6146d28c124c8..cc7d2193f934f 100644
--- a/dev/tools/Magento/Tools/View/generator.php
+++ b/dev/tools/Magento/Tools/View/generator.php
@@ -28,7 +28,7 @@
*/
require __DIR__ . '/../../../../../app/bootstrap.php';
-\Magento\Framework\Autoload\IncludePath::addIncludePath(__DIR__ . '/../../../');
+(new \Magento\Framework\Autoload\IncludePath())->addIncludePath(__DIR__ . '/../../../');
/**
* Command line usage help
diff --git a/dev/tools/bootstrap.php b/dev/tools/bootstrap.php
index 7dc8a7ab85e48..851c4dd51fd19 100644
--- a/dev/tools/bootstrap.php
+++ b/dev/tools/bootstrap.php
@@ -23,7 +23,7 @@
*/
require_once __DIR__ . '/../../app/autoload.php';
define('BP', __DIR__ . '/../..');
-\Magento\Framework\Autoload\IncludePath::addIncludePath(
+(new \Magento\Framework\Autoload\IncludePath())->addIncludePath(
array(
BP . '/app/code',
BP . '/lib',
diff --git a/dev/tools/layout/xml-updater.php b/dev/tools/layout/xml-updater.php
index d8f78e3b800ec..6179cb4edb690 100644
--- a/dev/tools/layout/xml-updater.php
+++ b/dev/tools/layout/xml-updater.php
@@ -26,7 +26,7 @@
require_once $basePath . '/app/autoload.php';
require __DIR__ . '/Formatter.php';
-\Magento\Framework\Autoload\IncludePath::addIncludePath(array(
+(new \Magento\Framework\Autoload\IncludePath())->addIncludePath(array(
$basePath . '/lib',
));
diff --git a/lib/Magento/Framework/App/Http.php b/lib/Magento/Framework/App/Http.php
index 7b580f0c9b4e5..7048fd52ddfa2 100644
--- a/lib/Magento/Framework/App/Http.php
+++ b/lib/Magento/Framework/App/Http.php
@@ -144,7 +144,7 @@ public function launch()
}
}
require_once $this->_filesystem->getPath(Filesystem::PUB_DIR) . '/errors/report.php';
- $processor = new \Error_Processor($this->_response);
+ $processor = new \Magento\Framework\Error\Processor($this->_response);
$processor->saveReport($reportData);
$this->_response = $processor->processReport();
}
diff --git a/lib/Magento/Framework/App/ObjectManagerFactory.php b/lib/Magento/Framework/App/ObjectManagerFactory.php
index 7e4db4d5e8539..583e8b40dcadf 100644
--- a/lib/Magento/Framework/App/ObjectManagerFactory.php
+++ b/lib/Magento/Framework/App/ObjectManagerFactory.php
@@ -73,7 +73,7 @@ public function create($rootDir, array $arguments, $useCompiled = true)
) ? $arguments[Filesystem::PARAM_APP_DIRS] : array();
$directoryList = new DirectoryList($rootDir, $directories);
- \Magento\Framework\Autoload\IncludePath::addIncludePath(
+ (new \Magento\Framework\Autoload\IncludePath())->addIncludePath(
array($directoryList->getDir(Filesystem::GENERATION_DIR))
);
diff --git a/lib/Magento/Framework/AppInterface.php b/lib/Magento/Framework/AppInterface.php
index 27d31ec50a9c8..aa8866c27a151 100644
--- a/lib/Magento/Framework/AppInterface.php
+++ b/lib/Magento/Framework/AppInterface.php
@@ -35,7 +35,7 @@ interface AppInterface
/**
* Magento version
*/
- const VERSION = '2.0.0.0-dev75';
+ const VERSION = '2.0.0.0-dev76';
/**
* Launch application
diff --git a/lib/Magento/Framework/Autoload/IncludePath.php b/lib/Magento/Framework/Autoload/IncludePath.php
index 2fe513e6cafb1..9c01fcad1a052 100644
--- a/lib/Magento/Framework/Autoload/IncludePath.php
+++ b/lib/Magento/Framework/Autoload/IncludePath.php
@@ -38,9 +38,9 @@ class IncludePath
* @param string $class
* @return string|bool
*/
- public static function getFile($class)
+ public function getFile($class)
{
- $relativePath = self::getFilePath($class);
+ $relativePath = $this->getFilePath($class);
return stream_resolve_include_path($relativePath);
}
@@ -51,7 +51,7 @@ public static function getFile($class)
* @param string $class
* @return string
*/
- public static function getFilePath($class)
+ public function getFilePath($class)
{
if (strpos($class, self::NS_SEPARATOR) !== false) {
$class = ltrim(str_replace(self::NS_SEPARATOR, '_', $class), '_');
@@ -66,7 +66,7 @@ public static function getFilePath($class)
* @param bool $prepend Whether to prepend paths or to append them
* @return void
*/
- public static function addIncludePath($path, $prepend = true)
+ public function addIncludePath($path, $prepend = true)
{
$includePathExtra = implode(PATH_SEPARATOR, (array)$path);
$includePath = get_include_path();
@@ -85,9 +85,9 @@ public static function addIncludePath($path, $prepend = true)
* @param string $class
* @return void
*/
- public static function load($class)
+ public function load($class)
{
- $file = self::getFile($class);
+ $file = $this->getFile($class);
if ($file) {
include $file;
}
diff --git a/lib/Magento/Framework/Code/Generator.php b/lib/Magento/Framework/Code/Generator.php
index 9f0804de25ecf..058a23f7ed914 100644
--- a/lib/Magento/Framework/Code/Generator.php
+++ b/lib/Magento/Framework/Code/Generator.php
@@ -107,7 +107,7 @@ public function generateClass($className)
// check if file already exists
$autoloader = $this->_autoloader;
- if ($autoloader::getFile($className)) {
+ if ($autoloader->getFile($className)) {
return self::GENERATION_SKIP;
}
diff --git a/lib/Magento/Framework/Code/Generator/Autoloader.php b/lib/Magento/Framework/Code/Generator/Autoloader.php
index e8701863f41d3..c98b83ac674f0 100644
--- a/lib/Magento/Framework/Code/Generator/Autoloader.php
+++ b/lib/Magento/Framework/Code/Generator/Autoloader.php
@@ -48,7 +48,7 @@ public function load($className)
{
if (!class_exists($className)) {
if (\Magento\Framework\Code\Generator::GENERATION_SUCCESS === $this->_generator->generateClass($className)) {
- \Magento\Framework\Autoload\IncludePath::load($className);
+ (new \Magento\Framework\Autoload\IncludePath())->load($className);
}
}
}
diff --git a/lib/Magento/Framework/Code/Generator/EntityAbstract.php b/lib/Magento/Framework/Code/Generator/EntityAbstract.php
index c57eb698c7f2f..6f1cb6c1f62f8 100644
--- a/lib/Magento/Framework/Code/Generator/EntityAbstract.php
+++ b/lib/Magento/Framework/Code/Generator/EntityAbstract.php
@@ -288,13 +288,13 @@ protected function _validateData()
$filePath = stream_resolve_include_path(str_replace('_', '/', $controllerPath) . '.php');
$isSourceClassValid = !empty($filePath);
} else {
- $isSourceClassValid = $autoloader::getFile($sourceClassName);
+ $isSourceClassValid = $autoloader->getFile($sourceClassName);
}
if (!$isSourceClassValid) {
$this->_addError('Source class ' . $sourceClassName . ' doesn\'t exist.');
return false;
- } elseif ($autoloader::getFile($resultClassName)) {
+ } elseif ($autoloader->getFile($resultClassName)) {
$this->_addError('Result class ' . $resultClassName . ' already exists.');
return false;
} elseif (!$this->_ioObject->makeGenerationDirectory()) {
diff --git a/lib/Magento/Framework/Code/Generator/Io.php b/lib/Magento/Framework/Code/Generator/Io.php
index 57ff61a71d0da..5f4e0c85fe39a 100644
--- a/lib/Magento/Framework/Code/Generator/Io.php
+++ b/lib/Magento/Framework/Code/Generator/Io.php
@@ -107,7 +107,7 @@ public function getResultFileDirectory($className)
public function getResultFileName($className)
{
$autoloader = $this->_autoloader;
- $resultFileName = $autoloader::getFilePath($className);
+ $resultFileName = $autoloader->getFilePath($className);
return $this->_generationDirectory . $resultFileName;
}
diff --git a/lib/Magento/Framework/Data/Form/Element/Label.php b/lib/Magento/Framework/Data/Form/Element/Label.php
index 94fda10b579c5..5308d0b3d1c2e 100644
--- a/lib/Magento/Framework/Data/Form/Element/Label.php
+++ b/lib/Magento/Framework/Data/Form/Element/Label.php
@@ -59,8 +59,7 @@ public function __construct(
public function getElementHtml()
{
$html = $this->getBold() ? '
' : '
';
- $html .= $this->getEscapedValue();
- $html .= $this->getBold() ? '
' : '
';
+ $html .= $this->getEscapedValue() . '
';
$html .= $this->getAfterElementHtml();
return $html;
}
diff --git a/lib/Magento/Framework/Data/Form/Element/Note.php b/lib/Magento/Framework/Data/Form/Element/Note.php
index 91667b72ea96e..e4d7448632dd3 100644
--- a/lib/Magento/Framework/Data/Form/Element/Note.php
+++ b/lib/Magento/Framework/Data/Form/Element/Note.php
@@ -58,8 +58,13 @@ public function __construct(
*/
public function getElementHtml()
{
- $html = '
' . $this->getText() . '
';
- $html .= $this->getAfterElementHtml();
+ $html = $this->getBeforeElementHtml()
+ . '
'
+ . $this->getText()
+ . '
'
+ . $this->getAfterElementHtml();
return $html;
}
}
diff --git a/lib/Magento/Framework/Filesystem/File/ReadFactory.php b/lib/Magento/Framework/Filesystem/File/ReadFactory.php
index 83860377a334d..c3cef19a6cfdd 100644
--- a/lib/Magento/Framework/Filesystem/File/ReadFactory.php
+++ b/lib/Magento/Framework/Filesystem/File/ReadFactory.php
@@ -50,7 +50,8 @@ public function __construct(\Magento\Framework\Filesystem\DriverFactory $driverF
*/
public function create($path, $protocol = null, DriverInterface $driver = null)
{
- $driver = $protocol ? $this->driverFactory->get($protocol, get_class($driver)) : $driver;
+ $driverClassName = is_null($driver) ? null : get_class($driver);
+ $driver = $protocol ? $this->driverFactory->get($protocol, $driverClassName) : $driver;
return new \Magento\Framework\Filesystem\File\Read($path, $driver);
}
}
diff --git a/lib/Magento/Framework/Less/File/Source/Base.php b/lib/Magento/Framework/Less/File/Source/Base.php
index 42b50514f7227..2f03cd47f09f5 100644
--- a/lib/Magento/Framework/Less/File/Source/Base.php
+++ b/lib/Magento/Framework/Less/File/Source/Base.php
@@ -79,7 +79,7 @@ public function getFiles(ThemeInterface $theme, $filePath = '*')
continue;
}
$moduleFull = "{$matches['namespace']}_{$matches['module']}";
- $result[] = $this->fileFactory->create($filename, $moduleFull, $theme);
+ $result[] = $this->fileFactory->create($filename, $moduleFull);
}
return $result;
}
diff --git a/lib/Magento/Framework/Less/File/Source/Theme.php b/lib/Magento/Framework/Less/File/Source/Theme.php
index bf2f648195a9d..8f76b7c0fc0a3 100644
--- a/lib/Magento/Framework/Less/File/Source/Theme.php
+++ b/lib/Magento/Framework/Less/File/Source/Theme.php
@@ -75,7 +75,7 @@ public function getFiles(ThemeInterface $theme, $filePath = '*')
if (!preg_match($pattern, $filename, $matches)) {
continue;
}
- $result[] = $this->fileFactory->create($filename, $matches['moduleName'], $theme);
+ $result[] = $this->fileFactory->create($filename, $matches['moduleName']);
}
return $result;
diff --git a/lib/Magento/Framework/Pricing/Adjustment/AdjustmentInterface.php b/lib/Magento/Framework/Pricing/Adjustment/AdjustmentInterface.php
index a5398106eb74a..456c5ba99bfae 100644
--- a/lib/Magento/Framework/Pricing/Adjustment/AdjustmentInterface.php
+++ b/lib/Magento/Framework/Pricing/Adjustment/AdjustmentInterface.php
@@ -18,6 +18,8 @@
* versions in the future. If you wish to customize Magento for your
* needs please refer to http://www.magentocommerce.com for more information.
*
+ * @category Magento
+ * @package Magento_Pricing
* @copyright Copyright (c) 2014 X.commerce, Inc. (http://www.magentocommerce.com)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/
diff --git a/lib/Magento/Framework/Pricing/Adjustment/Calculator.php b/lib/Magento/Framework/Pricing/Adjustment/Calculator.php
index ae19f54451471..3c71b2e50f30e 100644
--- a/lib/Magento/Framework/Pricing/Adjustment/Calculator.php
+++ b/lib/Magento/Framework/Pricing/Adjustment/Calculator.php
@@ -18,6 +18,8 @@
* versions in the future. If you wish to customize Magento for your
* needs please refer to http://www.magentocommerce.com for more information.
*
+ * @category Magento
+ * @package Magento_Pricing
* @copyright Copyright (c) 2014 X.commerce, Inc. (http://www.magentocommerce.com)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/
@@ -46,6 +48,9 @@ public function __construct(AmountFactory $amountFactory)
}
/**
+ * Retrieve Amount object based on given float amount, product and exclude option.
+ * It is possible to pass "true" or adjustment code to exclude all or specific adjustment from an amount.
+ *
* @param float|string $amount
* @param SaleableInterface $saleableItem
* @param null|bool|string $exclude
diff --git a/lib/Magento/Framework/Pricing/Adjustment/CalculatorInterface.php b/lib/Magento/Framework/Pricing/Adjustment/CalculatorInterface.php
index c7dca4ea6afa8..1ce2dee55f85e 100644
--- a/lib/Magento/Framework/Pricing/Adjustment/CalculatorInterface.php
+++ b/lib/Magento/Framework/Pricing/Adjustment/CalculatorInterface.php
@@ -18,6 +18,8 @@
* versions in the future. If you wish to customize Magento for your
* needs please refer to http://www.magentocommerce.com for more information.
*
+ * @category Magento
+ * @package Magento_Pricing
* @copyright Copyright (c) 2014 X.commerce, Inc. (http://www.magentocommerce.com)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/
diff --git a/lib/Magento/Framework/Pricing/Adjustment/Collection.php b/lib/Magento/Framework/Pricing/Adjustment/Collection.php
index 7c0f33fdadbb0..7bc6a43b27e1b 100644
--- a/lib/Magento/Framework/Pricing/Adjustment/Collection.php
+++ b/lib/Magento/Framework/Pricing/Adjustment/Collection.php
@@ -18,14 +18,14 @@
* versions in the future. If you wish to customize Magento for your
* needs please refer to http://www.magentocommerce.com for more information.
*
+ * @category Magento
+ * @package Magento_Pricing
* @copyright Copyright (c) 2014 X.commerce, Inc. (http://www.magentocommerce.com)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/
namespace Magento\Framework\Pricing\Adjustment;
-use Magento\Framework\Pricing\Adjustment\AdjustmentInterface;
-
/**
* Adjustment collection model
*/
diff --git a/lib/Magento/Framework/Pricing/Adjustment/Factory.php b/lib/Magento/Framework/Pricing/Adjustment/Factory.php
index 107a8d7f8b57b..8192001c7d411 100644
--- a/lib/Magento/Framework/Pricing/Adjustment/Factory.php
+++ b/lib/Magento/Framework/Pricing/Adjustment/Factory.php
@@ -56,12 +56,12 @@ public function __construct(\Magento\Framework\ObjectManager $objectManager)
*/
public function create($className, array $arguments = [])
{
- $price = $this->objectManager->create($className, $arguments);
- if (!$price instanceof AdjustmentInterface) {
+ $adjustment = $this->objectManager->create($className, $arguments);
+ if (!$adjustment instanceof AdjustmentInterface) {
throw new \InvalidArgumentException(
$className . ' doesn\'t implement \Magento\Framework\Pricing\Adjustment\AdjustmentInterface'
);
}
- return $price;
+ return $adjustment;
}
}
diff --git a/lib/Magento/Framework/Pricing/Adjustment/Pool.php b/lib/Magento/Framework/Pricing/Adjustment/Pool.php
index dd6a7733b44ac..64d94aa307ebd 100644
--- a/lib/Magento/Framework/Pricing/Adjustment/Pool.php
+++ b/lib/Magento/Framework/Pricing/Adjustment/Pool.php
@@ -18,6 +18,8 @@
* versions in the future. If you wish to customize Magento for your
* needs please refer to http://www.magentocommerce.com for more information.
*
+ * @category Magento
+ * @package Magento_Pricing
* @copyright Copyright (c) 2014 X.commerce, Inc. (http://www.magentocommerce.com)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/
diff --git a/lib/Magento/Framework/Pricing/Amount/AmountInterface.php b/lib/Magento/Framework/Pricing/Amount/AmountInterface.php
index d8140403a2a13..c84698ac19d65 100644
--- a/lib/Magento/Framework/Pricing/Amount/AmountInterface.php
+++ b/lib/Magento/Framework/Pricing/Amount/AmountInterface.php
@@ -18,6 +18,8 @@
* versions in the future. If you wish to customize Magento for your
* needs please refer to http://www.magentocommerce.com for more information.
*
+ * @category Magento
+ * @package Magento_Pricing
* @copyright Copyright (c) 2014 X.commerce, Inc. (http://www.magentocommerce.com)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/
diff --git a/lib/Magento/Framework/Pricing/Amount/Base.php b/lib/Magento/Framework/Pricing/Amount/Base.php
index 02876f2c2b8ba..1b3b2f0bcfddc 100644
--- a/lib/Magento/Framework/Pricing/Amount/Base.php
+++ b/lib/Magento/Framework/Pricing/Amount/Base.php
@@ -173,11 +173,9 @@ protected function calculateAmounts()
{
$this->baseAmount = $this->amount;
$this->totalAdjustmentAmount = 0.;
- if ($this->adjustmentAmounts) {
- foreach ($this->adjustmentAmounts as $amount) {
- $this->baseAmount -= $amount;
- $this->totalAdjustmentAmount += $amount;
- }
+ foreach ($this->adjustmentAmounts as $amount) {
+ $this->baseAmount -= $amount;
+ $this->totalAdjustmentAmount += $amount;
}
}
}
diff --git a/lib/Magento/Framework/Pricing/Object/SaleableInterface.php b/lib/Magento/Framework/Pricing/Object/SaleableInterface.php
index ab93e715a4c2f..5e9a6ac8fe36d 100644
--- a/lib/Magento/Framework/Pricing/Object/SaleableInterface.php
+++ b/lib/Magento/Framework/Pricing/Object/SaleableInterface.php
@@ -18,6 +18,8 @@
* versions in the future. If you wish to customize Magento for your
* needs please refer to http://www.magentocommerce.com for more information.
*
+ * @category Magento
+ * @package Magento_Pricing
* @copyright Copyright (c) 2014 X.commerce, Inc. (http://www.magentocommerce.com)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/
@@ -25,28 +27,35 @@
namespace Magento\Framework\Pricing\Object;
/**
- * //@TODO Templates invoke methods that are not defined in the interface:
- * getProductUrl():
- * /app\code\Magento\Catalog\view\frontend\product\price\final_price.phtml
- * /app\code\Magento\Catalog\view\frontend\product\price\msrp_item.phtml
- *
- * getId() - /app\code\Magento\Catalog\view\frontend\product\price\final_price.phtml
- * getMsrp() - /app\code\Magento\Catalog\view\frontend\product\price\msrp_item.phtml
+ * Interface SaleableInterface
*/
interface SaleableInterface
{
/**
+ * Returns PriceInfo container of saleable item
+ *
* @return \Magento\Framework\Pricing\PriceInfoInterface
*/
public function getPriceInfo();
/**
+ * Returns type identifier of saleable item
+ *
* @return string
*/
public function getTypeId();
/**
+ * Returns identifier of saleable item
+ *
* @return int
*/
public function getId();
+
+ /**
+ * Returns quantity of saleable item
+ *
+ * @return float
+ */
+ public function getQty();
}
diff --git a/lib/Magento/Framework/Pricing/Price/AbstractPrice.php b/lib/Magento/Framework/Pricing/Price/AbstractPrice.php
new file mode 100644
index 0000000000000..d00f8f38eb21b
--- /dev/null
+++ b/lib/Magento/Framework/Pricing/Price/AbstractPrice.php
@@ -0,0 +1,134 @@
+product = $saleableItem;
+ $this->quantity = $quantity;
+ $this->calculator = $calculator;
+ $this->priceInfo = $saleableItem->getPriceInfo();
+ }
+
+ /**
+ * Get price value
+ *
+ * @return float|bool
+ */
+ abstract public function getValue();
+
+ /**
+ * Get Price Amount object
+ *
+ * @return AmountInterface
+ */
+ public function getAmount()
+ {
+ if (null === $this->amount) {
+ $this->amount = $this->calculator->getAmount($this->getValue(), $this->product);
+ }
+ return $this->amount;
+ }
+
+ /**
+ * @param float $amount
+ * @param null|bool|string $exclude
+ * @return AmountInterface|bool|float
+ */
+ public function getCustomAmount($amount = null, $exclude = null)
+ {
+ $amount = (null === $amount) ? $this->getValue() : $amount;
+ return $this->calculator->getAmount($amount, $this->product, $exclude);
+ }
+
+ /**
+ * Get price type code
+ *
+ * @return string
+ */
+ public function getPriceCode()
+ {
+ return static::PRICE_CODE;
+ }
+}
diff --git a/lib/Magento/Framework/Pricing/Price/BasePriceProviderInterface.php b/lib/Magento/Framework/Pricing/Price/BasePriceProviderInterface.php
new file mode 100644
index 0000000000000..00634ae0f4840
--- /dev/null
+++ b/lib/Magento/Framework/Pricing/Price/BasePriceProviderInterface.php
@@ -0,0 +1,35 @@
+saleableItem = $saleableItem;
+ $this->priceFactory = $priceFactory;
+ $this->pool = $pool;
+ $this->quantity = $quantity;
+ }
+
+ /**
+ * Reset the Collection to the first element
+ *
+ * @return mixed|void
+ */
+ public function rewind()
+ {
+ return $this->pool->rewind();
+ }
+
+ /**
+ * Return the current element
+ *
+ * @return \Magento\Framework\Pricing\Price\PriceInterface
+ */
+ public function current()
+ {
+ return $this->get($this->key());
+ }
+
+ /**
+ * Return the key of the current element
+ *
+ * @return string
+ */
+ public function key()
+ {
+ return $this->pool->key();
+ }
+
+ /**
+ * Move forward to next element
+ *
+ * @return mixed|void
+ */
+ public function next()
+ {
+ return $this->pool->next();
+ }
+
+ /**
+ * Checks if current position is valid
+ *
+ * @return bool
+ */
+ public function valid()
+ {
+ return $this->pool->valid();
+ }
+
+ /**
+ * Returns price model by code
+ *
+ * @param string $code
+ * @return PriceInterface
+ */
+ public function get($code)
+ {
+ return $this->priceFactory->create(
+ $this->saleableItem,
+ $this->pool[$code],
+ $this->quantity
+ );
+ }
+}
diff --git a/lib/Magento/Framework/Pricing/Price/Factory.php b/lib/Magento/Framework/Pricing/Price/Factory.php
index 0fb0056269c4d..22897b2d173da 100644
--- a/lib/Magento/Framework/Pricing/Price/Factory.php
+++ b/lib/Magento/Framework/Pricing/Price/Factory.php
@@ -51,16 +51,16 @@ public function __construct(\Magento\Framework\ObjectManager $objectManager)
/**
* Create Price object for particular product
*
- * @param SaleableInterface $salableItem
+ * @param SaleableInterface $saleableItem
* @param string $className
* @param float $quantity
* @param array $arguments
* @throws \InvalidArgumentException
* @return \Magento\Framework\Pricing\Price\PriceInterface
*/
- public function create(SaleableInterface $salableItem, $className, $quantity, array $arguments = [])
+ public function create(SaleableInterface $saleableItem, $className, $quantity, array $arguments = [])
{
- $arguments['salableItem'] = $salableItem;
+ $arguments['saleableItem'] = $saleableItem;
$arguments['quantity'] = $quantity;
$price = $this->objectManager->create($className, $arguments);
if (!$price instanceof PriceInterface) {
diff --git a/lib/Magento/Framework/Pricing/Price/Pool.php b/lib/Magento/Framework/Pricing/Price/Pool.php
new file mode 100644
index 0000000000000..c42c39a3873fa
--- /dev/null
+++ b/lib/Magento/Framework/Pricing/Price/Pool.php
@@ -0,0 +1,162 @@
+prices = $prices;
+ foreach ($target ?: [] as $code => $class) {
+ if (empty($this->prices[$code])) {
+ $this->prices[$code] = $class;
+ }
+ }
+ }
+
+ /**
+ * Reset the Collection to the first element
+ *
+ * @return mixed
+ */
+ public function rewind()
+ {
+ return reset($this->prices);
+ }
+
+ /**
+ * Return the current element
+ *
+ * @return mixed
+ */
+ public function current()
+ {
+ return current($this->prices);
+ }
+
+ /**
+ * Return the key of the current element
+ *
+ * @return string
+ */
+ public function key()
+ {
+ return key($this->prices);
+ }
+
+ /**
+ * Move forward to next element
+ *
+ * @return mixed
+ */
+ public function next()
+ {
+ return next($this->prices);
+ }
+
+ /**
+ * Checks if current position is valid
+ *
+ * @return bool
+ */
+ public function valid()
+ {
+ return (bool)$this->key();
+ }
+
+ /**
+ * Returns price class by code
+ *
+ * @param string $code
+ * @return string
+ */
+ public function get($code)
+ {
+ return $this->prices[$code];
+ }
+
+ /**
+ * The value to set.
+ *
+ * @param string $offset
+ * @param string $value
+ * @return void
+ */
+ public function offsetSet($offset, $value)
+ {
+ if (is_null($offset)) {
+ $this->prices[] = $value;
+ } else {
+ $this->prices[$offset] = $value;
+ }
+ }
+
+ /**
+ * The return value will be casted to boolean if non-boolean was returned.
+ *
+ * @param string $offset
+ * @return bool
+ */
+ public function offsetExists($offset)
+ {
+ return isset($this->prices[$offset]);
+ }
+
+ /**
+ * The offset to unset.
+ *
+ * @param string $offset
+ * @return void
+ */
+ public function offsetUnset($offset)
+ {
+ unset($this->prices[$offset]);
+ }
+
+ /**
+ * The offset to retrieve.
+ *
+ * @param string $offset
+ * @return string
+ */
+ public function offsetGet($offset)
+ {
+ return isset($this->prices[$offset]) ? $this->prices[$offset] : null;
+ }
+}
diff --git a/lib/Magento/Framework/Pricing/Price/PriceInterface.php b/lib/Magento/Framework/Pricing/Price/PriceInterface.php
index f38b6973ae54c..066d65fd877a8 100644
--- a/lib/Magento/Framework/Pricing/Price/PriceInterface.php
+++ b/lib/Magento/Framework/Pricing/Price/PriceInterface.php
@@ -18,6 +18,8 @@
* versions in the future. If you wish to customize Magento for your
* needs please refer to http://www.magentocommerce.com for more information.
*
+ * @category Magento
+ * @package Magento_Pricing
* @copyright Copyright (c) 2014 X.commerce, Inc. (http://www.magentocommerce.com)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/
@@ -36,7 +38,7 @@ interface PriceInterface
*
* @return string
*/
- public function getPriceType();
+ public function getPriceCode();
/**
* Get price value
diff --git a/lib/Magento/Framework/Pricing/PriceComposite.php b/lib/Magento/Framework/Pricing/PriceComposite.php
deleted file mode 100644
index e9a9f9b771e03..0000000000000
--- a/lib/Magento/Framework/Pricing/PriceComposite.php
+++ /dev/null
@@ -1,89 +0,0 @@
-priceFactory = $priceFactory;
- $this->metadata = $metadata;
- }
-
- /**
- * @return array
- */
- public function getPriceCodes()
- {
- return array_keys($this->metadata);
- }
-
- /**
- * Returns metadata for prices
- *
- * @return array
- */
- public function getMetadata()
- {
- return $this->metadata;
- }
-
- /**
- * @param SaleableInterface $salableItem
- * @param string $priceCode
- * @param float $quantity
- * @return PriceInterface
- * @throws \InvalidArgumentException
- */
- public function createPriceObject(SaleableInterface $salableItem, $priceCode, $quantity)
- {
- if (!isset($this->metadata[$priceCode])) {
- throw new \InvalidArgumentException($priceCode . ' is not registered in prices list');
- }
- $className = $this->metadata[$priceCode]['class'];
- return $this->priceFactory->create($salableItem, $className, $quantity);
- }
-}
diff --git a/lib/Magento/Framework/Pricing/PriceCurrencyInterface.php b/lib/Magento/Framework/Pricing/PriceCurrencyInterface.php
index 621bc80d65da2..91a446753b3c7 100644
--- a/lib/Magento/Framework/Pricing/PriceCurrencyInterface.php
+++ b/lib/Magento/Framework/Pricing/PriceCurrencyInterface.php
@@ -18,6 +18,8 @@
* versions in the future. If you wish to customize Magento for your
* needs please refer to http://www.magentocommerce.com for more information.
*
+ * @category Magento
+ * @package Magento_Pricing
* @copyright Copyright (c) 2014 X.commerce, Inc. (http://www.magentocommerce.com)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/
diff --git a/lib/Magento/Framework/Pricing/PriceInfo/Base.php b/lib/Magento/Framework/Pricing/PriceInfo/Base.php
index 00e4645b03a94..18751c3f38923 100644
--- a/lib/Magento/Framework/Pricing/PriceInfo/Base.php
+++ b/lib/Magento/Framework/Pricing/PriceInfo/Base.php
@@ -24,33 +24,23 @@
namespace Magento\Framework\Pricing\PriceInfo;
-use Magento\Framework\Pricing\Amount\AmountFactory;
use Magento\Framework\Pricing\PriceInfoInterface;
-use Magento\Framework\Pricing\PriceComposite;
use Magento\Framework\Pricing\Price\PriceInterface;
use Magento\Framework\Pricing\Adjustment\Collection;
use Magento\Framework\Pricing\Adjustment\AdjustmentInterface;
-use Magento\Framework\Pricing\Object\SaleableInterface;
+use Magento\Framework\Pricing\Price\Collection as PriceCollection;
/**
+ * Class Base
* Price info base model
+ * @package Magento\Framework\Pricing\PriceInfo
*/
class Base implements PriceInfoInterface
{
/**
- * @var SaleableInterface
+ * @var PriceCollection
*/
- protected $saleableItem;
-
- /**
- * @var PriceComposite
- */
- protected $prices;
-
- /**
- * @var PriceInterface[]
- */
- protected $priceInstances;
+ protected $priceCollection;
/**
* @var Collection
@@ -58,85 +48,36 @@ class Base implements PriceInfoInterface
protected $adjustmentCollection;
/**
- * @var float
- */
- protected $quantity;
-
- /**
- * @var AmountFactory
- */
- protected $amountFactory;
-
- /**
- * @param SaleableInterface $saleableItem
- * @param PriceComposite $prices
+ * @param PriceCollection $prices
* @param Collection $adjustmentCollection
- * @param AmountFactory $amountFactory
- * @param float $quantity
*/
public function __construct(
- SaleableInterface $saleableItem,
- PriceComposite $prices,
- Collection $adjustmentCollection,
- AmountFactory $amountFactory,
- $quantity = self::PRODUCT_QUANTITY_DEFAULT
+ PriceCollection $prices,
+ Collection $adjustmentCollection
) {
- $this->saleableItem = $saleableItem;
- $this->prices = $prices;
$this->adjustmentCollection = $adjustmentCollection;
- $this->amountFactory = $amountFactory;
- $this->quantity = $quantity;
+ $this->priceCollection = $prices;
}
/**
- * @return PriceInterface[]
+ * Returns array of prices
+ *
+ * @return PriceCollection
*/
public function getPrices()
{
- // check if all prices initialized
- $this->initPrices();
- return $this->priceInstances;
+ return $this->priceCollection;
}
/**
- * Init price types
+ * Returns price by code
*
- * @return $this
- */
- protected function initPrices()
- {
- $prices = $this->prices->getPriceCodes();
- foreach ($prices as $code) {
- if (!isset($this->priceInstances[$code])) {
- $this->priceInstances[$code] = $this->prices->createPriceObject(
- $this->saleableItem,
- $code,
- $this->quantity
- );
- }
- }
- return $this;
- }
-
- /**
* @param string $priceCode
- * @param float|null $quantity
* @return PriceInterface
*/
- public function getPrice($priceCode, $quantity = null)
+ public function getPrice($priceCode)
{
- if (!isset($this->priceInstances[$priceCode]) && $quantity === null) {
- $this->priceInstances[$priceCode] = $this->prices->createPriceObject(
- $this->saleableItem,
- $priceCode,
- $this->quantity
- );
- return $this->priceInstances[$priceCode];
- } elseif (isset($this->priceInstances[$priceCode]) && $quantity === null) {
- return $this->priceInstances[$priceCode];
- } else {
- return $this->prices->createPriceObject($this->saleableItem, $priceCode, $quantity);
- }
+ return $this->priceCollection->get($priceCode);
}
/**
@@ -160,23 +101,4 @@ public function getAdjustment($adjustmentCode)
{
return $this->adjustmentCollection->getItemByCode($adjustmentCode);
}
-
- /**
- * Returns prices included in base price
- *
- * @return array
- */
- public function getPricesIncludedInBase()
- {
- $prices = [];
- foreach ($this->prices->getMetadata() as $code => $price) {
- if (isset($price['include_in_base_price']) && $price['include_in_base_price']) {
- $priceModel = $this->getPrice($code, $this->quantity);
- if ($priceModel->getValue() !== false) {
- $prices[] = $priceModel;
- }
- }
- }
- return $prices;
- }
}
diff --git a/lib/Magento/Framework/Pricing/PriceInfo/Factory.php b/lib/Magento/Framework/Pricing/PriceInfo/Factory.php
index 09ad85628bd75..753af9fb19a3b 100644
--- a/lib/Magento/Framework/Pricing/PriceInfo/Factory.php
+++ b/lib/Magento/Framework/Pricing/PriceInfo/Factory.php
@@ -27,6 +27,7 @@
*/
namespace Magento\Framework\Pricing\PriceInfo;
+use Magento\Framework\ObjectManager;
use Magento\Framework\Pricing\Object\SaleableInterface;
/**
@@ -34,11 +35,6 @@
*/
class Factory
{
- /**
- * Default Price Info class
- */
- const DEFAULT_PRICE_INFO_CLASS = 'Magento\Framework\Pricing\PriceInfoInterface';
-
/**
* List of Price Info classes by product types
*
@@ -49,7 +45,7 @@ class Factory
/**
* Object Manager
*
- * @var \Magento\Framework\ObjectManager
+ * @var ObjectManager
*/
protected $objectManager;
@@ -59,8 +55,10 @@ class Factory
* @param array $types
* @param \Magento\Framework\ObjectManager $objectManager
*/
- public function __construct(array $types, \Magento\Framework\ObjectManager $objectManager)
- {
+ public function __construct(
+ array $types,
+ ObjectManager $objectManager
+ ) {
$this->types = $types;
$this->objectManager = $objectManager;
}
@@ -76,19 +74,33 @@ public function __construct(array $types, \Magento\Framework\ObjectManager $obje
public function create(SaleableInterface $saleableItem, array $arguments = [])
{
$type = $saleableItem->getTypeId();
- $className = isset($this->types[$type]) ? $this->types[$type] : self::DEFAULT_PRICE_INFO_CLASS;
- $arguments['saleableItem'] = $saleableItem;
- if ($saleableItem->getQty()) {
- $arguments['quantity'] = $saleableItem->getQty();
+ if (isset($this->types[$type]['infoClass'])) {
+ $priceInfo = $this->types[$type]['infoClass'];
+ } else {
+ $priceInfo = $this->types['default']['infoClass'];
}
- $priceInfo = $this->objectManager->create($className, $arguments);
- if (!$priceInfo instanceof \Magento\Framework\Pricing\PriceInfoInterface) {
- throw new \InvalidArgumentException(
- $className . ' doesn\'t implement \Magento\Framework\Pricing\PriceInfoInterface'
- );
+ if (isset($this->types[$type]['prices'])) {
+ $priceCollection = $this->types[$type]['prices'];
+ } else {
+ $priceCollection = $this->types['default']['prices'];
}
- return $priceInfo;
+
+ $arguments['saleableItem'] = $saleableItem;
+ $quantity = $saleableItem->getQty();
+ if ($quantity) {
+ $arguments['quantity'] = $quantity;
+ }
+
+ $arguments['prices'] = $this->objectManager->create(
+ $priceCollection,
+ [
+ 'saleableItem' => $arguments['saleableItem'],
+ 'quantity' => $quantity
+ ]
+ );
+
+ return $this->objectManager->create($priceInfo, $arguments);
}
}
diff --git a/lib/Magento/Framework/Pricing/PriceInfoInterface.php b/lib/Magento/Framework/Pricing/PriceInfoInterface.php
index 7f29615106ad3..247b0cd9e7dfd 100644
--- a/lib/Magento/Framework/Pricing/PriceInfoInterface.php
+++ b/lib/Magento/Framework/Pricing/PriceInfoInterface.php
@@ -18,6 +18,8 @@
* versions in the future. If you wish to customize Magento for your
* needs please refer to http://www.magentocommerce.com for more information.
*
+ * @category Magento
+ * @package Magento_Pricing
* @copyright Copyright (c) 2014 X.commerce, Inc. (http://www.magentocommerce.com)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/
@@ -38,30 +40,32 @@ interface PriceInfoInterface
const PRODUCT_QUANTITY_DEFAULT = 1.;
/**
+ * Returns array of prices
+ *
* @return PriceInterface[]
*/
public function getPrices();
/**
+ * Returns price by code
+ *
* @param string $priceCode
- * @param float|null $quantity
* @return PriceInterface
*/
- public function getPrice($priceCode, $quantity = null);
+ public function getPrice($priceCode);
/**
+ * Get all registered adjustments
+ *
* @return AdjustmentInterface[]
*/
public function getAdjustments();
/**
+ * Get adjustment by code
+ *
* @param string $adjustmentCode
* @return AdjustmentInterface
*/
public function getAdjustment($adjustmentCode);
-
- /**
- * @return PriceInterface[]
- */
- public function getPricesIncludedInBase();
}
diff --git a/lib/Magento/Framework/Pricing/Render.php b/lib/Magento/Framework/Pricing/Render.php
index 03f9efb022bfd..dbd6f5048b4ff 100644
--- a/lib/Magento/Framework/Pricing/Render.php
+++ b/lib/Magento/Framework/Pricing/Render.php
@@ -18,6 +18,8 @@
* versions in the future. If you wish to customize Magento for your
* needs please refer to http://www.magentocommerce.com for more information.
*
+ * @category Magento
+ * @package Magento_Pricing
* @copyright Copyright (c) 2014 X.commerce, Inc. (http://www.magentocommerce.com)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/
@@ -113,14 +115,7 @@ public function render($priceCode, SaleableInterface $saleableItem, array $argum
// obtain concrete Price Render
$priceRender = $rendererPool->createPriceRender($priceCode, $saleableItem, $useArguments);
- if ($priceRender) {
- //@TODO PriceBoxRenderInterface does not contain toHtml() method
- $result = $priceRender->toHtml();
- } else {
- $result = '';
- }
- // return rendered output
- return $result;
+ return $priceRender->toHtml();
}
/**
@@ -149,12 +144,6 @@ public function renderAmount(
// obtain concrete Amount Render
$amountRender = $rendererPool->createAmountRender($amount, $saleableItem, $price, $useArguments);
- if ($amountRender) {
- $result = $amountRender->toHtml();
- } else {
- $result = '';
- }
- // return rendered output
- return $result;
+ return $amountRender->toHtml();
}
}
diff --git a/lib/Magento/Framework/Pricing/Render/AbstractAdjustment.php b/lib/Magento/Framework/Pricing/Render/AbstractAdjustment.php
index 6da9aeb97f030..3fe9d92e2c966 100644
--- a/lib/Magento/Framework/Pricing/Render/AbstractAdjustment.php
+++ b/lib/Magento/Framework/Pricing/Render/AbstractAdjustment.php
@@ -18,6 +18,8 @@
* versions in the future. If you wish to customize Magento for your
* needs please refer to http://www.magentocommerce.com for more information.
*
+ * @category Magento
+ * @package Magento_Pricing
* @copyright Copyright (c) 2014 X.commerce, Inc. (http://www.magentocommerce.com)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/
@@ -63,7 +65,7 @@ public function __construct(
/**
* @param AmountRenderInterface $amountRender
* @param array $arguments
- * @return void
+ * @return string
*/
public function render(AmountRenderInterface $amountRender, array $arguments = [])
{
@@ -136,7 +138,7 @@ public function getAdjustment()
}
/**
- * @return void
+ * @return string
*/
abstract protected function apply();
}
diff --git a/lib/Magento/Framework/Pricing/Render/AdjustmentRenderInterface.php b/lib/Magento/Framework/Pricing/Render/AdjustmentRenderInterface.php
index 24a38d99cd0d0..b263114a9614c 100644
--- a/lib/Magento/Framework/Pricing/Render/AdjustmentRenderInterface.php
+++ b/lib/Magento/Framework/Pricing/Render/AdjustmentRenderInterface.php
@@ -18,6 +18,8 @@
* versions in the future. If you wish to customize Magento for your
* needs please refer to http://www.magentocommerce.com for more information.
*
+ * @category Magento
+ * @package Magento_Pricing
* @copyright Copyright (c) 2014 X.commerce, Inc. (http://www.magentocommerce.com)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/
diff --git a/lib/Magento/Framework/Pricing/Render/Amount.php b/lib/Magento/Framework/Pricing/Render/Amount.php
index fd8e5d68b8402..0c48a14202478 100644
--- a/lib/Magento/Framework/Pricing/Render/Amount.php
+++ b/lib/Magento/Framework/Pricing/Render/Amount.php
@@ -18,6 +18,8 @@
* versions in the future. If you wish to customize Magento for your
* needs please refer to http://www.magentocommerce.com for more information.
*
+ * @category Magento
+ * @package Magento_Pricing
* @copyright Copyright (c) 2014 X.commerce, Inc. (http://www.magentocommerce.com)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/
@@ -67,7 +69,7 @@ class Amount extends Template implements AmountRenderInterface
protected $rendererPool;
/**
- * @var float
+ * @var AmountInterface
*/
protected $amount;
@@ -152,16 +154,6 @@ public function getPrice()
return $this->price;
}
- /**
- * @param string $code
- * @param string $html
- * @return void
- */
- public function addAdjustmentHtml($code, $html)
- {
- $this->adjustmentsHtml[$code] = $html;
- }
-
/**
* @return bool
*/
@@ -183,10 +175,9 @@ public function getAdjustmentsHtml()
*/
protected function _toHtml()
{
- // apply Price Adjustment Renders if available
$adjustmentRenders = $this->getApplicableAdjustmentRenders();
if ($adjustmentRenders) {
- $this->applyAdjustments($adjustmentRenders);
+ $this->adjustmentsHtml = $this->getAdjustments($adjustmentRenders);
}
$html = parent::_toHtml();
return $html;
@@ -199,11 +190,7 @@ protected function _toHtml()
*/
protected function getApplicableAdjustmentRenders()
{
- if (!$this->hasSkipAdjustments()) {
- return $this->getAdjustmentRenders();
- } else {
- return [];
- }
+ return (!$this->hasSkipAdjustments()) ? $this->getAdjustmentRenders() : [];
}
/**
@@ -216,15 +203,20 @@ protected function getAdjustmentRenders()
/**
* @param AdjustmentRenderInterface[] $adjustmentRenders
- * @return void
+ * @return array
*/
- protected function applyAdjustments($adjustmentRenders)
+ protected function getAdjustments($adjustmentRenders)
{
$this->setAdjustmentCssClasses($adjustmentRenders);
$data = $this->getData();
+ $adjustments = [];
foreach ($adjustmentRenders as $adjustmentRender) {
- $adjustmentRender->render($this, $data);
+ $html = $adjustmentRender->render($this, $data);
+ if (trim($html)) {
+ $adjustments[$adjustmentRender->getAdjustmentCode()] = $html;
+ }
}
+ return $adjustments;
}
/**
diff --git a/lib/Magento/Framework/Pricing/Render/AmountRenderInterface.php b/lib/Magento/Framework/Pricing/Render/AmountRenderInterface.php
index 1bbf8a69bbdbc..87e60dc7a0ef1 100644
--- a/lib/Magento/Framework/Pricing/Render/AmountRenderInterface.php
+++ b/lib/Magento/Framework/Pricing/Render/AmountRenderInterface.php
@@ -18,6 +18,8 @@
* versions in the future. If you wish to customize Magento for your
* needs please refer to http://www.magentocommerce.com for more information.
*
+ * @category Magento
+ * @package Magento_Pricing
* @copyright Copyright (c) 2014 X.commerce, Inc. (http://www.magentocommerce.com)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/
@@ -63,13 +65,6 @@ public function getSaleableItem();
*/
public function getPrice();
- /**
- * @param string $code
- * @param string $html
- * @return void
- */
- public function addAdjustmentHtml($code, $html);
-
/**
* @return string
*/
diff --git a/lib/Magento/Framework/Pricing/Render/Layout.php b/lib/Magento/Framework/Pricing/Render/Layout.php
index 5c8b9662ce65e..08e0d2a988fcd 100644
--- a/lib/Magento/Framework/Pricing/Render/Layout.php
+++ b/lib/Magento/Framework/Pricing/Render/Layout.php
@@ -18,6 +18,8 @@
* versions in the future. If you wish to customize Magento for your
* needs please refer to http://www.magentocommerce.com for more information.
*
+ * @category Magento
+ * @package Magento_Pricing
* @copyright Copyright (c) 2014 X.commerce, Inc. (http://www.magentocommerce.com)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/
diff --git a/lib/Magento/Framework/Pricing/Render/PriceBox.php b/lib/Magento/Framework/Pricing/Render/PriceBox.php
index a7752d0fb850c..f068656ba3c9a 100644
--- a/lib/Magento/Framework/Pricing/Render/PriceBox.php
+++ b/lib/Magento/Framework/Pricing/Render/PriceBox.php
@@ -18,6 +18,8 @@
* versions in the future. If you wish to customize Magento for your
* needs please refer to http://www.magentocommerce.com for more information.
*
+ * @category Magento
+ * @package Magento_Pricing
* @copyright Copyright (c) 2014 X.commerce, Inc. (http://www.magentocommerce.com)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/
@@ -78,7 +80,7 @@ public function __construct(
protected function _toHtml()
{
$cssClasses = $this->hasData('css_classes') ? explode(' ', $this->getData('css_classes')) : [];
- $cssClasses[] = 'price-' . $this->getPrice()->getPriceType();
+ $cssClasses[] = 'price-' . $this->getPrice()->getPriceCode();
$this->setData('css_classes', implode(' ', $cssClasses));
return parent::_toHtml();
}
@@ -88,7 +90,6 @@ protected function _toHtml()
*/
public function getSaleableItem()
{
- // @todo move to abstract pricing block
return $this->saleableItem;
}
@@ -97,7 +98,6 @@ public function getSaleableItem()
*/
public function getPrice()
{
- // @todo move to abstract pricing block
return $this->price;
}
@@ -114,16 +114,8 @@ public function getPriceId($defaultPrefix = null, $defaultSuffix = null)
return $this->getData('price_id');
}
$priceId = $this->saleableItem->getId();
- if ($this->hasData('price_id_prefix')) {
- $prefix = $this->getData('price_id_prefix') . $priceId;
- } else {
- $prefix = $defaultPrefix;
- }
- if ($this->hasData('price_id_suffix')) {
- $suffix = $this->getData('price_id_suffix');
- } else {
- $suffix = $defaultSuffix;
- }
+ $prefix = $this->hasData('price_id_prefix') ? $this->getData('price_id_prefix') : $defaultPrefix;
+ $suffix = $this->hasData('price_id_suffix') ? $this->getData('price_id_suffix') : $defaultSuffix;
$priceId = $prefix . $priceId . $suffix;
return $priceId;
}
@@ -132,12 +124,11 @@ public function getPriceId($defaultPrefix = null, $defaultSuffix = null)
* Retrieve price object of given type and quantity
*
* @param string $priceCode
- * @param float|null $quantity
* @return PriceInterface
*/
- public function getPriceType($priceCode, $quantity = null)
+ public function getPriceType($priceCode)
{
- return $this->saleableItem->getPriceInfo()->getPrice($priceCode, $quantity);
+ return $this->saleableItem->getPriceInfo()->getPrice($priceCode);
}
/**
diff --git a/lib/Magento/Framework/Pricing/Render/PriceBoxRenderInterface.php b/lib/Magento/Framework/Pricing/Render/PriceBoxRenderInterface.php
index 9948e1672551b..0a5c98d87ec32 100644
--- a/lib/Magento/Framework/Pricing/Render/PriceBoxRenderInterface.php
+++ b/lib/Magento/Framework/Pricing/Render/PriceBoxRenderInterface.php
@@ -18,6 +18,8 @@
* versions in the future. If you wish to customize Magento for your
* needs please refer to http://www.magentocommerce.com for more information.
*
+ * @category Magento
+ * @package Magento_Pricing
* @copyright Copyright (c) 2014 X.commerce, Inc. (http://www.magentocommerce.com)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/
diff --git a/lib/Magento/Framework/Pricing/Render/RendererPool.php b/lib/Magento/Framework/Pricing/Render/RendererPool.php
index d7363e793cc1a..eb56815362d93 100644
--- a/lib/Magento/Framework/Pricing/Render/RendererPool.php
+++ b/lib/Magento/Framework/Pricing/Render/RendererPool.php
@@ -126,7 +126,7 @@ public function createAmountRender(
$renderClassName = self::AMOUNT_RENDERER_DEFAULT;
if ($price) {
- $priceCode = $price->getPriceType();
+ $priceCode = $price->getPriceCode();
// implement class resolving fallback
$pattern = [
$type . '/prices/' . $priceCode . '/amount_render_class',
@@ -172,7 +172,7 @@ public function createAmountRender(
public function getAdjustmentRenders(SaleableInterface $saleableItem = null, PriceInterface $price = null)
{
$itemType = is_null($saleableItem) ? 'default' : $saleableItem->getTypeId();
- $priceType = is_null($price) ? 'default' : $price->getPriceType();
+ $priceType = is_null($price) ? 'default' : $price->getPriceCode();
$fallbackPattern = [
"{$itemType}/adjustments/{$priceType}",
diff --git a/lib/Magento/Framework/Url.php b/lib/Magento/Framework/Url.php
index a25696eb57c3a..a87fac692ba8a 100644
--- a/lib/Magento/Framework/Url.php
+++ b/lib/Magento/Framework/Url.php
@@ -560,9 +560,8 @@ protected function _setRouteName($data)
'controller_name'
)->unsetData(
'action_name'
- )->unsetData(
- 'secure'
);
+ $this->_queryParamsResolver->unsetData('secure');
return $this->setData('route_name', $data);
}
@@ -607,7 +606,8 @@ protected function _setControllerName($data)
if ($this->_getData('controller_name') == $data) {
return $this;
}
- $this->unsetData('route_path')->unsetData('action_name')->unsetData('secure');
+ $this->unsetData('route_path')->unsetData('action_name');
+ $this->_queryParamsResolver->unsetData('secure');
return $this->setData('controller_name', $data);
}
@@ -635,7 +635,9 @@ protected function _setActionName($data)
return $this;
}
$this->unsetData('route_path');
- return $this->setData('action_name', $data)->unsetData('secure');
+ $this->setData('action_name', $data);
+ $this->_queryParamsResolver->unsetData('secure');
+ return $this;
}
/**
diff --git a/lib/Magento/Framework/View/Design/Fallback/Factory.php b/lib/Magento/Framework/View/Design/Fallback/Factory.php
index b3ce86e3aad25..34b815f43c7b1 100644
--- a/lib/Magento/Framework/View/Design/Fallback/Factory.php
+++ b/lib/Magento/Framework/View/Design/Fallback/Factory.php
@@ -79,7 +79,8 @@ public function createFileRule()
new Composite(
array(
new Theme(new Simple("{$themesDir}/