Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
CatalogEavValidationRulesTest.php
Go to the documentation of this file.
1 <?php
7 
10 use PHPUnit_Framework_MockObject_MockObject as MockObject;
11 
12 class CatalogEavValidationRulesTest extends \PHPUnit\Framework\TestCase
13 {
18 
23 
27  protected function setUp()
28  {
29  $this->objectManagerHelper = new ObjectManagerHelper($this);
30  $this->catalogEavValidationRules = $this->objectManagerHelper->getObject(CatalogEavValidationRules::class);
31  }
32 
41  public function testBuild($frontendInput, $frontendClass, array $eavConfig, array $expectedResult)
42  {
44  $attribute = $this->createMock(\Magento\Catalog\Api\Data\ProductAttributeInterface::class);
45 
46  $attribute->expects($this->once())
47  ->method('getFrontendInput')
48  ->willReturn($frontendInput);
49  $attribute->expects($this->once())
50  ->method('getFrontendClass')
51  ->willReturn($frontendClass);
52 
53  $this->assertEquals($expectedResult, $this->catalogEavValidationRules->build($attribute, $eavConfig));
54  }
55 
59  public function buildDataProvider()
60  {
61  $data['required'] = true;
62 
63  return [
64  [
65  'frontendInput' => 'input',
66  'frontendClass' => '',
67  'eavConfig' => [],
68  'expectedResult' => [],
69  ],
70  [
71  'frontendInput' => 'price',
72  'frontendClass' => '',
73  'eavConfig' => $data,
74  'expectedResult' => [
75  'required-entry' => true,
76  'validate-zero-or-greater' => true,
77  ],
78  ],
79  [
80  'frontendInput' => 'input',
81  'frontendClass' => 'maximum-length-20 minimum-length-10 validate-number validate-digits'
82  . ' validate-email validate-url validate-alpha validate-alphanum',
83  'eavConfig' => [],
84  'expectedResult' => [
85  'max_text_length' => 20,
86  'min_text_length' => 10,
87  'validate-number' => true,
88  'validate-digits' => true,
89  'validate-email' => true,
90  'validate-url' => true,
91  'validate-alpha' => true,
92  'validate-alphanum' => true,
93  ],
94  ],
95  ];
96  }
97 }