Welcome to mirror list, hosted at ThFree Co, Russian Federation.

DateTimeTest.php « Validator « Unit « PHPUnit « tests - github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: b430efd78669f585372579370c56e6d83d7001c3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<?php
/**
 * Piwik - free/libre analytics platform
 *
 * @link https://matomo.org
 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
 */

namespace Piwik\Tests\Unit\Translation\Loader;

use Piwik\Validators\DateTime;

/**
 * @group Validator
 * @group DateTime
 * @group DateTimeTest
 */
class DateTimeTest extends \PHPUnit_Framework_TestCase
{
    public function test_validate_successValueNotEmpty()
    {
        $this->validate('2014-05-06 10:13:14');
        $this->validate('2014-05-06T10:13:14');
        $this->validate('2014-05-06 10:13:14Z');
        $this->validate('2014-05-06T10:13:14Z');
    }

    public function test_validate_successValueMayBeEmpty()
    {
        $this->validate(false);
        $this->validate('');
    }

    /**
     * @dataProvider getWrongFormat
     * @expectedException \Piwik\Validators\Exception
     * @expectedExceptionMessage General_ValidatorErrorInvalidDateTimeFormat
     */
    public function test_validate_failInvalidFormat($date)
    {
        $this->validate($date);
    }

    public function getWrongFormat()
    {
        return array(
            array('2014-05-0610:13:14'),
            array('2014-05-06 10:13:14 '),
            array('2014/05/06 10:13:14'),
            array('10:13:14'),
            array('2014/05/06'),
            array('10:13:14 2014-05-06'),
            array('1577873410'),
            array('foo'),
            array('0'),
        );
    }

    /**
     * @expectedException \Piwik\Validators\Exception
     * @expectedExceptionMessage General_ExceptionInvalidDateFormat
     */
    public function test_validate_invalidDate()
    {
        $this->validate('2014-15-26 90:43:32');
    }

    private function validate($value)
    {
        $validator = new DateTime();
        $validator->validate($value);
    }

}