[BUGFIX] Respect extendToSubpages on generating preview urls
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Tests / Unit / Validation / Validator / EmailAddressValidatorTest.php
1 <?php
2
3 /*
4 * This file is part of the TYPO3 CMS project.
5 *
6 * It is free software; you can redistribute it and/or modify it under
7 * the terms of the GNU General Public License, either version 2
8 * of the License, or any later version.
9 *
10 * For the full copyright and license information, please read the
11 * LICENSE.txt file that was distributed with this source code.
12 *
13 * The TYPO3 project - inspiring people to share!
14 */
15
16 namespace TYPO3\CMS\Extbase\Tests\Unit\Validation\Validator;
17
18 use TYPO3\CMS\Extbase\Validation\Validator\EmailAddressValidator;
19 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
20
21 /**
22 * Test case
23 */
24 class EmailAddressValidatorTest extends UnitTestCase
25 {
26 /**
27 * @test
28 */
29 public function emailAddressValidatorReturnsNoErrorsForAValidEmailAddress(): void
30 {
31 /** @var \TYPO3\CMS\Extbase\Validation\Validator\EmailAddressValidator|\PHPUnit\Framework\MockObject\MockObject $subject */
32 $subject = $this->getMockBuilder(EmailAddressValidator::class)
33 ->onlyMethods(['translateErrorMessage'])
34 ->getMock();
35 self::assertFalse($subject->validate('valid.email@example.com')->hasErrors());
36 }
37
38 /**
39 * @test
40 */
41 public function emailAddressValidatorReturnsFalseForAnInvalidEmailAddress(): void
42 {
43 /** @var \TYPO3\CMS\Extbase\Validation\Validator\EmailAddressValidator|\PHPUnit\Framework\MockObject\MockObject $subject */
44 $subject = $this->getMockBuilder(EmailAddressValidator::class)
45 ->onlyMethods(['translateErrorMessage'])
46 ->getMock();
47 self::assertTrue($subject->validate('@typo3.org')->hasErrors());
48 }
49
50 /**
51 * @test
52 */
53 public function emailAddressValidatorReturnsFalseForNonStringAddress(): void
54 {
55 /** @var \TYPO3\CMS\Extbase\Validation\Validator\EmailAddressValidator|\PHPUnit\Framework\MockObject\MockObject $subject */
56 $subject = $this->getMockBuilder(EmailAddressValidator::class)
57 ->onlyMethods(['translateErrorMessage'])
58 ->getMock();
59 self::assertTrue($subject->validate(123)->hasErrors());
60 }
61
62 /**
63 * @test
64 */
65 public function emailValidatorCreatesTheCorrectErrorForAnInvalidEmailAddress(): void
66 {
67 /** @var \TYPO3\CMS\Extbase\Validation\Validator\EmailAddressValidator|\PHPUnit\Framework\MockObject\MockObject $subject */
68 $subject = $this->getMockBuilder(EmailAddressValidator::class)
69 ->onlyMethods(['translateErrorMessage'])
70 ->getMock();
71 self::assertCount(1, $subject->validate('someone@typo3.')->getErrors());
72 }
73 }