Completed
Pull Request — master (#207)
by Jason
08:34 queued 06:14
created
tests/objects/LocationTest.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -23,7 +23,7 @@
 block discarded – undo
23 23
     public function testGetCoords()
24 24
     {
25 25
         $location = $this->objFromFixture(Location::class, 'dynamic');
26
-        $coords = ((int)$location->Lat != 0 && (int)$location->Lng != 0) ? 'true' : 'false';
26
+        $coords = ((int) $location->Lat != 0 && (int) $location->Lng != 0) ? 'true' : 'false';
27 27
         $this->assertEquals($coords, $location->getCoords());
28 28
     }
29 29
 
Please login to merge, or discard this patch.
Indentation   +166 added lines, -166 removed lines patch added patch discarded remove patch
@@ -14,170 +14,170 @@
 block discarded – undo
14 14
  */
15 15
 class LocationTest extends SapphireTest
16 16
 {
17
-    /**
18
-     * @var string
19
-     */
20
-    protected static $fixture_file = '../fixtures.yml';
21
-
22
-    /**
23
-     *
24
-     */
25
-    public function testGetCoords()
26
-    {
27
-        $location = $this->objFromFixture(Location::class, 'dynamic');
28
-        $coords = ((int)$location->Lat != 0 && (int)$location->Lng != 0) ? 'true' : 'false';
29
-        $this->assertEquals($coords, $location->getCoords());
30
-    }
31
-
32
-    /**
33
-     *
34
-     */
35
-    public function testFieldLabels()
36
-    {
37
-        $location = $this->objFromFixture(Location::class, 'dynamic');
38
-        $labels = $location->FieldLabels();
39
-        $expected = array(
40
-            'Title' => 'Name',
41
-            'Featured' => 'Featured',
42
-            'Website' => 'Website',
43
-            'Phone' => 'Phone',
44
-            'Email' => 'Email',
45
-            'Fax' => 'Fax',
46
-            'Address' => 'Address',
47
-            'City' => 'City',
48
-            'State' => 'State',
49
-            'PostalCode' => 'Postal Code',
50
-            'Country' => 'Country',
51
-            'Lat' => 'Lat',
52
-            'Lng' => 'Lng',
53
-            'Categories' => 'Categories',
54
-            'Category.Name' => 'Category',
55
-            'Category.ID' => 'Category',
56
-            'Featured.NiceAsBoolean' => 'Featured',
57
-            'Import_ID' => 'Import_ID',
58
-            'Version' => 'Version',
59
-            'Versions' => 'Versions',
60
-            'Address2' => 'Address2',
61
-            'LinkTracking' => 'Link Tracking',
62
-            'FileTracking' => 'File Tracking',
63
-        );
64
-        $this->assertEquals($expected, $labels);
65
-    }
66
-
67
-    /**
68
-     *
69
-     */
70
-    public function testGetCMSFields()
71
-    {
72
-        $object = new Location();
73
-        $fieldset = $object->getCMSFields();
74
-        $this->assertinstanceOf(FieldList::class, $fieldset);
75
-    }
76
-
77
-    /**
78
-     *
79
-     */
80
-    public function testCanView()
81
-    {
82
-        $object = $this->objFromFixture(Location::class, 'dynamic');
83
-        $object->write();
84
-
85
-        $this->assertTrue($object->canView());
86
-
87
-        $nullMember = Member::create();
88
-        $nullMember->write();
89
-
90
-        $this->assertTrue($object->canView($nullMember));
91
-
92
-        $nullMember->delete();
93
-    }
94
-
95
-    /**
96
-     *
97
-     */
98
-    public function testCanEdit()
99
-    {
100
-        $object = $this->objFromFixture(Location::class, 'dynamic');
101
-        $object->write();
102
-
103
-        $objectID = $object->ID;
104
-
105
-        //test permissions per permission setting
106
-        $create = $this->objFromFixture(Member::class, 'locationcreate');
107
-        $edit = $this->objFromFixture(Member::class, 'locationedit');
108
-        $delete = $this->objFromFixture(Member::class, 'locationdelete');
109
-
110
-        $originalTitle = $object->Title;
111
-        $this->assertEquals($originalTitle, 'Dynamic, Inc.');
112
-
113
-        $this->assertTrue($object->canEdit($edit));
114
-        $this->assertFalse($object->canEdit($create));
115
-        $this->assertFalse($object->canEdit($delete));
116
-
117
-        $object->Title = 'Changed Title';
118
-        $object->write();
119
-
120
-        $testEdit = Location::get()->byID($objectID);
121
-        $this->assertEquals($testEdit->Title, 'Changed Title');
122
-    }
123
-
124
-    /**
125
-     *
126
-     */
127
-    public function testCanDelete()
128
-    {
129
-        $object = $this->objFromFixture(Location::class, 'dynamic');
130
-        $object->write();
131
-
132
-        //test permissions per permission setting
133
-        $create = $this->objFromFixture(Member::class, 'locationcreate');
134
-        $edit = $this->objFromFixture(Member::class, 'locationedit');
135
-        $delete = $this->objFromFixture(Member::class, 'locationdelete');
136
-
137
-        $this->assertTrue($object->canDelete($delete));
138
-        $this->assertFalse($object->canDelete($create));
139
-        $this->assertFalse($object->canDelete($edit));
140
-
141
-        $checkObject = $object;
142
-        $object->delete();
143
-
144
-        $this->assertEquals($checkObject->ID, 0);
145
-    }
146
-
147
-    /**
148
-     *
149
-     */
150
-    public function testCanCreate()
151
-    {
152
-        $object = singleton(Location::class);
153
-
154
-        //test permissions per permission setting
155
-        $create = $this->objFromFixture(Member::class, 'locationcreate');
156
-        $edit = $this->objFromFixture(Member::class, 'locationedit');
157
-        $delete = $this->objFromFixture(Member::class, 'locationdelete');
158
-
159
-        $this->assertTrue($object->canCreate($create));
160
-        $this->assertFalse($object->canCreate($edit));
161
-        $this->assertFalse($object->canCreate($delete));
162
-
163
-        $nullMember = Member::create();
164
-        $nullMember->write();
165
-        $this->assertFalse($object->canCreate($nullMember));
166
-
167
-        $nullMember->delete();
168
-    }
169
-
170
-    /**
171
-     *
172
-     */
173
-    public function testProvidePermissions()
174
-    {
175
-        $object = Location::create();
176
-        $expected = array(
177
-            'Location_EDIT' => 'Edit a Location',
178
-            'Location_DELETE' => 'Delete a Location',
179
-            'Location_CREATE' => 'Create a Location',
180
-        );
181
-        $this->assertEquals($expected, $object->providePermissions());
182
-    }
17
+	/**
18
+	 * @var string
19
+	 */
20
+	protected static $fixture_file = '../fixtures.yml';
21
+
22
+	/**
23
+	 *
24
+	 */
25
+	public function testGetCoords()
26
+	{
27
+		$location = $this->objFromFixture(Location::class, 'dynamic');
28
+		$coords = ((int)$location->Lat != 0 && (int)$location->Lng != 0) ? 'true' : 'false';
29
+		$this->assertEquals($coords, $location->getCoords());
30
+	}
31
+
32
+	/**
33
+	 *
34
+	 */
35
+	public function testFieldLabels()
36
+	{
37
+		$location = $this->objFromFixture(Location::class, 'dynamic');
38
+		$labels = $location->FieldLabels();
39
+		$expected = array(
40
+			'Title' => 'Name',
41
+			'Featured' => 'Featured',
42
+			'Website' => 'Website',
43
+			'Phone' => 'Phone',
44
+			'Email' => 'Email',
45
+			'Fax' => 'Fax',
46
+			'Address' => 'Address',
47
+			'City' => 'City',
48
+			'State' => 'State',
49
+			'PostalCode' => 'Postal Code',
50
+			'Country' => 'Country',
51
+			'Lat' => 'Lat',
52
+			'Lng' => 'Lng',
53
+			'Categories' => 'Categories',
54
+			'Category.Name' => 'Category',
55
+			'Category.ID' => 'Category',
56
+			'Featured.NiceAsBoolean' => 'Featured',
57
+			'Import_ID' => 'Import_ID',
58
+			'Version' => 'Version',
59
+			'Versions' => 'Versions',
60
+			'Address2' => 'Address2',
61
+			'LinkTracking' => 'Link Tracking',
62
+			'FileTracking' => 'File Tracking',
63
+		);
64
+		$this->assertEquals($expected, $labels);
65
+	}
66
+
67
+	/**
68
+	 *
69
+	 */
70
+	public function testGetCMSFields()
71
+	{
72
+		$object = new Location();
73
+		$fieldset = $object->getCMSFields();
74
+		$this->assertinstanceOf(FieldList::class, $fieldset);
75
+	}
76
+
77
+	/**
78
+	 *
79
+	 */
80
+	public function testCanView()
81
+	{
82
+		$object = $this->objFromFixture(Location::class, 'dynamic');
83
+		$object->write();
84
+
85
+		$this->assertTrue($object->canView());
86
+
87
+		$nullMember = Member::create();
88
+		$nullMember->write();
89
+
90
+		$this->assertTrue($object->canView($nullMember));
91
+
92
+		$nullMember->delete();
93
+	}
94
+
95
+	/**
96
+	 *
97
+	 */
98
+	public function testCanEdit()
99
+	{
100
+		$object = $this->objFromFixture(Location::class, 'dynamic');
101
+		$object->write();
102
+
103
+		$objectID = $object->ID;
104
+
105
+		//test permissions per permission setting
106
+		$create = $this->objFromFixture(Member::class, 'locationcreate');
107
+		$edit = $this->objFromFixture(Member::class, 'locationedit');
108
+		$delete = $this->objFromFixture(Member::class, 'locationdelete');
109
+
110
+		$originalTitle = $object->Title;
111
+		$this->assertEquals($originalTitle, 'Dynamic, Inc.');
112
+
113
+		$this->assertTrue($object->canEdit($edit));
114
+		$this->assertFalse($object->canEdit($create));
115
+		$this->assertFalse($object->canEdit($delete));
116
+
117
+		$object->Title = 'Changed Title';
118
+		$object->write();
119
+
120
+		$testEdit = Location::get()->byID($objectID);
121
+		$this->assertEquals($testEdit->Title, 'Changed Title');
122
+	}
123
+
124
+	/**
125
+	 *
126
+	 */
127
+	public function testCanDelete()
128
+	{
129
+		$object = $this->objFromFixture(Location::class, 'dynamic');
130
+		$object->write();
131
+
132
+		//test permissions per permission setting
133
+		$create = $this->objFromFixture(Member::class, 'locationcreate');
134
+		$edit = $this->objFromFixture(Member::class, 'locationedit');
135
+		$delete = $this->objFromFixture(Member::class, 'locationdelete');
136
+
137
+		$this->assertTrue($object->canDelete($delete));
138
+		$this->assertFalse($object->canDelete($create));
139
+		$this->assertFalse($object->canDelete($edit));
140
+
141
+		$checkObject = $object;
142
+		$object->delete();
143
+
144
+		$this->assertEquals($checkObject->ID, 0);
145
+	}
146
+
147
+	/**
148
+	 *
149
+	 */
150
+	public function testCanCreate()
151
+	{
152
+		$object = singleton(Location::class);
153
+
154
+		//test permissions per permission setting
155
+		$create = $this->objFromFixture(Member::class, 'locationcreate');
156
+		$edit = $this->objFromFixture(Member::class, 'locationedit');
157
+		$delete = $this->objFromFixture(Member::class, 'locationdelete');
158
+
159
+		$this->assertTrue($object->canCreate($create));
160
+		$this->assertFalse($object->canCreate($edit));
161
+		$this->assertFalse($object->canCreate($delete));
162
+
163
+		$nullMember = Member::create();
164
+		$nullMember->write();
165
+		$this->assertFalse($object->canCreate($nullMember));
166
+
167
+		$nullMember->delete();
168
+	}
169
+
170
+	/**
171
+	 *
172
+	 */
173
+	public function testProvidePermissions()
174
+	{
175
+		$object = Location::create();
176
+		$expected = array(
177
+			'Location_EDIT' => 'Edit a Location',
178
+			'Location_DELETE' => 'Delete a Location',
179
+			'Location_CREATE' => 'Create a Location',
180
+		);
181
+		$this->assertEquals($expected, $object->providePermissions());
182
+	}
183 183
 }
Please login to merge, or discard this patch.
tests/form/LocatorFormTest.php 1 patch
Indentation   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -11,34 +11,34 @@
 block discarded – undo
11 11
 
12 12
 class LocatorFormTest extends FunctionalTest
13 13
 {
14
-    /**
15
-     * @var string
16
-     */
17
-    protected static $fixture_file = '../fixtures.yml';
18
-
19
-    /**
20
-     *
21
-     */
22
-    public function testLocatorFormBase()
23
-    {
24
-        $form = LocatorForm::create(LocatorController::create(Locator::get()->first()), 'LocatorForm');
25
-
26
-        $this->assertInstanceOf(FieldList::class, $form->Fields());
27
-        $this->assertInstanceOf(RequiredFields::class, $form->getValidator());
28
-    }
29
-
30
-    /**
31
-     *
32
-     */
33
-    public function testUpdateRequiredFields()
34
-    {
35
-        $form = LocatorForm::create(LocatorController::create(Locator::get()->first()), 'LocatorForm');
36
-        $validator = $form->getValidator();
37
-
38
-        $validator->removeRequiredField('Address');
39
-        $validator->addRequiredField('Foo');
40
-
41
-        $this->assertEquals(['Foo'], $form->getValidator()->getRequired());
42
-    }
14
+	/**
15
+	 * @var string
16
+	 */
17
+	protected static $fixture_file = '../fixtures.yml';
18
+
19
+	/**
20
+	 *
21
+	 */
22
+	public function testLocatorFormBase()
23
+	{
24
+		$form = LocatorForm::create(LocatorController::create(Locator::get()->first()), 'LocatorForm');
25
+
26
+		$this->assertInstanceOf(FieldList::class, $form->Fields());
27
+		$this->assertInstanceOf(RequiredFields::class, $form->getValidator());
28
+	}
29
+
30
+	/**
31
+	 *
32
+	 */
33
+	public function testUpdateRequiredFields()
34
+	{
35
+		$form = LocatorForm::create(LocatorController::create(Locator::get()->first()), 'LocatorForm');
36
+		$validator = $form->getValidator();
37
+
38
+		$validator->removeRequiredField('Address');
39
+		$validator->addRequiredField('Foo');
40
+
41
+		$this->assertEquals(['Foo'], $form->getValidator()->getRequired());
42
+	}
43 43
 
44 44
 }
Please login to merge, or discard this patch.
tests/objects/LocationCategoryTest.php 1 patch
Indentation   +54 added lines, -54 removed lines patch added patch discarded remove patch
@@ -14,69 +14,69 @@
 block discarded – undo
14 14
  */
15 15
 class LocationCategoryTest extends SapphireTest
16 16
 {
17
-    /**
18
-     * @var string
19
-     */
20
-    protected static $fixture_file = '../fixtures.yml';
17
+	/**
18
+	 * @var string
19
+	 */
20
+	protected static $fixture_file = '../fixtures.yml';
21 21
 
22
-    /**
23
-     *
24
-     */
25
-    public function testGetCMSFields()
26
-    {
27
-        $object = $this->objFromFixture(LocationCategory::class, 'service');
28
-        $fieldset = $object->getCMSFields();
29
-        $this->assertInstanceOf(FieldList::class, $fieldset);
30
-    }
22
+	/**
23
+	 *
24
+	 */
25
+	public function testGetCMSFields()
26
+	{
27
+		$object = $this->objFromFixture(LocationCategory::class, 'service');
28
+		$fieldset = $object->getCMSFields();
29
+		$this->assertInstanceOf(FieldList::class, $fieldset);
30
+	}
31 31
 
32
-    /**
33
-     *
34
-     */
35
-    public function testCanView()
36
-    {
37
-        $object = $this->objFromFixture(LocationCategory::class, 'service');
38
-        $this->assertTrue($object->canView());
39
-    }
32
+	/**
33
+	 *
34
+	 */
35
+	public function testCanView()
36
+	{
37
+		$object = $this->objFromFixture(LocationCategory::class, 'service');
38
+		$this->assertTrue($object->canView());
39
+	}
40 40
 
41
-    /**
42
-     *
43
-     */
44
-    public function testCanEdit()
45
-    {
46
-        $object = $this->objFromFixture(LocationCategory::class, 'service');
41
+	/**
42
+	 *
43
+	 */
44
+	public function testCanEdit()
45
+	{
46
+		$object = $this->objFromFixture(LocationCategory::class, 'service');
47 47
 
48
-        $admin = $this->objFromFixture(Member::class, 'locationedit');
49
-        $this->assertTrue($object->canEdit($admin));
48
+		$admin = $this->objFromFixture(Member::class, 'locationedit');
49
+		$this->assertTrue($object->canEdit($admin));
50 50
 
51
-        $member = $this->objFromFixture(Member::class, 'default');
52
-        $this->assertFalse($object->canEdit($member));
53
-    }
51
+		$member = $this->objFromFixture(Member::class, 'default');
52
+		$this->assertFalse($object->canEdit($member));
53
+	}
54 54
 
55
-    /**
56
-     *
57
-     */
58
-    public function testCanDelete()
59
-    {
60
-        $object = $this->objFromFixture(LocationCategory::class, 'service');
55
+	/**
56
+	 *
57
+	 */
58
+	public function testCanDelete()
59
+	{
60
+		$object = $this->objFromFixture(LocationCategory::class, 'service');
61 61
 
62
-        $admin = $this->objFromFixture(Member::class, 'locationdelete');
63
-        $this->assertTrue($object->canDelete($admin));
62
+		$admin = $this->objFromFixture(Member::class, 'locationdelete');
63
+		$this->assertTrue($object->canDelete($admin));
64 64
 
65
-        $member = $this->objFromFixture(Member::class, 'default');
66
-        $this->assertFalse($object->canDelete($member));
67
-    }
65
+		$member = $this->objFromFixture(Member::class, 'default');
66
+		$this->assertFalse($object->canDelete($member));
67
+	}
68 68
 
69
-    /**
70
-     *
71
-     */
72
-    public function testCanCreate()
73
-    {
74
-        $object = $this->objFromFixture(LocationCategory::class, 'service');
69
+	/**
70
+	 *
71
+	 */
72
+	public function testCanCreate()
73
+	{
74
+		$object = $this->objFromFixture(LocationCategory::class, 'service');
75 75
 
76
-        $admin = $this->objFromFixture(Member::class, 'locationcreate');
77
-        $this->assertTrue($object->canCreate($admin));
76
+		$admin = $this->objFromFixture(Member::class, 'locationcreate');
77
+		$this->assertTrue($object->canCreate($admin));
78 78
 
79
-        $member = $this->objFromFixture(Member::class, 'default');
80
-        $this->assertFalse($object->canCreate($member));
81
-    }
79
+		$member = $this->objFromFixture(Member::class, 'default');
80
+		$this->assertFalse($object->canCreate($member));
81
+	}
82 82
 }
Please login to merge, or discard this patch.
tests/pages/LocatorTest.php 1 patch
Indentation   +155 added lines, -155 removed lines patch added patch discarded remove patch
@@ -21,159 +21,159 @@
 block discarded – undo
21 21
  */
22 22
 class LocatorTest extends FunctionalTest
23 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
-     */
98
-    public function testGetRadii()
99
-    {
100
-        /** @var Locator $locator */
101
-        $locator = Injector::inst()->create(Locator::class);
102
-        $radii = [
103
-            '0' => '5',
104
-            '1' => '10',
105
-            '2' => '15',
106
-            '3' => '100',
107
-        ];
108
-        Config::modify()->set(Locator::class, 'radii', $radii);
109
-        $this->assertEquals($radii, $locator->getRadii());
110
-    }
111
-
112
-    /**
113
-     *
114
-     */
115
-    public function testGetRadiiArrayList()
116
-    {
117
-        /** @var Locator $locator */
118
-        $locator = Injector::inst()->create(Locator::class);
119
-        $this->assertInstanceOf(ArrayList::class, $locator->getRadiiArrayList());
120
-    }
121
-
122
-    /**
123
-     *
124
-     */
125
-    public function testGetLimit()
126
-    {
127
-        /** @var Locator $locator */
128
-        $locator = Injector::inst()->create(Locator::class);
129
-        $this->assertEquals(50, $locator->getLimit());
130
-    }
131
-
132
-    /**
133
-     *
134
-     */
135
-    public function testGetShowRadius()
136
-    {
137
-        /** @var Locator $locator */
138
-        $locator = Injector::inst()->create(Locator::class);
139
-        $this->assertTrue($locator->getShowRadius());
140
-    }
141
-
142
-    /**
143
-     *
144
-     */
145
-    public function testGetUsedCategories()
146
-    {
147
-        /** @var Locator $locator */
148
-        $locator = $this->objFromFixture(Locator::class, 'locator1');
149
-
150
-        $categories = $locator->getUsedCategories()->toArray();
151
-        $this->assertEquals(1, count($categories));
152
-    }
153
-
154
-    /**
155
-     *
156
-     */
157
-    public function testGetInfoWindowTemplate()
158
-    {
159
-        /** @var Locator $object */
160
-        $object = Injector::inst()->create(Locator::class);
161
-        $template = $object->getInfoWindowTemplate();
162
-        // get rid of cache ending
163
-        $template = preg_replace('/\?.*$/', '', $template);
164
-        $this->assertStringEndsWith('client/infowindow-description.html', $template);
165
-    }
166
-
167
-    /**
168
-     *
169
-     */
170
-    public function testGetListTemplate()
171
-    {
172
-        /** @var Locator $object */
173
-        $object = Injector::inst()->create(Locator::class);
174
-        $template = $object->getListTemplate();
175
-        // get rid of cache ending
176
-        $template = preg_replace('/\?.*$/', '', $template);
177
-        $this->assertStringEndsWith('client/location-list-description.html', $template);
178
-    }
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
+	 */
98
+	public function testGetRadii()
99
+	{
100
+		/** @var Locator $locator */
101
+		$locator = Injector::inst()->create(Locator::class);
102
+		$radii = [
103
+			'0' => '5',
104
+			'1' => '10',
105
+			'2' => '15',
106
+			'3' => '100',
107
+		];
108
+		Config::modify()->set(Locator::class, 'radii', $radii);
109
+		$this->assertEquals($radii, $locator->getRadii());
110
+	}
111
+
112
+	/**
113
+	 *
114
+	 */
115
+	public function testGetRadiiArrayList()
116
+	{
117
+		/** @var Locator $locator */
118
+		$locator = Injector::inst()->create(Locator::class);
119
+		$this->assertInstanceOf(ArrayList::class, $locator->getRadiiArrayList());
120
+	}
121
+
122
+	/**
123
+	 *
124
+	 */
125
+	public function testGetLimit()
126
+	{
127
+		/** @var Locator $locator */
128
+		$locator = Injector::inst()->create(Locator::class);
129
+		$this->assertEquals(50, $locator->getLimit());
130
+	}
131
+
132
+	/**
133
+	 *
134
+	 */
135
+	public function testGetShowRadius()
136
+	{
137
+		/** @var Locator $locator */
138
+		$locator = Injector::inst()->create(Locator::class);
139
+		$this->assertTrue($locator->getShowRadius());
140
+	}
141
+
142
+	/**
143
+	 *
144
+	 */
145
+	public function testGetUsedCategories()
146
+	{
147
+		/** @var Locator $locator */
148
+		$locator = $this->objFromFixture(Locator::class, 'locator1');
149
+
150
+		$categories = $locator->getUsedCategories()->toArray();
151
+		$this->assertEquals(1, count($categories));
152
+	}
153
+
154
+	/**
155
+	 *
156
+	 */
157
+	public function testGetInfoWindowTemplate()
158
+	{
159
+		/** @var Locator $object */
160
+		$object = Injector::inst()->create(Locator::class);
161
+		$template = $object->getInfoWindowTemplate();
162
+		// get rid of cache ending
163
+		$template = preg_replace('/\?.*$/', '', $template);
164
+		$this->assertStringEndsWith('client/infowindow-description.html', $template);
165
+	}
166
+
167
+	/**
168
+	 *
169
+	 */
170
+	public function testGetListTemplate()
171
+	{
172
+		/** @var Locator $object */
173
+		$object = Injector::inst()->create(Locator::class);
174
+		$template = $object->getListTemplate();
175
+		// get rid of cache ending
176
+		$template = preg_replace('/\?.*$/', '', $template);
177
+		$this->assertStringEndsWith('client/location-list-description.html', $template);
178
+	}
179 179
 }
