summaryrefslogtreecommitdiff
path: root/tests/units/Validator/LinkValidatorTest.php
blob: a4ec170e6300dd8a191034b36d652aecd820bbd2 (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
<?php

require_once __DIR__.'/../Base.php';

use Kanboard\Validator\LinkValidator;

class LinkValidatorTest extends Base
{
    public function testValidateCreation()
    {
        $linkValidator = new LinkValidator($this->container);

        $r = $linkValidator->validateCreation(array('label' => 'a'));
        $this->assertTrue($r[0]);

        $r = $linkValidator->validateCreation(array('label' => 'a', 'opposite_label' => 'b'));
        $this->assertTrue($r[0]);

        $r = $linkValidator->validateCreation(array('label' => 'relates to'));
        $this->assertFalse($r[0]);

        $r = $linkValidator->validateCreation(array('label' => 'a', 'opposite_label' => 'a'));
        $this->assertFalse($r[0]);

        $r = $linkValidator->validateCreation(array('label' => ''));
        $this->assertFalse($r[0]);
    }

    public function testValidateModification()
    {
        $validator = new LinkValidator($this->container);

        $r = $validator->validateModification(array('id' => 20, 'label' => 'a', 'opposite_id' => 0));
        $this->assertTrue($r[0]);

        $r = $validator->validateModification(array('id' => 20, 'label' => 'a', 'opposite_id' => '1'));
        $this->assertTrue($r[0]);

        $r = $validator->validateModification(array('id' => 20, 'label' => 'relates to', 'opposite_id' => '1'));
        $this->assertFalse($r[0]);

        $r = $validator->validateModification(array('id' => 20, 'label' => '', 'opposite_id' => '1'));
        $this->assertFalse($r[0]);

        $r = $validator->validateModification(array('label' => '', 'opposite_id' => '1'));
        $this->assertFalse($r[0]);

        $r = $validator->validateModification(array('id' => 20, 'opposite_id' => '1'));
        $this->assertFalse($r[0]);

        $r = $validator->validateModification(array('label' => 'test'));
        $this->assertFalse($r[0]);
    }
}