/**
  * @see ExceptionLocalizer::getExceptionMessage()
  *
  * @param Exception $exception
  *
  * @throws InvalidArgumentException
  * @return Message
  */
 public function getExceptionMessage(Exception $exception)
 {
     if (!$this->hasExceptionMessage($exception)) {
         throw new InvalidArgumentException('$exception is not a ChangeOpValidationException.');
     }
     /** @var ChangeOpValidationException $exception */
     $result = $exception->getValidationResult();
     foreach ($result->getErrors() as $error) {
         $msg = $this->validatorErrorLocalizer->getErrorMessage($error);
         return $msg;
     }
     return wfMessage('wikibase-validator-invalid');
 }
 /**
  * @dataProvider provideGetErrorMessage()
  */
 public function testGetErrorMessage($error, array $params)
 {
     $localizer = new ValidatorErrorLocalizer($this->getMockFormatter());
     $message = $localizer->getErrorMessage($error);
     //TODO: check that messages for actual error codes exist
     $this->assertInstanceOf('Message', $message);
     $this->assertEquals($params, $message->getParams());
 }
 protected function assertErrorCodeLocalization(Result $result)
 {
     $localizer = new ValidatorErrorLocalizer();
     $errors = $result->getErrors();
     $this->assertGreaterThanOrEqual(1, $errors);
     foreach ($errors as $error) {
         $msg = $localizer->getErrorMessage($error);
         $this->assertTrue($msg->exists(), 'message: ' . $msg);
     }
 }
 /**
  * @dataProvider provideValidate_failure()
  */
 public function testValidate_failure($value, $type, $errorCode)
 {
     $validator = new EntityExistsValidator($this->getEntityLookup(), $type);
     $result = $validator->validate($value);
     $this->assertFalse($result->isValid());
     $errors = $result->getErrors();
     $this->assertCount(1, $errors);
     $this->assertEquals($errorCode, $errors[0]->getCode());
     $localizer = new ValidatorErrorLocalizer();
     $msg = $localizer->getErrorMessage($errors[0]);
     $this->assertTrue($msg->exists(), $msg);
 }
 /**
  * @dataProvider provideValidate()
  */
 public function testValidate($validators, $value, $expectedErrorCount, $message)
 {
     $validator = new AlternativeValidator($validators);
     $result = $validator->validate($value);
     $errors = $result->getErrors();
     $this->assertEquals($expectedErrorCount === 0, $result->isValid(), $message);
     $this->assertCount($expectedErrorCount, $errors, $message);
     $localizer = new ValidatorErrorLocalizer();
     foreach ($errors as $error) {
         $msg = $localizer->getErrorMessage($error);
         $this->assertTrue($msg->exists(), $msg);
     }
 }
 /**
  * @dataProvider provideValidate()
  */
 public function testValidate($values, $normalize, $value, $expected)
 {
     $validator = new MembershipValidator($values, 'not-allowed', $normalize);
     $result = $validator->validate($value);
     $this->assertEquals($expected, $result->isValid());
     if (!$expected) {
         $errors = $result->getErrors();
         $this->assertCount(1, $errors);
         $this->assertTrue(in_array($errors[0]->getCode(), array('not-allowed')), $errors[0]->getCode());
         $localizer = new ValidatorErrorLocalizer();
         $msg = $localizer->getErrorMessage($errors[0]);
         $this->assertTrue($msg->exists(), $msg);
     }
 }
 /**
  * @dataProvider provideValidate()
  */
 public function testValidate($type, $value, $expected, $message)
 {
     $validator = new TypeValidator($type);
     $result = $validator->validate($value);
     $this->assertEquals($expected, $result->isValid(), $message);
     if (!$expected) {
         $errors = $result->getErrors();
         $this->assertCount(1, $errors, $message);
         $this->assertEquals('bad-type', $errors[0]->getCode(), $message);
         $localizer = new ValidatorErrorLocalizer();
         $msg = $localizer->getErrorMessage($errors[0]);
         $this->assertTrue($msg->exists(), $msg);
     }
 }
 /**
  * @dataProvider provideValidate()
  */
 public function testValidate($minLength, $maxLength, $measure, $value, $expected, $message)
 {
     $validator = new StringLengthValidator($minLength, $maxLength, $measure);
     $result = $validator->validate($value);
     $this->assertEquals($expected, $result->isValid(), $message);
     if (!$expected) {
         $errors = $result->getErrors();
         $this->assertCount(1, $errors, $message);
         $this->assertTrue(in_array($errors[0]->getCode(), array('too-long', 'too-short')), $message . "\n" . $errors[0]->getCode());
         $localizer = new ValidatorErrorLocalizer();
         $msg = $localizer->getErrorMessage($errors[0]);
         $this->assertTrue($msg->exists(), $msg);
     }
 }
 /**
  * @dataProvider provideValidate()
  */
 public function testValidate($schemes, $value, $expectedErrorCode)
 {
     $validator = new UrlValidator($schemes);
     $result = $validator->validate($value);
     if ($expectedErrorCode === null) {
         $this->assertTrue($result->isValid(), 'isValid');
     } else {
         $this->assertFalse($result->isValid(), 'isValid');
         $errors = $result->getErrors();
         $this->assertCount(1, $errors);
         $this->assertEquals($expectedErrorCode, $errors[0]->getCode(), 'error code');
         $localizer = new ValidatorErrorLocalizer();
         $msg = $localizer->getErrorMessage($errors[0]);
         $this->assertTrue($msg->exists(), 'message: ' . $msg);
     }
 }
 /**
  * @dataProvider provideValidate()
  */
 public function testValidate($validator, $value, $expected, $exception, $message)
 {
     if ($exception !== null) {
         $this->setExpectedException($exception);
     }
     $validator = new DataValueValidator($validator);
     $result = $validator->validate($value);
     $this->assertEquals($expected, $result->isValid(), $message);
     if (!$expected) {
         $errors = $result->getErrors();
         $this->assertCount(1, $errors, $message);
         $localizer = new ValidatorErrorLocalizer();
         $msg = $localizer->getErrorMessage($errors[0]);
         $this->assertTrue($msg->exists(), $msg);
     }
 }