Please login to merge, or discard this patch.
tests/pages/LocatorControllerTest.php 1 patch
Indentation   +74 added lines, -74 removed lines patch added patch discarded remove patch
@@ -18,79 +18,79 @@
 block discarded – undo
18 18
 class LocatorControllerTest extends FunctionalTest
19 19
 {
20 20
 
21
-    /**
22
-     * @var string
23
-     */
24
-    protected static $fixture_file = '../fixtures.yml';
25
-
26
-    /**
27
-     * @var bool
28
-     */
29
-    protected static $use_draft_site = true;
30
-
31
-    /**
32
-     *
33
-     */
34
-    public function testIndex()
35
-    {
36
-        $locator = $this->objFromFixture(Locator::class, 'locator1');
37
-        $controller = LocatorController::create($locator);
38
-        $this->assertInstanceOf(ViewableData::class, $controller->index($controller->getRequest()));
39
-    }
40
-
41
-    /**
42
-     *
43
-     */
44
-    public function testXml()
45
-    {
46
-        /** @var Locator $locator */
47
-        $locator = $this->objFromFixture(Locator::class, 'locator1');
48
-        $page = $this->get($locator->Link('xml'));
49
-
50
-        $this->assertEquals(200, $page->getStatusCode());
51
-        $this->assertEquals('application/xml', $page->getHeader('content-type'));
52
-
53
-        $dom = new DOMDocument();
54
-        // true if it loads, false if it doesn't
55
-        $valid = $dom->loadXML($page->getBody());
56
-        $this->assertTrue($valid);
57
-    }
58
-
59
-    /**
60
-     *
61
-     */
62
-    public function testJson()
63
-    {
64
-        /** @var Locator $locator */
65
-        $locator = $this->objFromFixture(Locator::class, 'locator1');
66
-        $page = $this->get($locator->Link('json'));
67
-
68
-        $this->assertEquals(200, $page->getStatusCode());
69
-        $this->assertEquals('application/json', $page->getHeader('content-type'));
70
-
71
-        $json = json_decode($page->getBody());
72
-        // if it is null its not valid
73
-        $this->assertNotNull($json);
74
-    }
75
-
76
-    /**
77
-     *
78
-     */
79
-    public function testLocationSearch()
80
-    {
81
-        $locator = $this->objFromFixture(Locator::class, 'locator1');
82
-        $object = LocatorController::create($locator);
83
-        $form = $object->LocationSearch();
84
-        $this->assertInstanceOf(Form::class, $form);
85
-
86
-        $category = $this->objFromFixture(LocationCategory::class, 'service');
87
-        $category2 = $this->objFromFixture(LocationCategory::class, 'manufacturing');
88
-        $locator->Categories()->add($category);
89
-        $locator->Categories()->add($category2);
90
-
91
-        $form = $object->LocationSearch();
92
-        $fields = $form->Fields();
93
-        $this->assertInstanceOf(FieldList::class, $fields);
94
-    }
21
+	/**
22
+	 * @var string
23
+	 */
24
+	protected static $fixture_file = '../fixtures.yml';
25
+
26
+	/**
27
+	 * @var bool
28
+	 */
29
+	protected static $use_draft_site = true;
30
+
31
+	/**
32
+	 *
33
+	 */
34
+	public function testIndex()
35
+	{
36
+		$locator = $this->objFromFixture(Locator::class, 'locator1');
37
+		$controller = LocatorController::create($locator);
38
+		$this->assertInstanceOf(ViewableData::class, $controller->index($controller->getRequest()));
39
+	}
40
+
41
+	/**
42
+	 *
43
+	 */
44
+	public function testXml()
45
+	{
46
+		/** @var Locator $locator */
47
+		$locator = $this->objFromFixture(Locator::class, 'locator1');
48
+		$page = $this->get($locator->Link('xml'));
49
+
50
+		$this->assertEquals(200, $page->getStatusCode());
51
+		$this->assertEquals('application/xml', $page->getHeader('content-type'));
52
+
53
+		$dom = new DOMDocument();
54
+		// true if it loads, false if it doesn't
55
+		$valid = $dom->loadXML($page->getBody());
56
+		$this->assertTrue($valid);
57
+	}
58
+
59
+	/**
60
+	 *
61
+	 */
62
+	public function testJson()
63
+	{
64
+		/** @var Locator $locator */
65
+		$locator = $this->objFromFixture(Locator::class, 'locator1');
66
+		$page = $this->get($locator->Link('json'));
67
+
68
+		$this->assertEquals(200, $page->getStatusCode());
69
+		$this->assertEquals('application/json', $page->getHeader('content-type'));
70
+
71
+		$json = json_decode($page->getBody());
72
+		// if it is null its not valid
73
+		$this->assertNotNull($json);
74
+	}
75
+
76
+	/**
77
+	 *
78
+	 */
79
+	public function testLocationSearch()
80
+	{
81
+		$locator = $this->objFromFixture(Locator::class, 'locator1');
82
+		$object = LocatorController::create($locator);
83
+		$form = $object->LocationSearch();
84
+		$this->assertInstanceOf(Form::class, $form);
85
+
86
+		$category = $this->objFromFixture(LocationCategory::class, 'service');
87
+		$category2 = $this->objFromFixture(LocationCategory::class, 'manufacturing');
88
+		$locator->Categories()->add($category);
89
+		$locator->Categories()->add($category2);
90
+
91
+		$form = $object->LocationSearch();
92
+		$fields = $form->Fields();
93
+		$this->assertInstanceOf(FieldList::class, $fields);
94
+	}
95 95
 
96 96
 }
