Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug - Mage_Sales_Model_Order_Invoice_Total_Shipping:50 #72

Closed
2 changes: 1 addition & 1 deletion app/code/core/Mage/Eav/Model/Attribute/Data/Text.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function validateValue($value)
$value = $this->getEntity()->getDataUsingMethod($attribute->getAttributeCode());
}

if ($attribute->getIsRequired() && empty($value)) {
if ($attribute->getIsRequired() && empty($value) && $value !=='0') {
$errors[] = Mage::helper('Mage_Eav_Helper_Data')->__('"%s" is a required value.', $label);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function collect(Mage_Sales_Model_Order_Invoice $invoice)
* Check shipping amount in previus invoices
*/
foreach ($invoice->getOrder()->getInvoiceCollection() as $previusInvoice) {
if ($previusInvoice->getShippingAmount() && !$previusInvoice->isCanceled()) {
if ($previusInvoice->getShippingAmount() > 0 && !$previusInvoice->isCanceled()) {
return $this;
}
}
Expand Down
102 changes: 102 additions & 0 deletions dev/tests/unit/testsuite/Mage/Eav/Model/Attribute/Data/TextTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
<?php
/**
* Magento
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@magentocommerce.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade Magento to newer
* 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 Mage_Eav
* @subpackage unit_tests
* @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/
class Mage_Eav_Model_Attribute_Data_TextTest extends PHPUnit_Framework_TestCase
{

/**
* Text Model to be tested
* @var Mage_Eav_Model_Attribute_Data_Text|PHPUnit_Framework_MockObject_MockObject
*/
protected $_model;
/**
* @var $_attribute Mage_Eav_Model_Entity_Attribute_Abstract|PHPUnit_Framework_MockObject_MockObject
*/
protected $_attribute;
protected function setUp()
{
$this->_model = $this->getMock('Mage_Eav_Model_Attribute_Data_Text', array('getAttribute'), array(), '', false);
$attributeData = array(
'store_label' => 'Test',
'attribute_code' => 'test',
'is_required' => 1,
'validate_rules' => array(
'min_text_length' => 0,
'max_text_length' => 0,
'input_validation' => 0
)
);

/** @var $model Mage_Core_Model_Abstract */
$attribute = $this->getMock('Mage_Core_Model_Abstract', null, array($attributeData));

$this->_attribute = $attribute;
$this->_model->expects($this->any())
->method('getAttribute')
->will($this->returnValue($this->_attribute));
$helper = $this->getMockBuilder('Mage_Core_Helper_String')
->setMethods(array('__'))
->disableOriginalConstructor()
->getMock();
$helper->expects($this->any())
->method('__')
->will($this->returnArgument(0));
Mage::register('_helper/Mage_Eav_Helper_Data', $helper);
Mage::register('_helper/Mage_Core_Helper_String', $helper);


}

protected function tearDown()
{
$this->_model = null;
Mage::unregister('_helper/Mage_Eav_Helper_Data');
Mage::unregister('_helper/Mage_Core_Helper_String');
}

/**
* This test is to check the change made to validateValue.
* A bug was found where a text attribute that has is_required==1
* would not accept the string value of "0" (zero) as an input.
* That bug was fixed.
* @covers Mage_Eav_Model_Attribute_Data_Text::validateValue
* @param string|int|float|array $value
* @param string|int|float|array $expectedResult
* @dataProvider dataGetValuesAndResults
*/
public function testValidateValue($value, $expectedResult)
{
$this->assertEquals($expectedResult, $this->_model->validateValue($value));
}

public static function dataGetValuesAndResults()
{
return array(
array("0",true), //The string value of zero should be a valid input
array(0, array('"%s" is a required value.')) //Integer value of zero remains invalid
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<?php
/**
* Magento
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@magentocommerce.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade Magento to newer
* 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 Mage_Sales
* @subpackage unit_tests
* @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/
class Mage_Sales_Model_Order_Invoice_Total_ShippingTest extends PHPUnit_Framework_TestCase
{
/**
* Invoice to be passed to the collect method in testCollect
* @var Mage_Sales_Model_Order_Invoice $_invoice
*/
protected $_invoice;

/**
* Order to be returned when calling 'getOrder' inside collect method.
* @var Mage_Sales_Model_Order $_order
*/
protected $_order;


protected function setUp()
{
$this->_invoice = $this->getMock('Mage_Sales_Model_Order_Invoice', array('getOrder'), array(), '', false);
$this->_order = $this->getMock('Mage_Sales_Model_Order', array('getInvoiceCollection'), array(),'',false);

$this->_invoice->expects($this->any())
->method('getOrder')
->will($this->returnValue($this->_order));
}
/**
* @covers Mage_Sales_Model_Order_Invoice_Total_Shipping::collect
* @param $collection array
* @param $shippingAmount float
* @dataProvider dataGetValuesAndResults
*/
public function testCollect($collection, $shippingAmount)
{
$temp_collection = array();
foreach($collection as $tempShippingAmount){
$temp_invoice = $this->getMock('Mage_Sales_Model_Order_Invoice', null, array(), '', false);
$temp_invoice->setShippingAmount($tempShippingAmount);
$temp_collection[] = $temp_invoice;
}

$this->_order->expects($this->any())
->method('getInvoiceCollection')
->will($this->returnValue($temp_collection));
$this->_order->setData('shipping_amount',$shippingAmount);
$this->_order->setData('invoice_collection', $collection);
$total = new Mage_Sales_Model_Order_Invoice_Total_Shipping();
$total->collect($this->_invoice);
$this->assertEquals($this->_invoice->getShippingAmount(), $this->_order->getShippingAmount());


}

public static function dataGetValuesAndResults()
{
return array(
array(
array("0.0000")
,10.00
),
array(
array("10.000"),
0
)
);
}
}