Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
EavValidationRulesTest.php
Go to the documentation of this file.
1 <?php
8 
12 
16 class EavValidationRulesTest extends \PHPUnit\Framework\TestCase
17 {
21  protected $objectManager;
22 
26  protected $subject;
27 
31  protected $attributeMock;
32 
36  protected function setUp()
37  {
38  $this->objectManager = new ObjectManager($this);
39  $this->attributeMock =
40  $this->getMockBuilder(AbstractAttribute::class)
41  ->setMethods(['getFrontendInput', 'getValidateRules'])
42  ->disableOriginalConstructor()
43  ->getMockForAbstractClass();
44 
45  $this->subject = new EavValidationRules();
46  }
47 
55  public function testBuild($attributeInputType, $validateRules, $data, $expected): void
56  {
57  $this->attributeMock->expects($this->once())->method('getFrontendInput')->willReturn($attributeInputType);
58  $this->attributeMock->expects($this->any())->method('getValidateRules')->willReturn($validateRules);
59  $validationRules = $this->subject->build($this->attributeMock, $data);
60  $this->assertEquals($expected, $validationRules);
61  }
62 
66  public function buildDataProvider()
67  {
68  return [
69  ['', '', [], []],
70  ['', null, [], []],
71  ['', false, [], []],
72  ['', [], [], []],
73  ['', '', ['required' => 1], ['required-entry' => true]],
74  ['price', '', [], ['validate-zero-or-greater' => true]],
75  ['price', '', ['required' => 1], ['validate-zero-or-greater' => true, 'required-entry' => true]],
76  ['', ['input_validation' => 'email'], [], ['validate-email' => true]],
77  ['', ['input_validation' => 'date'], [], ['validate-date' => true]],
78  ['', ['input_validation' => 'other'], [], []],
79  ['', ['max_text_length' => '254'], ['required' => 1], ['required-entry' => true]],
80  [
81  '',
82  ['input_validation' => 'other', 'max_text_length' => '254'],
83  ['required' => 1],
84  ['max_text_length' => 254, 'required-entry' => true]
85  ],
86  [
87  '',
88  ['input_validation' => 'other', 'max_text_length' => '254', 'min_text_length' => 1],
89  [],
90  ['max_text_length' => 254, 'min_text_length' => 1]
91  ],
92  [
93  '',
94  ['max_text_length' => '254', 'input_validation' => 'date'],
95  [],
96  ['max_text_length' => 254, 'validate-date' => true]
97  ],
98  ];
99  }
100 }
testBuild($attributeInputType, $validateRules, $data, $expected)