ShortURLTest::testGetLongURL()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

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