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

ShortURLTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 21
dl 0
loc 48
c 0
b 0
f 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testGetCMSFields() 0 5 1
A testGetValidate() 0 16 1
A testGetLongURL() 0 5 1
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
}