Completed
Pull Request — master (#4)
by Jason
11:47
created

ShortURLTest::testGetValidate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 17
rs 9.4285
cc 1
eloc 13
nc 1
nop 0
1
<?php
2
3
namespace Dynamic\ShortURL\Test;
4
5
use Dynamic\ShortUR\Model\ShortURL;
6
use SilverStripe\Dev\SapphireTest;
7
8
class ShortURLTest extends SapphireTest
9
{
10
    /**
11
     * @var array
12
     */
13
    protected static $fixture_file = [
14
        '../fixtures.yml',
15
    ];
16
17
    /**
18
     *
19
     */
20
    public function testGetCMSFields()
21
    {
22
        $object = $this->objFromFixture(ShortURL::class, 'one');
23
        $fields = $object->getCMSFields();
24
        $this->assertInstanceOf('FieldList', $fields);
25
    }
26
27
    /**
28
     *
29
     */
30
    public function testGetValidate()
31
    {
32
        $object = $this->objFromFixture(ShortURL::class, 'one');
33
        $object->Title = '';
34
        $this->expectException('ValidationException');
35
        $object->write();
36
37
        $this->objFromFixture(ShortURL::class, 'one');
38
        $object->URL = '';
39
        $this->expectException('ValidationException');
40
        $object->write();
41
42
        $this->objFromFixture(ShortURL::class, 'one');
43
        $object->CampaignSource = '';
44
        $this->expectException('ValidationException');
45
        $object->write();
46
    }
47
48
    /**
49
     *
50
     */
51
    function testGetLongURL()
52
    {
53
        $object = $this->objFromFixture(ShortURL::class, 'one');
54
        $expected = $object->URL . '?utm_source=' . $object->CampaignSource;
55
        $this->assertEquals($expected, $object->getLongURL());
56
    }
57
}