Passed
Pull Request — master (#223)
by Nic
02:34
created

LocatorTest::testGetPageCategories()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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