-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MAGETWO-36706: [GITHUB] Won't accept valid Brazil monetary value as i…
…nput #1192 - unit tests
- Loading branch information
Cristian Partica
committed
Jul 6, 2015
1 parent
18bb7bb
commit 36413b8
Showing
2 changed files
with
149 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 104 additions & 0 deletions
104
app/code/Magento/Catalog/Test/Unit/Model/Product/Attribute/Backend/WeightTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
<?php | ||
/** | ||
* Copyright © 2015 Magento. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\Catalog\Test\Unit\Model\Product\Attribute\Backend; | ||
|
||
class WeightTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
/** | ||
* @var \Magento\Catalog\Model\Product\Attribute\Backend\Weight | ||
*/ | ||
protected $model; | ||
|
||
protected function setUp() | ||
{ | ||
$objectHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); | ||
|
||
// we want to use an actual implementation of \Magento\Framework\Locale\FormatInterface | ||
$scopeResolver = $this->getMockForAbstractClass('\Magento\Framework\App\ScopeResolverInterface', [], '', false); | ||
$localeResolver = $this->getMockForAbstractClass('\Magento\Framework\Locale\ResolverInterface', [], '', false); | ||
$currencyFactory = $this->getMock('\Magento\Directory\Model\CurrencyFactory', [], [], '', false); | ||
$localeFormat = $objectHelper->getObject( | ||
'Magento\Framework\Locale\Format', | ||
[ | ||
'scopeResolver' => $scopeResolver, | ||
'localeResolver' => $localeResolver, | ||
'currencyFactory' => $currencyFactory, | ||
] | ||
); | ||
|
||
// the model we are testing | ||
$this->model = $objectHelper->getObject( | ||
'Magento\Catalog\Model\Product\Attribute\Backend\Weight', | ||
['localeFormat' => $localeFormat] | ||
); | ||
|
||
$attribute = $this->getMockForAbstractClass( | ||
'\Magento\Eav\Model\Entity\Attribute\AbstractAttribute', | ||
[], | ||
'', | ||
false | ||
); | ||
$this->model->setAttribute($attribute); | ||
} | ||
|
||
/** | ||
* Tests for the cases that expect to pass validation | ||
* | ||
* @dataProvider dataProviderValidate | ||
*/ | ||
public function testValidate($value) | ||
{ | ||
$object = $this->getMock('Magento\Catalog\Model\Product', [], [], '', false); | ||
$object->expects($this->once())->method('getData')->willReturn($value); | ||
|
||
$this->assertTrue($this->model->validate($object)); | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function dataProviderValidate() | ||
{ | ||
return [ | ||
'US simple' => ['1234.56'], | ||
'US full' => ['123,456.78'], | ||
'Brazil' => ['123.456,78'], | ||
'India' => ['1,23,456.78'], | ||
'Lebanon' => ['1 234'], | ||
'zero' => ['0.00'], | ||
'NaN becomes zero' => ['kiwi'], | ||
]; | ||
} | ||
|
||
/** | ||
* Tests for the cases that expect to fail validation | ||
* | ||
* @expectedException \Magento\Framework\Exception\LocalizedException | ||
* @dataProvider dataProviderValidateForFailure | ||
*/ | ||
public function testValidateForFailure($value) | ||
{ | ||
$object = $this->getMock('Magento\Catalog\Model\Product', [], [], '', false); | ||
$object->expects($this->once())->method('getData')->willReturn($value); | ||
|
||
$this->model->validate($object); | ||
$this->fail('Expected the following value to NOT validate: ' . $value); | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function dataProviderValidateForFailure() | ||
{ | ||
return [ | ||
'negative US simple' => ['-1234.56'], | ||
'negative US full' => ['-123,456.78'], | ||
'negative Brazil' => ['-123.456,78'], | ||
'negative India' => ['-1,23,456.78'], | ||
'negative Lebanon' => ['-1 234'], | ||
]; | ||
} | ||
} |