Passed
Push — master ( 15c2d1...14bd8a )
by Matthew
08:25
created

LocatorControllerTest::testXml()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 7
nc 1
nop 0
dl 0
loc 13
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Dynamic\Locator\Tests;
4
5
use \DOMDocument;
6
use Dynamic\Locator\LocationCategory;
7
use Dynamic\Locator\Locator;
8
use Dynamic\Locator\LocatorController;
9
use SilverStripe\Dev\FunctionalTest;
10
use SilverStripe\Forms\FieldList;
11
use SilverStripe\Forms\Form;
12
use SilverStripe\View\ViewableData;
13
14
/**
15
 * Class LocatorControllerTest
16
 * @package Dynamic\Locator\Tests
17
 */
18
class LocatorControllerTest extends FunctionalTest
19
{
20
21
    /**
22
     * @var string
23
     */
24
    protected static $fixture_file = '../fixtures.yml';
25
26
    /**
27
     * @var bool
28
     */
29
    protected static $use_draft_site = true;
30
31
    /**
32
     *
33
     */
34
    public function testIndex()
35
    {
36
        $locator = $this->objFromFixture(Locator::class, 'locator1');
37
        $controller = LocatorController::create($locator);
0 ignored issues
show
Bug introduced by
$locator of type SilverStripe\ORM\DataObject is incompatible with the type array expected by parameter $args of SilverStripe\View\ViewableData::create(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

37
        $controller = LocatorController::create(/** @scrutinizer ignore-type */ $locator);
Loading history...
38
        $this->assertInstanceOf(ViewableData::class, $controller->index($controller->getRequest()));
39
    }
40
41
    /**
42
     *
43
     */
44
    public function testXml()
45
    {
46
        /** @var Locator $locator */
47
        $locator = $this->objFromFixture(Locator::class, 'locator1');
48
        $page = $this->get($locator->Link('xml'));
49
50
        $this->assertEquals(200, $page->getStatusCode());
51
        $this->assertEquals('application/xml', $page->getHeader('content-type'));
52
53
        $dom = new DOMDocument();
54
        // true if it loads, false if it doesn't
55
        $valid = $dom->loadXML($page->getBody());
56
        $this->assertTrue($valid);
57
    }
58
59
    /**
60
     *
61
     */
62
    public function testJson()
63
    {
64
        /** @var Locator $locator */
65
        $locator = $this->objFromFixture(Locator::class, 'locator1');
66
        $page = $this->get($locator->Link('json'));
67
68
        $this->assertEquals(200, $page->getStatusCode());
69
        $this->assertEquals('application/json', $page->getHeader('content-type'));
70
71
        $json = json_decode($page->getBody());
72
        // if it is null its not valid
73
        $this->assertNotNull($json);
74
    }
75
76
    /**
77
     *
78
     */
79
    public function testLocationSearch()
80
    {
81
        $locator = $this->objFromFixture(Locator::class, 'locator1');
82
        $object = LocatorController::create($locator);
0 ignored issues
show
Bug introduced by
$locator of type SilverStripe\ORM\DataObject is incompatible with the type array expected by parameter $args of SilverStripe\View\ViewableData::create(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

82
        $object = LocatorController::create(/** @scrutinizer ignore-type */ $locator);
Loading history...
83
        $form = $object->LocationSearch();
84
        $this->assertInstanceOf(Form::class, $form);
85
86
        $category = $this->objFromFixture(LocationCategory::class, 'service');
87
        $category2 = $this->objFromFixture(LocationCategory::class, 'manufacturing');
88
        $locator->Categories()->add($category);
89
        $locator->Categories()->add($category2);
90
91
        $form = $object->LocationSearch();
92
        $fields = $form->Fields();
93
        $this->assertInstanceOf(FieldList::class, $fields);
94
    }
95
96
}
97