-
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-42994: Customer custom attribute is not validated on frontend
- Loading branch information
Sergey Semenov
committed
Jul 20, 2016
1 parent
f553937
commit 6ce2b5f
Showing
5 changed files
with
152 additions
and
45 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
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
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
91 changes: 91 additions & 0 deletions
91
app/code/Magento/Eav/Test/Unit/Model/Entity/Attribute/Frontend/DefaultFrontendTest.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,91 @@ | ||
<?php | ||
/** | ||
* Copyright © 2016 Magento. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\Eav\Test\Unit\Model\Entity\Attribute\Frontend; | ||
|
||
use Magento\Eav\Model\Entity\Attribute\Frontend\DefaultFrontend; | ||
|
||
class DefaultFrontendTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
/** | ||
* @var DefaultFrontend | ||
*/ | ||
protected $model; | ||
|
||
/** | ||
* @var \Magento\Eav\Model\Entity\Attribute\Source\BooleanFactory|\PHPUnit_Framework_MockObject_MockObject | ||
*/ | ||
protected $booleanFactory; | ||
|
||
protected function setUp() | ||
{ | ||
$this->booleanFactory = $this->getMockBuilder('Magento\Eav\Model\Entity\Attribute\Source\BooleanFactory') | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
|
||
$this->model = new DefaultFrontend( | ||
$this->booleanFactory | ||
); | ||
} | ||
|
||
public function testGetClassEmpty() | ||
{ | ||
/** @var \PHPUnit_Framework_MockObject_MockObject $attributeMock */ | ||
$attributeMock = $this->getMockBuilder('Magento\Eav\Model\Entity\Attribute\AbstractAttribute') | ||
->disableOriginalConstructor() | ||
->setMethods([ | ||
'getIsRequired', | ||
'getFrontendClass', | ||
'getValidateRules', | ||
]) | ||
->getMock(); | ||
$attributeMock->expects($this->once()) | ||
->method('getIsRequired') | ||
->willReturn(false); | ||
$attributeMock->expects($this->once()) | ||
->method('getFrontendClass') | ||
->willReturn(''); | ||
$attributeMock->expects($this->exactly(2)) | ||
->method('getValidateRules') | ||
->willReturn(''); | ||
|
||
$this->model->setAttribute($attributeMock); | ||
$this->assertEmpty($this->model->getClass()); | ||
} | ||
|
||
public function testGetClass() | ||
{ | ||
/** @var \PHPUnit_Framework_MockObject_MockObject $attributeMock */ | ||
$attributeMock = $this->getMockBuilder('Magento\Eav\Model\Entity\Attribute\AbstractAttribute') | ||
->disableOriginalConstructor() | ||
->setMethods([ | ||
'getIsRequired', | ||
'getFrontendClass', | ||
'getValidateRules', | ||
]) | ||
->getMock(); | ||
$attributeMock->expects($this->once()) | ||
->method('getIsRequired') | ||
->willReturn(true); | ||
$attributeMock->expects($this->once()) | ||
->method('getFrontendClass') | ||
->willReturn(''); | ||
$attributeMock->expects($this->exactly(2)) | ||
->method('getValidateRules') | ||
->willReturn([ | ||
'input_validation' => 'alphanumeric', | ||
'min_text_length' => 1, | ||
'max_text_length' => 2, | ||
]); | ||
|
||
$this->model->setAttribute($attributeMock); | ||
$result = $this->model->getClass(); | ||
|
||
$this->assertContains('validate-alphanum', $result); | ||
$this->assertContains('minimum-length-1', $result); | ||
$this->assertContains('maximum-length-2', $result); | ||
$this->assertContains('validate-length', $result); | ||
} | ||
} |
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