NumberRangeValidatorTest.php 2.24 KB
Newer Older
1
<?php
2

3
4
declare(strict_types=1);

5
6
7
8
9
10
11
12
13
14
15
16
/*
 * This file is part of the TYPO3 CMS project.
 *
 * It is free software; you can redistribute it and/or modify it under
 * the terms of the GNU General Public License, either version 2
 * of the License, or any later version.
 *
 * For the full copyright and license information, please read the
 * LICENSE.txt file that was distributed with this source code.
 *
 * The TYPO3 project - inspiring people to share!
 */
Thomas Maroschik's avatar
Thomas Maroschik committed
17

18
namespace TYPO3\CMS\Extbase\Tests\Functional\Validation\Validator;
19

20
use TYPO3\CMS\Core\Localization\LanguageServiceFactory;
21
use TYPO3\CMS\Extbase\Validation\Validator\NumberRangeValidator;
22
use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
23

24
class NumberRangeValidatorTest extends FunctionalTestCase
25
{
26
27
28
    protected function setUp(): void
    {
        parent::setUp();
29
        $GLOBALS['LANG'] = $this->get(LanguageServiceFactory::class)->create('default');
30
    }
31

32
33
34
    /**
     * @test
     */
35
    public function numberRangeValidatorReturnsNoErrorForASimpleIntegerInRange(): void
36
    {
37
        $options = ['minimum' => 0, 'maximum' => 1000];
38
39
        $validator = new NumberRangeValidator();
        $validator->setOptions($options);
40
        self::assertFalse($validator->validate(10.5)->hasErrors());
41
    }
42

43
44
45
    /**
     * @test
     */
46
    public function numberRangeValidatorReturnsErrorForANumberOutOfRange(): void
47
    {
48
        $options = ['minimum' => 0, 'maximum' => 1000];
49
50
        $validator = new NumberRangeValidator();
        $validator->setOptions($options);
51
        self::assertTrue($validator->validate(1000.1)->hasErrors());
52
    }
53

54
55
56
    /**
     * @test
     */
57
    public function numberRangeValidatorReturnsNoErrorForANumberInReversedRange(): void
58
    {
59
        $options = ['minimum' => 1000, 'maximum' => 0];
60
61
        $validator = new NumberRangeValidator();
        $validator->setOptions($options);
62
        self::assertFalse($validator->validate(100)->hasErrors());
63
    }
64

65
66
67
    /**
     * @test
     */
68
    public function numberRangeValidatorReturnsErrorForAString(): void
69
    {
70
        $options = ['minimum' => 0, 'maximum' => 1000];
71
72
        $validator = new NumberRangeValidator();
        $validator->setOptions($options);
73
        self::assertTrue($validator->validate('not a number')->hasErrors());
74
    }
75
}