コード例 #1
0
 /**
  * @dataProvider validateAllowspecificFalseDataProvider
  */
 public function testValidateAllowspecificFalse($storeId, $allowspecific, $isValid)
 {
     $validationSubject = ['storeId' => $storeId];
     $this->configMock->expects($this->at(0))->method('getValue')->with('allowspecific', $storeId)->willReturn($allowspecific);
     $this->resultFactoryMock->expects($this->once())->method('create')->with(['isValid' => $isValid])->willReturn($this->resultMock);
     $this->assertSame($this->resultMock, $this->model->validate($validationSubject));
 }
コード例 #2
0
 /**
  * Run test for validate method
  *
  * @param array $validationSubject
  * @param bool $isValid
  * @return void
  *
  * @dataProvider dataProviderTestValidate
  */
 public function testValidate(array $validationSubject, $isValid)
 {
     /** @var ResultInterface|\PHPUnit_Framework_MockObject_MockObject $resultMock */
     $resultMock = $this->getMock(ResultInterface::class);
     $this->subjectReaderMock->expects(self::once())->method('readResponseObject')->with($validationSubject)->willReturn($validationSubject['response']['object']);
     $this->resultInterfaceFactoryMock->expects(self::once())->method('create')->with(['isValid' => $isValid, 'failsDescription' => ['Transaction has been declined, please, try again later.']])->willReturn($resultMock);
     $actualMock = $this->responseValidator->validate($validationSubject);
     self::assertEquals($resultMock, $actualMock);
 }
コード例 #3
0
ファイル: CountryValidator.php プロジェクト: kid17/magento2
 /**
  * @param array $validationSubject
  * @return bool
  * @throws NotFoundException
  * @throws \Exception
  */
 public function validate(array $validationSubject)
 {
     $isValid = true;
     $storeId = $validationSubject['storeId'];
     if ((int) $this->config->getValue('allowspecific', $storeId) === 1) {
         $availableCountries = explode(',', $this->config->getValue('specificcountry', $storeId));
         if (!in_array($validationSubject['country'], $availableCountries)) {
             $isValid = false;
         }
     }
     return $this->resultFactory->create(['isValid' => $isValid]);
 }
コード例 #4
0
ファイル: ValidatorComposite.php プロジェクト: kid17/magento2
 /**
  * Performs domain level validation for business object
  *
  * @param array $validationSubject
  * @return ResultInterface
  */
 public function validate(array $validationSubject)
 {
     $isValid = true;
     $failsDescriptionAggregate = [];
     foreach ($this->validators as $validator) {
         $result = $validator->validate($validationSubject);
         if (!$result->isValid()) {
             $isValid = false;
             $failsDescriptionAggregate = array_merge($failsDescriptionAggregate, $result->getFailsDescription());
         }
     }
     return $this->resultFactory->create(['isValid' => $isValid, 'failsDescription' => $failsDescriptionAggregate]);
 }
 public function testValidateSuccess()
 {
     $obj = new \stdClass();
     $obj->success = true;
     $obj->paymentMethodNonce = new \stdClass();
     $obj->paymentMethodNonce->nonce = 'fj2hd9239kd1kq9';
     $subject = ['response' => ['object' => $obj]];
     $this->subjectReader->expects(static::once())->method('readResponseObject')->willReturn($obj);
     $result = $this->getMock(ResultInterface::class);
     $this->resultInterfaceFactory->expects(self::once())->method('create')->with(['isValid' => true, 'failsDescription' => []])->willReturn($result);
     $actual = $this->validator->validate($subject);
     static::assertEquals($result, $actual);
 }
 /**
  * @param array $response
  * @param array $expectationToResultCreation
  *
  * @dataProvider validateDataProvider
  */
 public function testValidate(array $response, array $expectationToResultCreation)
 {
     $this->resultFactory->expects(static::once())->method('create')->with($expectationToResultCreation)->willReturn($this->resultMock);
     $validator = new ResponseCodeValidator($this->resultFactory);
     static::assertInstanceOf(ResultInterface::class, $validator->validate(['response' => $response]));
 }