Please login to merge, or discard this patch.
src/bulkloader/LocationCsvBulkLoader.php 1 patch
Indentation   +40 added lines, -40 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
 namespace Dynamic\Locator;
4 4
 
5 5
 use SilverStripe\Dev\CsvBulkLoader,
6
-    SilverStripe\Core\Convert;
6
+	SilverStripe\Core\Convert;
7 7
 
8 8
 /**
9 9
  * Class LocationCsvBulkLoader
@@ -11,27 +11,27 @@  discard block
 block discarded – undo
11 11
 class LocationCsvBulkLoader extends CsvBulkLoader
12 12
 {
13 13
 
14
-    /**
15
-     * @var array
16
-     */
17
-    public $columnMap = array(
18
-        'Name' => 'Title',
19
-        'City' => 'Suburb',
20
-        'EmailAddress' => 'Email',
21
-        'Import_ID' => 'Import_ID',
22
-    );
23
-
24
-    /**
25
-     * @var array
26
-     */
27
-    public $duplicateChecks = array(
28
-        'Import_ID' => 'Import_ID'
29
-    );
30
-
31
-    /**
32
-     * @var array
33
-     */
34
-    /*
14
+	/**
15
+	 * @var array
16
+	 */
17
+	public $columnMap = array(
18
+		'Name' => 'Title',
19
+		'City' => 'Suburb',
20
+		'EmailAddress' => 'Email',
21
+		'Import_ID' => 'Import_ID',
22
+	);
23
+
24
+	/**
25
+	 * @var array
26
+	 */
27
+	public $duplicateChecks = array(
28
+		'Import_ID' => 'Import_ID'
29
+	);
30
+
31
+	/**
32
+	 * @var array
33
+	 */
34
+	/*
35 35
     public $relationCallbacks = array(
36 36
        'Category.Name' => array(
37 37
            'relationname' => 'Category',
@@ -39,23 +39,23 @@  discard block
 block discarded – undo
39 39
         ),
40 40
     );*/
