Completed
Pull Request — master (#192)
by Matthew
03:23
created

LocatorTest::testLocations()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 6
nc 1
nop 0
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Dynamic\Locator\Tests;
4
5
use Dynamic\Locator\Location;
6
use Dynamic\Locator\LocationCategory;
7
use Dynamic\Locator\Locator;
8
use Dynamic\Locator\LocatorController;
9
use Dynamic\SilverStripeGeocoder\GoogleGeocoder;
10
use SilverStripe\Core\Config\Config;
11
use SilverStripe\Core\Injector\Injector;
12
use SilverStripe\Dev\FunctionalTest;
13
use SilverStripe\Forms\FieldList;
14
use SilverStripe\Forms\Form;
15
use SilverStripe\ORM\ArrayList;
16
use SilverStripe\ORM\FieldType\DBHTMLText;
17
use SilverStripe\View\ViewableData;
18
19
/**
20
 * Class LocatorTest
21
 */
22
class LocatorTest extends FunctionalTest
23
{
24
    /**
25
     * @var string
26
     */
27
    protected static $fixture_file = '../fixtures.yml';
28
29
    /**
30
     *
31
     */
32
    public function testGetCMSFields()
33
    {
34
        /** @var Locator $locator */
35
        $locator = Injector::inst()->create(Locator::class);
36
        $this->assertInstanceOf(FieldList::class, $locator->getCMSFields());
37
    }
38
39
    /**
40
     *
41
     */
42
    public function testGetAllCategories()
43
    {
44
        $this->assertEquals(Locator::get_all_categories()->count(), 4);
45
    }
46
47
    /**
48
     *
49
     */
50
    public function testGetPageCategories()
51
    {
52
        $locator = $this->objFromFixture(Locator::class, 'locator1');
53
        $this->assertEquals($locator->getPageCategories()->count(), 1);
54
    }
55
56
    /**
57
     *
58
     */
59
    public function testLocator_categories_by_locator()
60
    {
61
        $categories = Locator::locator_categories_by_locator(0);
62
        $this->assertFalse($categories);
63
    }
64
65
    /**
66
     *
67
     */
68
    public function testLocatorCategoriesByLocator()
69
    {
70
71
        $locator = $this->objFromFixture(Locator::class, 'locator1');
72
        $this->assertEquals(Locator::locator_categories_by_locator($locator->ID)->count(), 1);
73
74
        $newLocator = Locator::create();
75
        $newLocator->Title = 'Locator 2';
76
        $newLocator->write();
77
78
        $this->assertEquals(Locator::locator_categories_by_locator($newLocator->ID)->count(), 0);
79
80
    }
81
82
    /**
83
     *
84
     */
85
    public function testGetRadii()
86
    {
87
        /** @var Locator $locator */
88
        $locator = Injector::inst()->create(Locator::class);
89
        $radii = [
90
            '0' => '5',
91
            '1' => '10',
92
            '2' => '15',
93
            '3' => '100',
94
        ];
95
        Config::modify()->set(Locator::class, 'radii', $radii);
96
        $this->assertEquals($radii, $locator->getRadii());
97
    }
98
99
    /**
100
     *
101
     */
102
    public function testGetRadiiArrayList()
103
    {
104
        /** @var Locator $locator */
105
        $locator = Injector::inst()->create(Locator::class);
106
        $this->assertInstanceOf(ArrayList::class, $locator->getRadiiArrayList());
107
    }
108
109
    /**
110
     *
111
     */
112
    public function testGetShowRadius()
113
    {
114
        /** @var Locator $locator */
115
        $locator = Injector::inst()->create(Locator::class);
116
        $this->assertTrue($locator->getShowRadius());
117
    }
118
119
    /**
120
     *
121
     */
122
    public function testGetUsedCategories()
123
    {
124
        /** @var Locator $locator */
125
        $locator = $this->objFromFixture(Locator::class, 'locator1');
126
127
        $categories = $locator->getUsedCategories()->toArray();
128
        $this->assertEquals(1, count($categories));
129
    }
130
131
    /**
132
     *
133
     */
134
    public function testGetInfoWindowTemplate()
135
    {
136
        /** @var Locator $object */
137
        $object = Injector::inst()->create(Locator::class);
138
        $template = $object->getInfoWindowTemplate();
139
        // get rid of cache ending
140
        $template = preg_replace('/\?.*$/', '', $template);
141
        $this->assertStringEndsWith('client/infowindow-description.html', $template);
142
    }
143
144
    /**
145
     *
146
     */
147
    public function testGetListTemplate()
148
    {
149
        /** @var Locator $object */
150
        $object = Injector::inst()->create(Locator::class);
151
        $template = $object->getListTemplate();
152
        // get rid of cache ending
153
        $template = preg_replace('/\?.*$/', '', $template);
154
        $this->assertStringEndsWith('client/location-list-description.html', $template);
155
    }
156
}
157