Example #1
0
 /**
  * Validate customer attribute values.
  * For existing customer password + confirmation will be validated only when password is set
  * (i.e. its change is requested)
  *
  * @return bool|string[]
  */
 public function validate()
 {
     /** @var $validator \Magento\Framework\Validator\DataObject */
     $validator = $this->_validatorObject->create();
     $this->validationRules->addUserInfoRules($validator);
     if (!$validator->isValid($this)) {
         return $validator->getMessages();
     }
     return true;
 }
Example #2
0
 /**
  * @return void
  */
 public function testValidateInvalid()
 {
     $messages = ['Invalid username'];
     /** @var $validatorMock \Magento\Framework\Validator\DataObject|\PHPUnit_Framework_MockObject_MockObject */
     $validatorMock = $this->getMockBuilder('Magento\\Framework\\Validator\\DataObject')->disableOriginalConstructor()->setMethods([])->getMock();
     $this->validatorObjectFactoryMock->expects($this->once())->method('create')->willReturn($validatorMock);
     $this->validationRulesMock->expects($this->once())->method('addUserInfoRules')->with($validatorMock);
     $validatorMock->expects($this->once())->method('isValid')->willReturn(false);
     $validatorMock->expects($this->once())->method('getMessages')->willReturn($messages);
     $this->assertEquals($messages, $this->model->validate());
 }
 public function testCheckPasswordChangeValid()
 {
     /** @var $validatorMock \Magento\Framework\Validator\DataObject|\PHPUnit_Framework_MockObject_MockObject */
     $validatorMock = $this->getMockBuilder('Magento\\Framework\\Validator\\DataObject')->disableOriginalConstructor()->setMethods([])->getMock();
     $this->validatorObjectFactoryMock->expects($this->once())->method('create')->willReturn($validatorMock);
     $this->validationRulesMock->expects($this->once())->method('addUserInfoRules')->with($validatorMock);
     $validatorMock->expects($this->once())->method('isValid')->willReturn(true);
     $newPassword = "******";
     $oldPassword = "******";
     $this->model->setPassword($newPassword)->setId(1)->setOrigData('password', $oldPassword);
     $this->encryptorMock->expects($this->atLeastOnce())->method('isValidHash')->will($this->onConsecutiveCalls(false, false, false));
     $this->resourceMock->expects($this->once())->method('getOldPasswords')->willReturn(['hash1', 'hash2']);
     $result = $this->model->validate();
     $this->assertTrue($result);
 }
 /**
  * @param \Magento\Framework\Model\Context $context
  * @param \Magento\Framework\Registry $registry
  * @param \Magento\Framework\App\Config\ScopeConfigInterface $config
  * @param \Magento\Framework\App\Cache\TypeListInterface $cacheTypeList
  * @param \Magento\Framework\Validator\DataObjectFactory $validatorCompositeFactory
  * @param \Magento\GoogleAdwords\Model\Validator\Factory $validatorFactory
  * @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource
  * @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection
  * @param array $data
  */
 public function __construct(\Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, \Magento\Framework\App\Config\ScopeConfigInterface $config, \Magento\Framework\App\Cache\TypeListInterface $cacheTypeList, \Magento\Framework\Validator\DataObjectFactory $validatorCompositeFactory, \Magento\GoogleAdwords\Model\Validator\Factory $validatorFactory, \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null, array $data = [])
 {
     parent::__construct($context, $registry, $config, $cacheTypeList, $resource, $resourceCollection, $data);
     $this->_validatorFactory = $validatorFactory;
     $this->_validatorComposite = $validatorCompositeFactory->create();
 }