Ejemplo n.º 1
0
 /**
  * @param bool $isValid
  * @dataProvider trueFalseDataProvider
  */
 public function testIsValid($isValid)
 {
     $data = ['something'];
     $attribute = $this->getMockAttribute();
     $this->mockDataModel($isValid, $attribute);
     $this->validator->setAttributes([$attribute]);
     $this->validator->setEntityType('ENTITY_TYPE');
     $this->validator->setData($data);
     $this->assertEquals($isValid, $this->validator->isValid(['ENTITY']));
     $this->validator->setData([]);
     $this->assertEquals($isValid, $this->validator->isValid(new \Magento\Framework\Object($data)));
 }
Ejemplo n.º 2
0
 /**
  * {@inheritdoc}
  */
 public function validate(CustomerInterface $customer)
 {
     $customerData = $this->extensibleDataObjectConverter->toFlatArray($customer, [], '\\Magento\\Customer\\Api\\Data\\CustomerInterface');
     $customerErrors = $this->validator->validateData($customerData, [], 'customer');
     $validationResults = $this->validationResultsDataFactory->create();
     if ($customerErrors !== true) {
         return $validationResults->setIsValid(false)->setMessages($this->validator->getMessages());
     }
     $oldAddresses = $customer->getAddresses();
     $customerModel = $this->customerFactory->create()->updateData($customer->setAddresses([]));
     $customer->setAddresses($oldAddresses);
     $result = $customerModel->validate();
     if (true !== $result && is_array($result)) {
         return $validationResults->setIsValid(false)->setMessages($result);
     }
     return $validationResults->setIsValid(true)->setMessages([]);
 }
 /**
  * {@inheritdoc}
  */
 public function validateCustomerData(Data\Customer $customer, array $attributes = [])
 {
     $customerErrors = $this->validator->validateData(\Magento\Framework\Service\EavDataObjectConverter::toFlatArray($customer), $attributes, 'customer');
     if ($customerErrors !== true) {
         return $this->customerValidationResultsBuilder->setIsValid(false)->setMessages($this->validator->getMessages())->create();
     }
     $customerModel = $this->converter->createCustomerModel($customer);
     $result = $customerModel->validate();
     if (true !== $result && is_array($result)) {
         return $this->customerValidationResultsBuilder->setIsValid(false)->setMessages($result)->create();
     }
     return $this->customerValidationResultsBuilder->setIsValid(true)->setMessages([])->create();
 }