41 41
 
42
-    /**
43
-     * @param $obj
44
-     * @param $val
45
-     * @param $record
46
-     * @return \SilverStripe\ORM\DataObject|static
47
-     */
48
-    public static function getCategoryByName(&$obj, $val, $record)
49
-    {
50
-        $val = Convert::raw2sql($val);
51
-        $category = LocationCategory::get()->filter(array('Name' => $val))->First();
52
-        if (!$category) {
53
-            $category = LocationCategory::create();
54
-            $category->Name = $val;
55
-            $category->write();
56
-        }
57
-
58
-        return $category;
59
-    }
42
+	/**
43
+	 * @param $obj
44
+	 * @param $val
45
+	 * @param $record
46
+	 * @return \SilverStripe\ORM\DataObject|static
47
+	 */
48
+	public static function getCategoryByName(&$obj, $val, $record)
49
+	{
50
+		$val = Convert::raw2sql($val);
51
+		$category = LocationCategory::get()->filter(array('Name' => $val))->First();
52
+		if (!$category) {
53
+			$category = LocationCategory::create();
54
+			$category->Name = $val;
55
+			$category->write();
56
+		}
57
+
58
+		return $category;
59
+	}
60 60
 
61 61
 }
Please login to merge, or discard this patch.
src/admin/LocationAdmin.php 1 patch
Indentation   +63 added lines, -63 removed lines patch added patch discarded remove patch
@@ -12,72 +12,72 @@
 block discarded – undo
