PageRenderTime 32ms CodeModel.GetById 9ms RepoModel.GetById 1ms app.codeStats 0ms

/Tests/Unit/Validation/Validator/EmailAddressValidatorTest.php

https://github.com/christianjul/FLOW3-Composer
PHP | 95 lines | 44 code | 11 blank | 40 comment | 0 complexity | 6496006e2c63ea37ed836dd73e07ab5e MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-3.0
  1. <?php
  2. namespace TYPO3\FLOW3\Tests\Unit\Validation\Validator;
  3. /* *
  4. * This script belongs to the FLOW3 framework. *
  5. * *
  6. * It is free software; you can redistribute it and/or modify it under *
  7. * the terms of the GNU Lesser General Public License, either version 3 *
  8. * of the License, or (at your option) any later version. *
  9. * *
  10. * The TYPO3 project - inspiring people to share! *
  11. * */
  12. require_once('AbstractValidatorTestcase.php');
  13. /**
  14. * Testcase for the email address validator
  15. *
  16. */
  17. class EmailAddressValidatorTest extends \TYPO3\FLOW3\Tests\Unit\Validation\Validator\AbstractValidatorTestcase {
  18. protected $validatorClassName = 'TYPO3\FLOW3\Validation\Validator\EmailAddressValidator';
  19. /**
  20. * @test
  21. */
  22. public function validateReturnsNoErrorIfTheGivenValueIsNull() {
  23. $this->assertFalse($this->validator->validate(NULL)->hasErrors());
  24. }
  25. /**
  26. * @test
  27. */
  28. public function validateReturnsNoErrorIfTheGivenValueIsAnEmptyString() {
  29. $this->assertFalse($this->validator->validate('')->hasErrors());
  30. }
  31. /**
  32. * Data provider with valid email addresses
  33. *
  34. * @return array
  35. */
  36. public function validAddresses() {
  37. return array(
  38. array('andreas.foerthner@netlogix.de'),
  39. array('user@localhost.localdomain'),
  40. array('info@guggenheim.museum'),
  41. array('just@test.invalid'),
  42. array('just+spam@test.de')
  43. );
  44. }
  45. /**
  46. * @test
  47. * @dataProvider validAddresses
  48. */
  49. public function emailAddressValidatorReturnsNoErrorsForAValidEmailAddress($address) {
  50. $this->assertFalse($this->validator->validate($address)->hasErrors());
  51. }
  52. /**
  53. * Data provider with invalid email addresses
  54. *
  55. * @return array
  56. */
  57. public function invalidAddresses() {
  58. return array(
  59. array('andreas.foerthner@'),
  60. array('@typo3.org'),
  61. array('someone@typo3.'),
  62. array('local@192.168.2'),
  63. array('local@192.168.270.1'),
  64. array('foo@bar.com' . chr(0)),
  65. array('foo@bar.org' . chr(10)),
  66. array('andreas@foerthner@example.com'),
  67. array('some@one.net ')
  68. );
  69. }
  70. /**
  71. * @test
  72. * @dataProvider invalidAddresses
  73. */
  74. public function emailAddressValidatorReturnsFalseForAnInvalidEmailAddress($address) {
  75. $this->assertTrue($this->validator->validate($address)->hasErrors());
  76. }
  77. /**
  78. * @test
  79. */
  80. public function emailValidatorCreatesTheCorrectErrorForAnInvalidEmailAddress() {
  81. $this->assertEquals(1, count($this->validator->validate('notAValidMail@Address')->getErrors()));
  82. }
  83. }
  84. ?>