Passed
Push — enhancement/more-config-option... ( e4871a...997483 )
by Matthew
03:47 queued 42s
created

LocatorTest::testGetPageCategories()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 1
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 testLocations()
43
    {
44
        $filter = Config::inst()->get(LocatorController::class, 'base_filter');
45
        $filterAny = Config::inst()->get(LocatorController::class, 'base_filter_any');
46
        $exclude = Config::inst()->get(LocatorController::class, 'base_exclude');
47
        $locations = Locator::get_locations($filter, $filterAny, $exclude);
48
        $locations2 = Location::get()->filter($filter)->filterAny($filterAny)->exclude($exclude);
49
        $this->assertEquals($locations->count(), $locations2->count());
50
    }
51
52
    /**
53
     *
54
     */
55
    public function testGetAllCategories()
56
    {
57
        $this->assertEquals(Locator::get_all_categories()->count(), 4);
58
    }
59
60
    /**
61
     *
62
     */
63
    public function testGetPageCategories()
64
    {
65
        $locator = $this->objFromFixture(Locator::class, 'locator1');
66
        $this->assertEquals($locator->getPageCategories()->count(), 1);
67
    }
68
69
    /**
70
     *
71
     */
72
    public function testLocator_categories_by_locator()
73
    {
74
        $categories = Locator::locator_categories_by_locator(0);
75
        $this->assertFalse($categories);
76
    }
77
78
    /**
79
     *
80
     */
81
    public function testLocatorCategoriesByLocator()
82
    {
83
84
        $locator = $this->objFromFixture(Locator::class, 'locator1');
85
        $this->assertEquals(Locator::locator_categories_by_locator($locator->ID)->count(), 1);
86
87
        $newLocator = Locator::create();
88
        $newLocator->Title = 'Locator 2';
89
        $newLocator->write();
90
91
        $this->assertEquals(Locator::locator_categories_by_locator($newLocator->ID)->count(), 0);
92
    }
93
94
    /**
95
     *
96
     */
97
    public function testGetRadii()
98
    {
99
        /** @var Locator $locator */
100
        $locator = Injector::inst()->create(Locator::class);
101
        $radii = [
102
            '0' => '5',
103
            '1' => '10',
104
            '2' => '15',
105
            '3' => '100',
106
        ];
107
        Config::modify()->set(Locator::class, 'radii', $radii);
108
        $this->assertEquals($radii, $locator->getRadii());
109
    }
110
111
    /**
112
     *
113
     */
114
    public function testGetRadiiArrayList()
115
    {
116
        /** @var Locator $locator */
117
        $locator = Injector::inst()->create(Locator::class);
118
        $this->assertInstanceOf(ArrayList::class, $locator->getRadiiArrayList());
119
    }
120
121
    /**
122
     *
123
     */
124
    public function testGetLimit()
125
    {
126
        /** @var Locator $locator */
127
        $locator = Injector::inst()->create(Locator::class);
128
        $this->assertEquals(50, $locator->getLimit());
129
    }
130
131
    /**
132
     *
133
     */
134
    public function testGetShowRadius()
135
    {
136
        /** @var Locator $locator */
137
        $locator = Injector::inst()->create(Locator::class);
138
        $this->assertTrue($locator->getShowRadius());
139
    }
140
141
    /**
142
     *
143
     */
144
    public function testGetUsedCategories()
145
    {
146
        /** @var Locator $locator */
147
        $locator = $this->objFromFixture(Locator::class, 'locator1');
148
149
        $categories = $locator->getUsedCategories()->toArray();
150
        $this->assertEquals(1, count($categories));
151
    }
152
153
    /**
154
     *
155
     */
156
    public function testGetInfoWindowTemplate()
157
    {
158
        /** @var Locator $object */
159
        $object = Injector::inst()->create(Locator::class);
160
        $template = $object->getInfoWindowTemplate();
161
        // get rid of cache ending
162
        $template = preg_replace('/\?.*$/', '', $template);
163
        $this->assertStringEndsWith('client/infowindow-description.html', $template);
164
    }
165
166
    /**
167
     *
168
     */
169
    public function testGetListTemplate()
170
    {
171
        /** @var Locator $object */
172
        $object = Injector::inst()->create(Locator::class);
173
        $template = $object->getListTemplate();
174
        // get rid of cache ending
175
        $template = preg_replace('/\?.*$/', '', $template);
176
        $this->assertStringEndsWith('client/location-list-description.html', $template);
177
    }
178
}
179