12 12
 class LocationAdmin extends ModelAdmin
13 13
 {
14 14
 
15
-    /**
16
-     * @var array
17
-     */
18
-    private static $managed_models = array(
19
-        Location::class,
20
-        LocationCategory::class,
21
-    );
15
+	/**
16
+	 * @var array
17
+	 */
18
+	private static $managed_models = array(
19
+		Location::class,
20
+		LocationCategory::class,
21
+	);
22 22
 
23
-    /**
24
-     * @var array
25
-     */
26
-    private static $model_importers = array(
27
-        Location::class => LocationCsvBulkLoader::class,
28
-        LocationCategory::class => CsvBulkLoader::class,
29
-    );
23
+	/**
24
+	 * @var array
25
+	 */
26
+	private static $model_importers = array(
27
+		Location::class => LocationCsvBulkLoader::class,
28
+		LocationCategory::class => CsvBulkLoader::class,
29
+	);
30 30
 
31
-    /**
32
-     * @var string
33
-     */
34
-    private static $menu_title = 'Locator';
35
-    /**
36
-     * @var string
37
-     */
38
-    private static $url_segment = 'locator';
31
+	/**
32
+	 * @var string
33
+	 */
34
+	private static $menu_title = 'Locator';
35
+	/**
36
+	 * @var string
37
+	 */
38
+	private static $url_segment = 'locator';
39 39
 
40
-    /**
41
-     * @return array
42
-     */
43
-    public function getExportFields()
44
-    {
45
-        if ($this->modelClass == 'Location') {
46
-            return array(
47
-                'Title' => 'Name',
48
-                'Address' => 'Address',
49
-                'City' => 'City',
50
-                'State' => 'State',
51
-                'PostalCode' => 'PostalCode',
52
-                'Country' => 'Country',
53
-                'Website' => 'Website',
54
-                'Phone' => 'Phone',
55
-                'Fax' => 'Fax',
56
-                'Email' => 'Email',
57
-                'ShowInLocator' => 'ShowInLocator',
58
-                'Featured' => 'Featured',
59
-                'Lat' => 'Lat',
60
-                'Lng' => 'Lng',
61
-            );
62
-        }
40
+	/**
41
+	 * @return array
42
+	 */
43
+	public function getExportFields()
44
+	{
45
+		if ($this->modelClass == 'Location') {
46
+			return array(
47
+				'Title' => 'Name',
48
+				'Address' => 'Address',
49
+				'City' => 'City',
50
+				'State' => 'State',
51
+				'PostalCode' => 'PostalCode',
52
+				'Country' => 'Country',
53
+				'Website' => 'Website',
54
+				'Phone' => 'Phone',
55
+				'Fax' => 'Fax',
56
+				'Email' => 'Email',
57
+				'ShowInLocator' => 'ShowInLocator',
58
+				'Featured' => 'Featured',
59
+				'Lat' => 'Lat',
60
+				'Lng' => 'Lng',
61
+			);
62
+		}
63 63
 
64
-        return parent::getExportFields();
65
-    }
64
+		return parent::getExportFields();
65
+	}
66 66
 
67
-    /**
68
-     * @param null $id
69
-     * @param null $fields
70
-     * @return $this|Form
71
-     */
72
-    public function getEditForm($id = null, $fields = null)
73
-    {
74
-        $form = parent::getEditForm($id, $fields);
75
-        $class = $this->sanitiseClassName($this->modelClass);
76
-        if ($class == 'Location') {
77
-            $gridField = $form->Fields()->fieldByName($class);
78
-            $config = $gridField->getConfig();
79
-            $config->removeComponentsByType('GridFieldDeleteAction');
80
-        }
81
-        return $form;
82
-    }
67
+	/**
68
+	 * @param null $id
69
+	 * @param null $fields
70
+	 * @return $this|Form
71
+	 */
72
+	public function getEditForm($id = null, $fields = null)
73
+	{
74
+		$form = parent::getEditForm($id, $fields);
75
+		$class = $this->sanitiseClassName($this->modelClass);
76
+		if ($class == 'Location') {
77
+			$gridField = $form->Fields()->fieldByName($class);
78
+			$config = $gridField->getConfig();
79
+			$config->removeComponentsByType('GridFieldDeleteAction');
80
+		}
81
+		return $form;
82
+	}
83 83
 }
