LocatorTest   A
last analyzed

Complexity

Total Complexity 14

Size/Duplication

Total Lines 165
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 48
dl 0
loc 165
rs 10
c 0
b 0
f 0
wmc 14

14 Methods

Rating   Name   Duplication   Size   Complexity  
A testGetShowRadius() 0 5 1
A testGetCMSFields() 0 5 1
A testGetListTemplate() 0 8 1
A testLocator_categories_by_locator() 0 4 1
A testLocations() 0 8 1
A testGetUsedCategories() 0 7 1
A testGetAllCategories() 0 3 1
A testLocatorCategoriesByLocator() 0 11 1
A testGetRadiiArrayList() 0 5 1
A testGetPageCategories() 0 4 1
A testGetRadii() 0 12 1
A testGetLimit() 0 5 1
A testGetInfoWindowTemplate() 0 8 1
A setUp() 0 5 1
1
<?php
2
3
namespace Dynamic\Locator\Tests\Page;
4
5
use Dynamic\Locator\Location;
6
use Dynamic\Locator\Page\Locator;
7
use Dynamic\Locator\Page\LocatorController;
8
use SilverStripe\Core\Config\Config;
9
use SilverStripe\Core\Injector\Injector;
10
use SilverStripe\Dev\FunctionalTest;
11
use SilverStripe\Forms\FieldList;
12
use SilverStripe\ORM\ArrayList;
13
14
/**
15
 * Class LocatorTest
16
 * @package Dynamic\Locator\Tests\Page
17
 */
18
class LocatorTest extends FunctionalTest
19
{
20
    /**
21
     * @var string
22
     */
23
    protected static $fixture_file = 'locatorfixture.yml';
24
25
    /**
26
     *
27
     */
28
    protected function setUp()
29
    {
30
        parent::setUp();
31
32
        Config::modify()->set(Locator::class, 'location_class', Location::class);
33
    }
34
35
    /**
36
     *
37
     */
38
    public function testGetCMSFields()
39
    {
40
        /** @var Locator $locator */
41
        $locator = Injector::inst()->create(Locator::class);
42
        $this->assertInstanceOf(FieldList::class, $locator->getCMSFields());
43
    }
44
45
    /**
46
     *
47
     */
48
    public function testLocations()
49
    {
50
        $filter = Config::inst()->get(LocatorController::class, 'base_filter');
51
        $filterAny = Config::inst()->get(LocatorController::class, 'base_filter_any');
52
        $exclude = Config::inst()->get(LocatorController::class, 'base_exclude');
53
        $locations = Locator::get_locations($filter, $filterAny, $exclude);
54
        $locations2 = Location::get()->filter($filter)->filterAny($filterAny)->exclude($exclude);
55
        $this->assertEquals($locations->count(), $locations2->count());
56
    }
57
58
    /**
59
     *
60
     */
61
    public function testGetAllCategories()
62
    {
63
        $this->assertEquals(Locator::get_all_categories()->count(), 4);
64
    }
65
66
    /**
67
     *
68
     */
69
    public function testGetPageCategories()
70
    {
71
        $locator = $this->objFromFixture(Locator::class, 'locator1');
72
        $this->assertEquals($locator->getPageCategories()->count(), 1);
73
    }
74
75
    /**
76
     *
77
     */
78
    public function testLocator_categories_by_locator()
79
    {
80
        $categories = Locator::locator_categories_by_locator(0);
81
        $this->assertFalse($categories);
82
    }
83
84
    /**
85
     *
86
     */
87
    public function testLocatorCategoriesByLocator()
88
    {
89
90
        $locator = $this->objFromFixture(Locator::class, 'locator1');
91
        $this->assertEquals(Locator::locator_categories_by_locator($locator->ID)->count(), 1);
92
93
        $newLocator = Locator::create();
94
        $newLocator->Title = 'Locator 2';
95
        $newLocator->write();
96
97
        $this->assertEquals(Locator::locator_categories_by_locator($newLocator->ID)->count(), 0);
98
    }
99
100
    /**
101
     *
102
     */
103
    public function testGetRadii()
104
    {
105
        /** @var Locator $locator */
106
        $locator = Injector::inst()->create(Locator::class);
107
        $radii = [
108
            '0' => '5',
109
            '1' => '10',
110
            '2' => '15',
111
            '3' => '100',
112
        ];
113
        Config::modify()->set(Locator::class, 'radii', $radii);
114
        $this->assertEquals($radii, $locator->getRadii());
115
    }
116
117
    /**
118
     *
119
     */
120
    public function testGetRadiiArrayList()
121
    {
122
        /** @var Locator $locator */
123
        $locator = Injector::inst()->create(Locator::class);
124
        $this->assertInstanceOf(ArrayList::class, $locator->getRadiiArrayList());
125
    }
126
127
    /**
128
     *
129
     */
130
    public function testGetLimit()
131
    {
132
        /** @var Locator $locator */
133
        $locator = Injector::inst()->create(Locator::class);
134
        $this->assertEquals(50, $locator->getLimit());
135
    }
136
137
    /**
138
     *
139
     */
140
    public function testGetShowRadius()
141
    {
142
        /** @var Locator $locator */
143
        $locator = Injector::inst()->create(Locator::class);
144
        $this->assertTrue($locator->getShowRadius());
145
    }
146
147
    /**
148
     *
149
     */
150
    public function testGetUsedCategories()
151
    {
152
        /** @var Locator $locator */
153
        $locator = $this->objFromFixture(Locator::class, 'locator1');
154
155
        $categories = $locator->getUsedCategories()->toArray();
156
        $this->assertEquals(1, count($categories));
157
    }
158
159
    /**
160
     *
161
     */
162
    public function testGetInfoWindowTemplate()
163
    {
164
        /** @var Locator $object */
165
        $object = Injector::inst()->create(Locator::class);
166
        $template = $object->getInfoWindowTemplate();
167
        // get rid of cache ending
168
        $template = preg_replace('/\?.*$/', '', $template);
169
        $this->assertStringEndsWith('client/infowindow-description.html', $template);
170
    }
171
172
    /**
173
     *
174
     */
175
    public function testGetListTemplate()
176
    {
177
        /** @var Locator $object */
178
        $object = Injector::inst()->create(Locator::class);
179
        $template = $object->getListTemplate();
180
        // get rid of cache ending
181
        $template = preg_replace('/\?.*$/', '', $template);
182
        $this->assertStringEndsWith('client/location-list-description.html', $template);
183
    }
184
}
185