customerRepository = $this->createMock(CustomerRepository::class); $this->customerSession = $this->createMock(CustomerSession::class); $this->addressHelper = $this->createMock(AddressHelper::class); $this->directoryHelper = $this->createMock(DirectoryHelper::class); $this->attributeMerger = new AttributeMerger( $this->addressHelper, $this->customerSession, $this->customerRepository, $this->directoryHelper ); } /** * Tests of element attributes merging. * * @param String $validationRule - validation rule. * @param String $expectedValidation - expected mapped validation. * @dataProvider validationRulesDataProvider */ public function testMerge(String $validationRule, String $expectedValidation): void { $elements = [ 'field' => [ 'visible' => true, 'formElement' => 'input', 'label' => __('City'), 'value' => null, 'sortOrder' => 1, 'validation' => [ 'input_validation' => $validationRule ], ] ]; $actualResult = $this->attributeMerger->merge( $elements, 'provider', 'dataScope', ['field' => [ 'validation' => ['length' => true] ] ] ); $expectedResult = [ $expectedValidation => true, 'length' => true ]; self::assertEquals($expectedResult, $actualResult['field']['validation']); } /** * Provides possible validation types. * * @return array */ public function validationRulesDataProvider(): array { return [ ['alpha', 'validate-alpha'], ['numeric', 'validate-number'], ['alphanumeric', 'validate-alphanum'], ['alphanum-with-spaces', 'validate-alphanum-with-spaces'], ['url', 'validate-url'], ['email', 'email2'], ['length', 'validate-length'] ]; } }