Please login to merge, or discard this patch.
src/form/LocatorForm.php 2 patches
Indentation   +64 added lines, -64 removed lines patch added patch discarded remove patch
@@ -19,79 +19,79 @@
 block discarded – undo
19 19
 class LocatorForm extends Form
20 20
 {
21 21
 
22
-    /**
23
-     * LocatorForm constructor.
24
-     * @param Controller $controller
25
-     * @param string $name
26
-     */
27
-    public function __construct(Controller $controller, $name)
28
-    {
22
+	/**
23
+	 * LocatorForm constructor.
24
+	 * @param Controller $controller
25
+	 * @param string $name
26
+	 */
27
+	public function __construct(Controller $controller, $name)
28
+	{
29 29
 
30
-        $fields = FieldList::create(
31
-            TextField::create('Address')
32
-                ->setTitle('')
33
-                ->setAttribute('placeholder', 'address or zip code')
34
-        );
30
+		$fields = FieldList::create(
31
+			TextField::create('Address')
32
+				->setTitle('')
33
+				->setAttribute('placeholder', 'address or zip code')
34
+		);
35 35
 
36
-        $pageCategories = Locator::locator_categories_by_locator($controller->data()->ID);
37
-        if ($pageCategories && $pageCategories->count() > 0) {
38
-            $categories = false;
39
-        } else {
40
-            $categories = Locator::get_all_categories();
41
-            if ($categories->count() < 1) {
42
-                $categories = false;
43
-            }
44
-        }
36
+		$pageCategories = Locator::locator_categories_by_locator($controller->data()->ID);
37
+		if ($pageCategories && $pageCategories->count() > 0) {
38
+			$categories = false;
39
+		} else {
40
+			$categories = Locator::get_all_categories();
41
+			if ($categories->count() < 1) {
42
+				$categories = false;
43
+			}
44
+		}
45 45
 
46
-        if ($categories) {
47
-            $categoriesField = DropdownField::create('CategoryID')
48
-                ->setTitle('')
49
-                ->setEmptyString('all categories')
50
-                ->setSource($categories->map());
51
-            $fields->push($categoriesField);
52
-        }
46
+		if ($categories) {
47
+			$categoriesField = DropdownField::create('CategoryID')
48
+				->setTitle('')
49
+				->setEmptyString('all categories')
50
+				->setSource($categories->map());
51
+			$fields->push($categoriesField);
52
+		}
53 53
 
54
-        if ($controller->getShowRadius()) {
55
-            $radiusArray = array_values($controller->getRadii());
56
-            $this->extend('overrideRadiusArray', $radiusArray);
57
-            $fields->push(DropdownField::create('Radius', '', ArrayLib::valuekey($radiusArray))
58
-                ->setEmptyString('radius')
59
-            );
60
-        }
54
+		if ($controller->getShowRadius()) {
55
+			$radiusArray = array_values($controller->getRadii());
56
+			$this->extend('overrideRadiusArray', $radiusArray);
57
+			$fields->push(DropdownField::create('Radius', '', ArrayLib::valuekey($radiusArray))
58
+				->setEmptyString('radius')
59
+			);
60
+		}
61 61
 
62
-        $actions = FieldList::create(
63
-            FormAction::create('doFilterLocations')
64
-                ->setTitle('Search')
65
-        );
62
+		$actions = FieldList::create(
63
+			FormAction::create('doFilterLocations')
64
+				->setTitle('Search')
65
+		);
66 66
 
67
-        $validator = $this->getValidator();
67
+		$validator = $this->getValidator();
68 68
 
69
-        parent::__construct($controller, $name, $fields, $actions, $validator);
70
-    }
69
+		parent::__construct($controller, $name, $fields, $actions, $validator);
70
+	}
71 71
 
72
-    /**
73
-     * @return null|RequiredFields|\SilverStripe\Forms\Validator
74
-     */
75
-    public function getValidator()
76
-    {
77
-        $validator = parent::getValidator();
78
-        if (empty($validator)) {
79
-            if (!$this->validator instanceof RequiredFields) $this->setValidator(RequiredFields::create('Address'));
80
-            $validator = $this->validator;
81
-        }
82
-        $this->extend('updateRequiredFields', $validator);
83
-        return $validator;
84
-    }
72
+	/**
73
+	 * @return null|RequiredFields|\SilverStripe\Forms\Validator
74
+	 */
75
+	public function getValidator()
76
+	{
77
+		$validator = parent::getValidator();
78
+		if (empty($validator)) {
79
+			if (!$this->validator instanceof RequiredFields) $this->setValidator(RequiredFields::create('Address'));
80
+			$validator = $this->validator;
81
+		}
82
+		$this->extend('updateRequiredFields', $validator);
83
+		return $validator;
84
+	}
85 85
 
86
-    /**
87
-     * @return FieldList
88
-     */
89
-    public function Fields()
90
-    {
91
-        $fields = parent::Fields();
86
+	/**
87
+	 * @return FieldList
88
+	 */
89
+	public function Fields()
90
+	{
91
+		$fields = parent::Fields();
92 92
 
93
-        $this->extend('updateLocatorFormFields', $fields);
93
+		$this->extend('updateLocatorFormFields', $fields);
94 94
 
95
-        return $fields;
96
-    }
95
+		return $fields;
96
+	}
97 97
 }
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -76,7 +76,9 @@
 block discarded – undo
