![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/old/vendor/magento/module-ui/Test/Unit/DataProvider/ |
<?php /** * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ declare(strict_types=1); namespace Magento\Ui\Test\Unit\DataProvider; use Magento\Eav\Model\Entity\Attribute\AbstractAttribute; use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; use Magento\Ui\DataProvider\EavValidationRules; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; class EavValidationRulesTest extends TestCase { /** * @var ObjectManager */ protected $objectManager; /** * @var EavValidationRules */ protected $subject; /** * @var AbstractAttribute|MockObject */ protected $attributeMock; /** * {@inheritDoc} */ protected function setUp(): void { $this->objectManager = new ObjectManager($this); $this->attributeMock = $this->getMockBuilder(AbstractAttribute::class) ->setMethods(['getFrontendInput', 'getValidateRules']) ->disableOriginalConstructor() ->getMockForAbstractClass(); $this->subject = new EavValidationRules(); } /** * @param string $attributeInputType * @param mixed $validateRules * @param array $data * @param array $expected * @dataProvider buildDataProvider */ public function testBuild($attributeInputType, $validateRules, $data, $expected): void { $this->attributeMock->expects($this->once())->method('getFrontendInput')->willReturn($attributeInputType); $this->attributeMock->expects($this->any())->method('getValidateRules')->willReturn($validateRules); $validationRules = $this->subject->build($this->attributeMock, $data); $this->assertEquals($expected, $validationRules); } /** * @return array */ public function buildDataProvider() { return [ ['', '', [], []], ['', null, [], []], ['', false, [], []], ['', [], [], []], ['', '', ['required' => 1], ['required-entry' => true]], ['price', '', [], ['validate-zero-or-greater' => true]], ['price', '', ['required' => 1], ['validate-zero-or-greater' => true, 'required-entry' => true]], ['', ['input_validation' => 'email'], [], ['validate-email' => true]], ['', ['input_validation' => 'date'], [], ['validate-date' => true]], ['', ['input_validation' => 'other'], [], []], ['', ['max_text_length' => '254'], ['required' => 1], ['required-entry' => true]], [ '', ['input_validation' => 'other', 'max_text_length' => '254'], ['required' => 1], ['max_text_length' => 254, 'required-entry' => true] ], [ '', ['input_validation' => 'other', 'max_text_length' => '254', 'min_text_length' => 1], [], ['max_text_length' => 254, 'min_text_length' => 1] ], [ '', ['max_text_length' => '254', 'input_validation' => 'date'], [], ['max_text_length' => 254, 'validate-date' => true] ], ]; } }