Passed
Pull Request — master (#174)
by Matthew
05:01
created

LocatorTest::testGetCategories()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 7
rs 9.4285
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
58
        $this->assertEquals(Locator::get_all_categories()->count(), 4);
59
    }
60
61
    /**
62
     *
63
     */
64
    public function testGetPageCategories()
65
    {
66
        $locator = $this->objFromFixture(Locator::class, 'locator1');
67
        $this->assertEquals($locator->getPageCategories()->count(), 2);
68
    }
69
70
    /**
71
     *
72
     */
73
    public function testLocatorCategoriesByLocator()
74
    {
75
76
        $locator = $this->objFromFixture(Locator::class, 'locator1');
77
        $this->assertEquals(Locator::locator_categories_by_locator($locator->ID)->count(), 2);
78
79
        $newLocator = Locator::create();
80
        $newLocator->Title = 'Locator 2';
81
        $newLocator->write();
82
83
        $this->assertEquals(Locator::locator_categories_by_locator($newLocator->ID)->count(), 0);
84
85
    }
86
87
    /**
88
     *
89
     */
90
    public function testGetRadii()
91
    {
92
        /** @var Locator $locator */
93
        $locator = Injector::inst()->create(Locator::class);
94
        $radii = [
95
            '0' => '5',
96
            '1' => '10',
97
            '2' => '15',
98
            '3' => '100',
99
        ];
100
        Config::modify()->set(Locator::class, 'radii', $radii);
101
        $this->assertEquals($radii, $locator->getRadii());
102
    }
103
104
    /**
105
     *
106
     */
107
    public function testGetRadiiArrayList()
108
    {
109
        /** @var Locator $locator */
110
        $locator = Injector::inst()->create(Locator::class);
111
        $this->assertInstanceOf(ArrayList::class, $locator->getRadiiArrayList());
112
    }
113
114
    /**
115
     *
116
     */
117
    public function testGetLimit()
118
    {
119
        /** @var Locator $locator */
120
        $locator = Injector::inst()->create(Locator::class);
121
        $this->assertEquals(50, $locator->getLimit());
122
    }
123
124
    /**
125
     *
126
     */
127
    public function testGetShowRadius()
128
    {
129
        /** @var Locator $locator */
130
        $locator = Injector::inst()->create(Locator::class);
131
        $this->assertTrue($locator->getShowRadius());
132
    }
133
134
    /**
135
     *
136
     */
137
    public function testGetCategories()
138
    {
139
        /** @var Locator $locator */
140
        $locator = $this->objFromFixture(Locator::class, 'locator1');
141
142
        $categories = $locator->getCategories()->toArray();
143
        $this->assertEquals(1, count($categories));
144
    }
145
146
    /**
147
     *
148
     */
149 View Code Duplication
    public function testGetInfoWindowTemplate()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
150
    {
151
        /** @var Locator $object */
152
        $object = Injector::inst()->create(Locator::class);
153
        $template = $object->getInfoWindowTemplate();
154
        // get rid of cache ending
155
        $template = preg_replace('/\?.*$/', '', $template);
156
        $this->assertStringEndsWith('client/infowindow-description.html', $template);
157
    }
158
159
    /**
160
     *
161
     */
162 View Code Duplication
    public function testGetListTemplate()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
163
    {
164
        /** @var Locator $object */
165
        $object = Injector::inst()->create(Locator::class);
166
        $template = $object->getListTemplate();
167
        // get rid of cache ending
168
        $template = preg_replace('/\?.*$/', '', $template);
169
        $this->assertStringEndsWith('client/location-list-description.html', $template);
170
    }
171
}
172