76 76
     {
77 77
         $validator = parent::getValidator();
78 78
         if (empty($validator)) {
79
-            if (!$this->validator instanceof RequiredFields) $this->setValidator(RequiredFields::create('Address'));
79
+            if (!$this->validator instanceof RequiredFields) {
80
+            	$this->setValidator(RequiredFields::create('Address'));
81
+            }
80 82
             $validator = $this->validator;
81 83
         }
82 84
         $this->extend('updateRequiredFields', $validator);
Please login to merge, or discard this patch.
src/objects/Location.php 2 patches
Indentation   +201 added lines, -201 removed lines patch added patch discarded remove patch
@@ -26,205 +26,205 @@
 block discarded – undo
26 26
  */
27 27
 class Location extends DataObject implements PermissionProvider
28 28
 {
29
-    /**
30
-     * @var string
31
-     */
32
-    private static $singular_name = 'Location';
33
-
34
-    /**
35
-     * @var string
36
-     */
37
-    private static $plural_name = 'Locations';
38
-
39
-    /**
40
-     * @var bool
41
-     */
42
-    private static $versioned_gridfield_extensions = true;
43
-
44
-    /**
45
-     * @var array
46
-     */
47
-    private static $db = array(
48
-        'Title' => 'Varchar(255)',
49
-        'Featured' => 'Boolean',
50
-        'Website' => 'Varchar(255)',
51
-        'Phone' => 'Varchar(40)',
52
-        'Email' => 'Varchar(255)',
53
-        'Fax' => 'Varchar(45)',
54
-        'Import_ID' => 'Int',
55
-    );
56
-
57
-    private static $many_many = [
58
-        'Categories' => LocationCategory::class,
59
-    ];
60
-
61
-    /**
62
-     * @var string
63
-     */
64
-    private static $table_name = 'Location';
65
-
66
-    /**
67
-     * @var array
68
-     */
69
-    private static $casting = array(
70
-        'distance' => 'Decimal(9,3)',
71
-    );
72
-
73
-    /**
74
-     * @var string
75
-     */
76
-    private static $default_sort = 'Title';
77
-
78
-    /**
79
-     * api access via Restful Server module
80
-     *
81
-     * @var bool
82
-     */
83
-    private static $api_access = true;
84
-
85
-    /**
86
-     * search fields for Model Admin
87
-     *
88
-     * @var array
89
-     */
90
-    private static $searchable_fields = array(
91
-        'Title',
92
-        'Address',
93
-        'City',
94
-        'State',
95
-        'PostalCode',
96
-        'Country',
97
-        'Website',
98
-        'Phone',
99
-        'Email',
100
-        'Featured',
101
-    );
102
-
103
-    /**
104
-     * columns for grid field
105
-     *
106
-     * @var array
107
-     */
108
-    private static $summary_fields = array(
109
-        'Title',
110
-        'Address',
111
-        'City',
112
-        'State',
113
-        'PostalCode',
114
-        'Country',
115
-        'Featured.NiceAsBoolean',
116
-        'Coords',
117
-    );
118
-
119
-    /**
120
-     * Coords status for $summary_fields
121
-     *
122
-     * @return string
123
-     */
124
-    public function getCoords()
125
-    {
126
-        return ($this->Lat != 0 && $this->Lng != 0) ? 'true' : 'false';
127
-    }
128
-
129
-    /**
130
-     * custom labels for fields
131
-     *
132
-     * @param bool $includerelations
133
-     * @return array|string
134
-     */
135
-    public function fieldLabels($includerelations = true)
136
-    {
137
-        $labels = parent::fieldLabels($includerelations);
138
-        $labels['Title'] = 'Name';
139
-        $labels['PostalCode'] = 'Postal Code';
140
-        $labels['Category.Name'] = 'Category';
141
-        $labels['Category.ID'] = 'Category';
142
-        $labels['Featured.NiceAsBoolean'] = 'Featured';
143
-        return $labels;
144
-    }
145
-
146
-    /**
147
-     * @return FieldList
148
-     */
149
-    public function getCMSFields()
150
-    {
151
-        $this->beforeUpdateCMSFields(function ($fields) {
152
-            $fields->removeByName(array(
153
-                'Import_ID',
154
-                'LinkTracking',
155
-                'FileTracking',
156
-            ));
157
-
158
-            $fields->dataFieldByName('Website')
159
-                ->setAttribute('placeholder', 'http://');
160
-
161
-            $fields->replaceField('Email', EmailField::create('Email'));
162
-
163
-            $featured = $fields->dataFieldByName('Featured')
164
-                ->setDescription('Location will display near the top of the results list');
165
-            $fields->insertAfter(
166
-                $featured,
167
-                'CategoryID'
168
-            );
169
-        });
170
-
171
-        $fields = parent::getCMSFields();
172
-
173
-        // allow to be extended via DataExtension
174
-        $this->extend('updateLocationFields', $fields);
175
-
176
-        return $fields;
177
-    }
178
-
179
-    /**
180
-     * @param null $member
181
-     * @param array $context
182
-     * @return bool
183
-     */
184
-    public function canView($member = null, $context = [])
185
-    {
186
-        return true;
187
-    }
188
-
189
-    /**
190
-     * @param null $member
191
-     * @param array $context
192
-     * @return bool|int
193
-     */
194
-    public function canEdit($member = null, $context = [])
195
-    {
196
-        return Permission::check('Location_EDIT', 'any', $member);
197
-    }
198
-
199
-    /**
200
-     * @param null $member
201
-     * @param array $context
202
-     * @return bool|int
203
-     */
204
-    public function canDelete($member = null, $context = [])
205
-    {
206
-        return Permission::check('Location_DELETE', 'any', $member);
207
-    }
208
-
209
-    /**
210
-     * @param null $member
211
-     * @param array $context
212
-     * @return bool|int
213
-     */
214
-    public function canCreate($member = null, $context = [])
215
-    {
216
-        return Permission::check('Location_CREATE', 'any', $member);
217
-    }
218
-
219
-    /**
220
-     * @return array
221
-     */
222
-    public function providePermissions()
223
-    {
224
-        return array(
225
-            'Location_EDIT' => 'Edit a Location',
226
-            'Location_DELETE' => 'Delete a Location',
227
-            'Location_CREATE' => 'Create a Location',
228
-        );
229
-    }
29
+	/**
30
+	 * @var string
31
+	 */
32
+	private static $singular_name = 'Location';
33
+
34
+	/**
35
+	 * @var string
36
+	 */
37
+	private static $plural_name = 'Locations';
38
+
39
+	/**
40
+	 * @var bool
41
+	 */
42
+	private static $versioned_gridfield_extensions = true;
43
+
44
+	/**
45
+	 * @var array
46
+	 */
47
+	private static $db = array(
48
+		'Title' => 'Varchar(255)',
49
+		'Featured' => 'Boolean',
50
+		'Website' => 'Varchar(255)',
51
+		'Phone' => 'Varchar(40)',
52
+		'Email' => 'Varchar(255)',
53
+		'Fax' => 'Varchar(45)',
54
+		'Import_ID' => 'Int',
55
+	);
56
+
57
+	private static $many_many = [
58
+		'Categories' => LocationCategory::class,
59
+	];
60
+
61
+	/**
62
+	 * @var string
63
+	 */
64
+	private static $table_name = 'Location';
65
+
66
+	/**
67
+	 * @var array
68
+	 */
69
+	private static $casting = array(
70
+		'distance' => 'Decimal(9,3)',
71
+	);
72
+
73
+	/**
74
+	 * @var string
75
+	 */
76
+	private static $default_sort = 'Title';
77
+
78
+	/**
79
+	 * api access via Restful Server module
80
+	 *
81
+	 * @var bool
82
+	 */
83
+	private static $api_access = true;
84
+
85
+	/**
86
+	 * search fields for Model Admin
87
+	 *
88
+	 * @var array
89
+	 */
90
+	private static $searchable_fields = array(
91
+		'Title',
92
+		'Address',
93
+		'City',
94
+		'State',
95
+		'PostalCode',
96
+		'Country',
97
+		'Website',
98
+		'Phone',
99
+		'Email',
100
+		'Featured',
101
+	);
102
+
103
+	/**
104
+	 * columns for grid field
105
+	 *
106
+	 * @var array
107
+	 */
108
+	private static $summary_fields = array(
109
+		'Title',
110
+		'Address',
111
+		'City',
112
+		'State',
113
+		'PostalCode',
114
+		'Country',
115
+		'Featured.NiceAsBoolean',
116
+		'Coords',
117
+	);
118
+
119
+	/**
120
+	 * Coords status for $summary_fields
121
+	 *
122
+	 * @return string
123
+	 */
124
+	public function getCoords()
125
+	{
126
+		return ($this->Lat != 0 && $this->Lng != 0) ? 'true' : 'false';
127
+	}
128
+
129
+	/**
130
+	 * custom labels for fields
131
+	 *
132
+	 * @param bool $includerelations
133
+	 * @return array|string
134
+	 */
135
+	public function fieldLabels($includerelations = true)
136
+	{
137
+		$labels = parent::fieldLabels($includerelations);
138
+		$labels['Title'] = 'Name';
139
+		$labels['PostalCode'] = 'Postal Code';
140
+		$labels['Category.Name'] = 'Category';
141
+		$labels['Category.ID'] = 'Category';
142
+		$labels['Featured.NiceAsBoolean'] = 'Featured';
143
+		return $labels;
144
+	}
145
+
146
+	/**
147
+	 * @return FieldList
148
+	 */
149
+	public function getCMSFields()
150
+	{
151
+		$this->beforeUpdateCMSFields(function ($fields) {
152
+			$fields->removeByName(array(
153
+				'Import_ID',
154
+				'LinkTracking',
155
+				'FileTracking',
156
+			));
157
+
158
+			$fields->dataFieldByName('Website')
159
+				->setAttribute('placeholder', 'http://');
160
+
161
+			$fields->replaceField('Email', EmailField::create('Email'));
162
+
163
+			$featured = $fields->dataFieldByName('Featured')
164
+				->setDescription('Location will display near the top of the results list');
165
+			$fields->insertAfter(
166
+				$featured,
167
+				'CategoryID'
168
+			);
169
+		});
170
+
171
+		$fields = parent::getCMSFields();
172
+
173
+		// allow to be extended via DataExtension
174
+		$this->extend('updateLocationFields', $fields);
175
+
176
+		return $fields;
177
+	}
178
+
179
+	/**
180
+	 * @param null $member
181
+	 * @param array $context
182
+	 * @return bool
183
+	 */
184
+	public function canView($member = null, $context = [])
185
+	{
186
+		return true;
187
+	}
188
+
189
+	/**
190
+	 * @param null $member
191
+	 * @param array $context
192
+	 * @return bool|int
193
+	 */
194
+	public function canEdit($member = null, $context = [])
195
+	{
196
+		return Permission::check('Location_EDIT', 'any', $member);
197
+	}
198
+
199
+	/**
200
+	 * @param null $member
201
+	 * @param array $context
202
+	 * @return bool|int
203
+	 */
204
+	public function canDelete($member = null, $context = [])
205
+	{
206
+		return Permission::check('Location_DELETE', 'any', $member);
207
+	}
208
+
209
+	/**
210
+	 * @param null $member
211
+	 * @param array $context
212
+	 * @return bool|int
213
+	 */
214
+	public function canCreate($member = null, $context = [])
215
+	{
216
+		return Permission::check('Location_CREATE', 'any', $member);
217
+	}
218
+
219
+	/**
220
+	 * @return array
221
+	 */
222
+	public function providePermissions()
223
+	{
224
+		return array(
225
+			'Location_EDIT' => 'Edit a Location',
226
+			'Location_DELETE' => 'Delete a Location',
227
+			'Location_CREATE' => 'Create a Location',
228
+		);
229
+	}
230 230
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -148,7 +148,7 @@
 block discarded – undo
148 148
      */
149 149
     public function getCMSFields()
150 150
     {
151
-        $this->beforeUpdateCMSFields(function ($fields) {
151
+        $this->beforeUpdateCMSFields(function($fields) {
152 152
             $fields->removeByName(array(
153 153
                 'Import_ID',
154 154
                 'LinkTracking',
Please login to merge, or discard this patch.