@@ -2,26 +2,26 @@ discard block |
||
| 2 | 2 | |
| 3 | 3 | class MappableDataTest extends SapphireTest { |
| 4 | 4 | |
| 5 | - public function setUpOnce() { |
|
| 6 | - $this->requiredExtensions = array( |
|
| 7 | - 'Member' => array('MapExtension') |
|
| 8 | - ); |
|
| 5 | + public function setUpOnce() { |
|
| 6 | + $this->requiredExtensions = array( |
|
| 7 | + 'Member' => array('MapExtension') |
|
| 8 | + ); |
|
| 9 | 9 | |
| 10 | - parent::setupOnce(); |
|
| 11 | - } |
|
| 10 | + parent::setupOnce(); |
|
| 11 | + } |
|
| 12 | 12 | |
| 13 | - public function setUp() { |
|
| 14 | - MapUtil::reset(); |
|
| 15 | - parent::setUp(); |
|
| 16 | - } |
|
| 13 | + public function setUp() { |
|
| 14 | + MapUtil::reset(); |
|
| 15 | + parent::setUp(); |
|
| 16 | + } |
|
| 17 | 17 | |
| 18 | - public function testGetRenderableMapSetNoMarkerValues() { |
|
| 19 | - $instance = $this->getInstance(); |
|
| 20 | - $instance->MapPinEdited = true; |
|
| 21 | - $html = $instance->getRenderableMap(300, 800, 2)->setDivId('testmap')->forTemplate()->getValue(); |
|
| 18 | + public function testGetRenderableMapSetNoMarkerValues() { |
|
| 19 | + $instance = $this->getInstance(); |
|
| 20 | + $instance->MapPinEdited = true; |
|
| 21 | + $html = $instance->getRenderableMap(300, 800, 2)->setDivId('testmap')->forTemplate()->getValue(); |
|
| 22 | 22 | |
| 23 | 23 | |
| 24 | - $expected = <<<HTML |
|
| 24 | + $expected = <<<HTML |
|
| 25 | 25 | |
| 26 | 26 | |
| 27 | 27 | <div id="testmap" data-google-map-lang="en" style="width:300; height: 800;" |
@@ -46,21 +46,21 @@ discard block |
||
| 46 | 46 | </div> |
| 47 | 47 | |
| 48 | 48 | HTML; |
| 49 | - $this->assertEquals($expected, $html); |
|
| 50 | - } |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * The existenve of 'TestKeyVal' in the markers is the test here |
|
| 54 | - * |
|
| 55 | - * FIXME: Leading blank space |
|
| 56 | - */ |
|
| 57 | - public function testSetMarkerTemplateValues() { |
|
| 58 | - $instance = $this->getInstance(); |
|
| 59 | - $instance->MapPinEdited = true; |
|
| 60 | - $vals = array('TestKey' => ' TestKeyVal'); |
|
| 61 | - $instance->setMarkerTemplateValues($vals); |
|
| 62 | - $html = $instance->getRenderableMap(300, 800, 2)->setDivId('testmap')->forTemplate()->getValue(); |
|
| 63 | - $expected = <<<HTML |
|
| 49 | + $this->assertEquals($expected, $html); |
|
| 50 | + } |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * The existenve of 'TestKeyVal' in the markers is the test here |
|
| 54 | + * |
|
| 55 | + * FIXME: Leading blank space |
|
| 56 | + */ |
|
| 57 | + public function testSetMarkerTemplateValues() { |
|
| 58 | + $instance = $this->getInstance(); |
|
| 59 | + $instance->MapPinEdited = true; |
|
| 60 | + $vals = array('TestKey' => ' TestKeyVal'); |
|
| 61 | + $instance->setMarkerTemplateValues($vals); |
|
| 62 | + $html = $instance->getRenderableMap(300, 800, 2)->setDivId('testmap')->forTemplate()->getValue(); |
|
| 63 | + $expected = <<<HTML |
|
| 64 | 64 | |
| 65 | 65 | |
| 66 | 66 | <div id="testmap" data-google-map-lang="en" style="width:300; height: 800;" |
@@ -86,117 +86,117 @@ discard block |
||
| 86 | 86 | |
| 87 | 87 | HTML; |
| 88 | 88 | |
| 89 | - $this->assertEquals($expected, $html); |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - |
|
| 93 | - |
|
| 94 | - public function testStaticMapChangeLocation() { |
|
| 95 | - $instance = $this->getInstance(); |
|
| 96 | - $instance->Lat = 13.84; |
|
| 97 | - $instance->Lon = 100.52; |
|
| 98 | - $html = $instance->StaticMap(300, 800); |
|
| 99 | - $expected = '<img src="//maps.googleapis.com/maps/api/staticmap?center=' |
|
| 100 | - . '13.84%2C100.52&markers=13.84%2C100.52' |
|
| 101 | - . '&zoom=13&size=300x800&sensor=false&mapt' |
|
| 102 | - . 'ype=roadmap" width="300" height="800" alt="User" />'; |
|
| 103 | - $this->assertEquals($expected, $html); |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - public function testStaticMapVarySize() { |
|
| 107 | - $instance = $this->getInstance(); |
|
| 108 | - $instance->Lat = 13.8188931; |
|
| 109 | - $instance->Lon = 100.5005558; |
|
| 110 | - $html = $instance->StaticMap(300, 800); |
|
| 111 | - $expected = '<img src="//maps.googleapis.com/maps/api/staticmap?center=' |
|
| 112 | - . '13.8188931%2C100.5005558&markers=13.8188931%2C100.5005' |
|
| 113 | - . '558&zoom=13&size=300x800&sensor=false&mapt' |
|
| 114 | - . 'ype=roadmap" width="300" height="800" alt="User" />'; |
|
| 115 | - $this->assertEquals($expected, $html); |
|
| 116 | - |
|
| 117 | - $html = $instance->StaticMap(310, 810); |
|
| 118 | - $expected = '<img src="//maps.googleapis.com/maps/api/staticmap?center=' |
|
| 119 | - . '13.8188931%2C100.5005558&markers=13.8188931%2C100.5005' |
|
| 120 | - . '558&zoom=13&size=310x810&sensor=false&mapt' |
|
| 121 | - . 'ype=roadmap" width="310" height="810" alt="User" />'; |
|
| 122 | - $this->assertEquals($expected, $html); |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - |
|
| 126 | - public function testStaticMapVaryTerrain() { |
|
| 127 | - $instance = $this->getInstance(); |
|
| 128 | - $instance->Lat = 13.8188931; |
|
| 129 | - $instance->Lon = 100.5005558; |
|
| 130 | - $html = $instance->StaticMap(300, 800, null, 'satellite'); |
|
| 131 | - $expected = '<img src="//maps.googleapis.com/maps/api/staticmap?center=' |
|
| 132 | - . '13.8188931%2C100.5005558&markers=13.8188931%2C100.5005' |
|
| 133 | - . '558&zoom=13&size=300x800&sensor=false&mapt' |
|
| 134 | - . 'ype=satellite" width="300" height="800" alt="User" />'; |
|
| 135 | - $this->assertEquals($expected, $html); |
|
| 136 | - |
|
| 137 | - $html = $instance->StaticMap(300, 800, null, 'terrain'); |
|
| 138 | - $expected = '<img src="//maps.googleapis.com/maps/api/staticmap?center=' |
|
| 139 | - . '13.8188931%2C100.5005558&markers=13.8188931%2C100.5005' |
|
| 140 | - . '558&zoom=13&size=300x800&sensor=false&mapt' |
|
| 141 | - . 'ype=terrain" width="300" height="800" alt="User" />'; |
|
| 142 | - |
|
| 143 | - $html = $instance->StaticMap(300, 800, null, 'hybrid'); |
|
| 144 | - $expected = '<img src="//maps.googleapis.com/maps/api/staticmap?center=' |
|
| 145 | - . '13.8188931%2C100.5005558&markers=13.8188931%2C100.5005' |
|
| 146 | - . '558&zoom=13&size=300x800&sensor=false&mapt' |
|
| 147 | - . 'ype=hybrid" width="300" height="800" alt="User" />'; |
|
| 148 | - $this->assertEquals($expected, $html); |
|
| 149 | - } |
|
| 150 | - |
|
| 151 | - public function testStaticMapVaryZoom() { |
|
| 152 | - $instance = $this->getInstance(); |
|
| 153 | - |
|
| 154 | - $html = $instance->StaticMap(300, 800, 2); |
|
| 155 | - $expected = '<img src="//maps.googleapis.com/maps/api/staticmap?center=' |
|
| 156 | - . '13.8188931%2C100.5005558&markers=13.8188931%2C100.5005' |
|
| 157 | - . '558&zoom=2&size=300x800&sensor=false&mapt' |
|
| 158 | - . 'ype=roadmap" width="300" height="800" alt="User" />'; |
|
| 159 | - $this->assertEquals($expected, $html); |
|
| 160 | - |
|
| 161 | - $html = $instance->StaticMap(300, 800, 12); |
|
| 162 | - $expected = '<img src="//maps.googleapis.com/maps/api/staticmap?center=' |
|
| 163 | - . '13.8188931%2C100.5005558&markers=13.8188931%2C100.5005' |
|
| 164 | - . '558&zoom=12&size=300x800&sensor=false&mapt' |
|
| 165 | - . 'ype=roadmap" width="300" height="800" alt="User" />'; |
|
| 166 | - $this->assertEquals($expected, $html); |
|
| 167 | - } |
|
| 168 | - |
|
| 169 | - public function testStaticMapWithMapPin() { |
|
| 170 | - $instance = $this->getInstance(); |
|
| 171 | - $this->addMapPinToInstance($instance); |
|
| 172 | - |
|
| 173 | - $html = $instance->StaticMap(300, 800, 2); |
|
| 174 | - |
|
| 175 | - $this->assertStringStartsWith('<img src="//maps.googleapis.com/maps/api/staticmap?center=13.8188931%2C100.5005558&markers=icon%3A', $html); |
|
| 176 | - $this->assertStringEndsWith('%2Fassets%2Fmapicontest.png%7C13.8188931%2C100.5005558&zoom=2&size=300x800&sensor=false&maptype=roadmap" width="300" height="800" alt="User, Test" />', $html); |
|
| 177 | - } |
|
| 178 | - |
|
| 179 | - private function getInstance() { |
|
| 180 | - $instance = new Member(); |
|
| 181 | - $instance->Lat = 13.8188931; |
|
| 182 | - $instance->Lon = 100.5005558; |
|
| 183 | - $instance->FirstName = 'Test'; |
|
| 184 | - $instance->Surname = 'User'; |
|
| 185 | - return $instance; |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - |
|
| 189 | - /** |
|
| 190 | - * @param Member $instance |
|
| 191 | - */ |
|
| 192 | - private function addMapPinToInstance(&$instance) { |
|
| 193 | - // Create a pin |
|
| 194 | - $copied = copy('mappable/tests/images/mapicontest.png', 'assets/mapicontest.png'); |
|
| 195 | - $this->assertTrue($copied); |
|
| 196 | - $imageFile = new Image(array('Name' => 'mapicontest.png', 'Filename' => 'assets/mapicontest.png')); |
|
| 197 | - $imageFile->write(); |
|
| 198 | - $instance->MapPinIconID = $imageFile->ID; |
|
| 199 | - $instance->write(); |
|
| 200 | - } |
|
| 89 | + $this->assertEquals($expected, $html); |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + |
|
| 93 | + |
|
| 94 | + public function testStaticMapChangeLocation() { |
|
| 95 | + $instance = $this->getInstance(); |
|
| 96 | + $instance->Lat = 13.84; |
|
| 97 | + $instance->Lon = 100.52; |
|
| 98 | + $html = $instance->StaticMap(300, 800); |
|
| 99 | + $expected = '<img src="//maps.googleapis.com/maps/api/staticmap?center=' |
|
| 100 | + . '13.84%2C100.52&markers=13.84%2C100.52' |
|
| 101 | + . '&zoom=13&size=300x800&sensor=false&mapt' |
|
| 102 | + . 'ype=roadmap" width="300" height="800" alt="User" />'; |
|
| 103 | + $this->assertEquals($expected, $html); |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + public function testStaticMapVarySize() { |
|
| 107 | + $instance = $this->getInstance(); |
|
| 108 | + $instance->Lat = 13.8188931; |
|
| 109 | + $instance->Lon = 100.5005558; |
|
| 110 | + $html = $instance->StaticMap(300, 800); |
|
| 111 | + $expected = '<img src="//maps.googleapis.com/maps/api/staticmap?center=' |
|
| 112 | + . '13.8188931%2C100.5005558&markers=13.8188931%2C100.5005' |
|
| 113 | + . '558&zoom=13&size=300x800&sensor=false&mapt' |
|
| 114 | + . 'ype=roadmap" width="300" height="800" alt="User" />'; |
|
| 115 | + $this->assertEquals($expected, $html); |
|
| 116 | + |
|
| 117 | + $html = $instance->StaticMap(310, 810); |
|
| 118 | + $expected = '<img src="//maps.googleapis.com/maps/api/staticmap?center=' |
|
| 119 | + . '13.8188931%2C100.5005558&markers=13.8188931%2C100.5005' |
|
| 120 | + . '558&zoom=13&size=310x810&sensor=false&mapt' |
|
| 121 | + . 'ype=roadmap" width="310" height="810" alt="User" />'; |
|
| 122 | + $this->assertEquals($expected, $html); |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + |
|
| 126 | + public function testStaticMapVaryTerrain() { |
|
| 127 | + $instance = $this->getInstance(); |
|
| 128 | + $instance->Lat = 13.8188931; |
|
| 129 | + $instance->Lon = 100.5005558; |
|
| 130 | + $html = $instance->StaticMap(300, 800, null, 'satellite'); |
|
| 131 | + $expected = '<img src="//maps.googleapis.com/maps/api/staticmap?center=' |
|
| 132 | + . '13.8188931%2C100.5005558&markers=13.8188931%2C100.5005' |
|
| 133 | + . '558&zoom=13&size=300x800&sensor=false&mapt' |
|
| 134 | + . 'ype=satellite" width="300" height="800" alt="User" />'; |
|
| 135 | + $this->assertEquals($expected, $html); |
|
| 136 | + |
|
| 137 | + $html = $instance->StaticMap(300, 800, null, 'terrain'); |
|
| 138 | + $expected = '<img src="//maps.googleapis.com/maps/api/staticmap?center=' |
|
| 139 | + . '13.8188931%2C100.5005558&markers=13.8188931%2C100.5005' |
|
| 140 | + . '558&zoom=13&size=300x800&sensor=false&mapt' |
|
| 141 | + . 'ype=terrain" width="300" height="800" alt="User" />'; |
|
| 142 | + |
|
| 143 | + $html = $instance->StaticMap(300, 800, null, 'hybrid'); |
|
| 144 | + $expected = '<img src="//maps.googleapis.com/maps/api/staticmap?center=' |
|
| 145 | + . '13.8188931%2C100.5005558&markers=13.8188931%2C100.5005' |
|
| 146 | + . '558&zoom=13&size=300x800&sensor=false&mapt' |
|
| 147 | + . 'ype=hybrid" width="300" height="800" alt="User" />'; |
|
| 148 | + $this->assertEquals($expected, $html); |
|
| 149 | + } |
|
| 150 | + |
|
| 151 | + public function testStaticMapVaryZoom() { |
|
| 152 | + $instance = $this->getInstance(); |
|
| 153 | + |
|
| 154 | + $html = $instance->StaticMap(300, 800, 2); |
|
| 155 | + $expected = '<img src="//maps.googleapis.com/maps/api/staticmap?center=' |
|
| 156 | + . '13.8188931%2C100.5005558&markers=13.8188931%2C100.5005' |
|
| 157 | + . '558&zoom=2&size=300x800&sensor=false&mapt' |
|
| 158 | + . 'ype=roadmap" width="300" height="800" alt="User" />'; |
|
| 159 | + $this->assertEquals($expected, $html); |
|
| 160 | + |
|
| 161 | + $html = $instance->StaticMap(300, 800, 12); |
|
| 162 | + $expected = '<img src="//maps.googleapis.com/maps/api/staticmap?center=' |
|
| 163 | + . '13.8188931%2C100.5005558&markers=13.8188931%2C100.5005' |
|
| 164 | + . '558&zoom=12&size=300x800&sensor=false&mapt' |
|
| 165 | + . 'ype=roadmap" width="300" height="800" alt="User" />'; |
|
| 166 | + $this->assertEquals($expected, $html); |
|
| 167 | + } |
|
| 168 | + |
|
| 169 | + public function testStaticMapWithMapPin() { |
|
| 170 | + $instance = $this->getInstance(); |
|
| 171 | + $this->addMapPinToInstance($instance); |
|
| 172 | + |
|
| 173 | + $html = $instance->StaticMap(300, 800, 2); |
|
| 174 | + |
|
| 175 | + $this->assertStringStartsWith('<img src="//maps.googleapis.com/maps/api/staticmap?center=13.8188931%2C100.5005558&markers=icon%3A', $html); |
|
| 176 | + $this->assertStringEndsWith('%2Fassets%2Fmapicontest.png%7C13.8188931%2C100.5005558&zoom=2&size=300x800&sensor=false&maptype=roadmap" width="300" height="800" alt="User, Test" />', $html); |
|
| 177 | + } |
|
| 178 | + |
|
| 179 | + private function getInstance() { |
|
| 180 | + $instance = new Member(); |
|
| 181 | + $instance->Lat = 13.8188931; |
|
| 182 | + $instance->Lon = 100.5005558; |
|
| 183 | + $instance->FirstName = 'Test'; |
|
| 184 | + $instance->Surname = 'User'; |
|
| 185 | + return $instance; |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + |
|
| 189 | + /** |
|
| 190 | + * @param Member $instance |
|
| 191 | + */ |
|
| 192 | + private function addMapPinToInstance(&$instance) { |
|
| 193 | + // Create a pin |
|
| 194 | + $copied = copy('mappable/tests/images/mapicontest.png', 'assets/mapicontest.png'); |
|
| 195 | + $this->assertTrue($copied); |
|
| 196 | + $imageFile = new Image(array('Name' => 'mapicontest.png', 'Filename' => 'assets/mapicontest.png')); |
|
| 197 | + $imageFile->write(); |
|
| 198 | + $instance->MapPinIconID = $imageFile->ID; |
|
| 199 | + $instance->write(); |
|
| 200 | + } |
|
| 201 | 201 | |
| 202 | 202 | } |
@@ -2,7 +2,7 @@ discard block |
||
| 2 | 2 | |
| 3 | 3 | class MapUtilTest extends SapphireTest { |
| 4 | 4 | |
| 5 | - /* |
|
| 5 | + /* |
|
| 6 | 6 | Other tests: |
| 7 | 7 | 1) List, ArrayList, DataList, null for get_map |
| 8 | 8 | 2) Negative and zero map sizes |
@@ -16,142 +16,142 @@ discard block |
||
| 16 | 16 | parent::setupOnce(); |
| 17 | 17 | } |
| 18 | 18 | */ |
| 19 | - public function setUp() { |
|
| 20 | - MapUtil::reset(); |
|
| 21 | - parent::setUp(); |
|
| 22 | - } |
|
| 23 | - |
|
| 24 | - public function test_set_api_key_string() { |
|
| 25 | - MapUtil::set_api_key('PRETENDAPIKEY'); |
|
| 26 | - $html = $this->htmlForMap(); |
|
| 27 | - $this->assertContains( |
|
| 28 | - ' data-google-map-key="PRETENDAPIKEY" data-google-map-lang="en"', |
|
| 29 | - $html |
|
| 30 | - ); |
|
| 31 | - |
|
| 32 | - $html = $this->htmlForMap(); |
|
| 33 | - $this->assertNotContains( |
|
| 34 | - ' data-google-map-key="PRETENDAPIKEY" data-google-map-lang="en"', |
|
| 35 | - $html |
|
| 36 | - ); |
|
| 37 | - } |
|
| 38 | - |
|
| 39 | - public function test_set_api_key_host_array() { |
|
| 40 | - $url = Director::absoluteBaseURL(); |
|
| 41 | - // remove http and https |
|
| 42 | - $url = str_replace('http://', '', $url); |
|
| 43 | - $url = str_replace('https://', '', $url); |
|
| 44 | - $parts = explode('/', $url); |
|
| 45 | - $host = $parts[0]; |
|
| 46 | - $key = array($host => 'PRETENDAPIKEY'); |
|
| 47 | - MapUtil::set_api_key($key); |
|
| 48 | - $html = $this->htmlForMap(); |
|
| 49 | - $this->assertContains( |
|
| 50 | - ' data-google-map-key="PRETENDAPIKEY" data-google-map-lang="en"', |
|
| 51 | - $html |
|
| 52 | - ); |
|
| 53 | - |
|
| 54 | - $html = $this->htmlForMap(); |
|
| 55 | - $this->assertNotContains( |
|
| 56 | - ' data-google-map-key="PRETENDAPIKEY" data-google-map-lang="en"', |
|
| 57 | - $html |
|
| 58 | - ); |
|
| 59 | - } |
|
| 60 | - |
|
| 61 | - public function test_set_map_size() { |
|
| 62 | - MapUtil::set_map_size('890px', '24em'); |
|
| 63 | - $html = $this->htmlForMap(); |
|
| 64 | - $this->assertContains(' style="width:890px; height: 24em;"', $html); |
|
| 65 | - } |
|
| 66 | - |
|
| 67 | - public function testSanitizeEmptyString() { |
|
| 68 | - $this->assertEquals( |
|
| 69 | - '', |
|
| 70 | - MapUtil::sanitize('') |
|
| 71 | - ); |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - public function testSanitizeAlreadySanitized() { |
|
| 75 | - $this->assertEquals( |
|
| 76 | - 'This is already sanitized', |
|
| 77 | - MapUtil::sanitize('This is already sanitized') |
|
| 78 | - ); |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - public function testSanitizeSlashN() { |
|
| 82 | - $this->assertEquals( |
|
| 83 | - 'String to be sanitized', |
|
| 84 | - MapUtil::sanitize("String\n to be sanitized") |
|
| 85 | - ); |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - public function testSanitizeSlashT() { |
|
| 89 | - $this->assertEquals( |
|
| 90 | - 'String to be sanitized', |
|
| 91 | - MapUtil::sanitize("String\t to be sanitized") |
|
| 92 | - ); |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - public function testSanitizeSlashR() { |
|
| 96 | - $this->assertEquals( |
|
| 97 | - 'String to be sanitized', |
|
| 98 | - MapUtil::sanitize("String\r to be sanitized") |
|
| 99 | - ); |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - /** |
|
| 103 | - * A single marker for the Member should appear in the UJS map data |
|
| 104 | - */ |
|
| 105 | - public function testSingularMappableItemMarkerUJSExists() { |
|
| 106 | - Member::add_extension('MapExtension'); |
|
| 107 | - $member = new Member(); |
|
| 108 | - $member->Lat = 12.847; |
|
| 109 | - $member->Lon = 29.24; |
|
| 110 | - |
|
| 111 | - // because we are not writing, set this manually |
|
| 112 | - $member->MapPinEdited = true; |
|
| 113 | - $list = new ArrayList(); |
|
| 114 | - $list->push($member); |
|
| 115 | - $map = MapUtil::get_map($list, array()); |
|
| 116 | - $html = $map->forTemplate(); |
|
| 117 | - $markerExpected = 'data-mapmarkers=\'[{"latitude":12.847,"longitude":29.24,"html":"MEMBER: ","category":"default","icon":false}]\''; |
|
| 118 | - $this->assertContains($markerExpected, $html); |
|
| 119 | - Member::remove_extension('MapExtension'); |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - private function htmlForMap() { |
|
| 123 | - $map = MapUtil::get_map(new ArrayList(), array()); |
|
| 124 | - $html = $map->forTemplate(); |
|
| 125 | - return $html; |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - public function test_set_center() { |
|
| 129 | - MapUtil::set_center('Klong Tan, Bangkok, Thailand'); |
|
| 130 | - $html = $this->htmlForMap(); |
|
| 131 | - //coordinates of Klong Tan in Bangkok |
|
| 132 | - $expected = 'data-centre=\'{"lat":13.7243075,"lng":100.5718086}'; |
|
| 133 | - $this->assertContains($expected, $html); |
|
| 134 | - } |
|
| 135 | - |
|
| 136 | - public function test_set_map_type() { |
|
| 137 | - $mapTypes = array( |
|
| 138 | - 'road' => 'road', |
|
| 139 | - 'satellite' => 'satellite', |
|
| 140 | - 'hybrid' => 'hybrid', |
|
| 141 | - 'terrain' => 'terrain', |
|
| 142 | - 'google.maps.MapTypeId.ROADMAP' => 'road', |
|
| 143 | - 'google.maps.MapTypeId.SATELLITE' => 'satellite', |
|
| 144 | - 'google.maps.MapTypeId.G_HYBRID_MAP' => 'hybrid', |
|
| 145 | - 'google.maps.MapTypeId.G_PHYSICAL_MAP' => 'terrain', |
|
| 146 | - 'custom_layer' => 'custom_layer' |
|
| 147 | - |
|
| 148 | - ); |
|
| 149 | - |
|
| 150 | - foreach (array_keys($mapTypes) as $mapType) { |
|
| 151 | - MapUtil::set_map_type($mapType); |
|
| 152 | - $expected = "data-maptype='".$mapTypes[$mapType]."'"; |
|
| 153 | - $html = $this->htmlForMap(); |
|
| 154 | - $this->assertContains($expected, $html); |
|
| 155 | - } |
|
| 156 | - } |
|
| 19 | + public function setUp() { |
|
| 20 | + MapUtil::reset(); |
|
| 21 | + parent::setUp(); |
|
| 22 | + } |
|
| 23 | + |
|
| 24 | + public function test_set_api_key_string() { |
|
| 25 | + MapUtil::set_api_key('PRETENDAPIKEY'); |
|
| 26 | + $html = $this->htmlForMap(); |
|
| 27 | + $this->assertContains( |
|
| 28 | + ' data-google-map-key="PRETENDAPIKEY" data-google-map-lang="en"', |
|
| 29 | + $html |
|
| 30 | + ); |
|
| 31 | + |
|
| 32 | + $html = $this->htmlForMap(); |
|
| 33 | + $this->assertNotContains( |
|
| 34 | + ' data-google-map-key="PRETENDAPIKEY" data-google-map-lang="en"', |
|
| 35 | + $html |
|
| 36 | + ); |
|
| 37 | + } |
|
| 38 | + |
|
| 39 | + public function test_set_api_key_host_array() { |
|
| 40 | + $url = Director::absoluteBaseURL(); |
|
| 41 | + // remove http and https |
|
| 42 | + $url = str_replace('http://', '', $url); |
|
| 43 | + $url = str_replace('https://', '', $url); |
|
| 44 | + $parts = explode('/', $url); |
|
| 45 | + $host = $parts[0]; |
|
| 46 | + $key = array($host => 'PRETENDAPIKEY'); |
|
| 47 | + MapUtil::set_api_key($key); |
|
| 48 | + $html = $this->htmlForMap(); |
|
| 49 | + $this->assertContains( |
|
| 50 | + ' data-google-map-key="PRETENDAPIKEY" data-google-map-lang="en"', |
|
| 51 | + $html |
|
| 52 | + ); |
|
| 53 | + |
|
| 54 | + $html = $this->htmlForMap(); |
|
| 55 | + $this->assertNotContains( |
|
| 56 | + ' data-google-map-key="PRETENDAPIKEY" data-google-map-lang="en"', |
|
| 57 | + $html |
|
| 58 | + ); |
|
| 59 | + } |
|
| 60 | + |
|
| 61 | + public function test_set_map_size() { |
|
| 62 | + MapUtil::set_map_size('890px', '24em'); |
|
| 63 | + $html = $this->htmlForMap(); |
|
| 64 | + $this->assertContains(' style="width:890px; height: 24em;"', $html); |
|
| 65 | + } |
|
| 66 | + |
|
| 67 | + public function testSanitizeEmptyString() { |
|
| 68 | + $this->assertEquals( |
|
| 69 | + '', |
|
| 70 | + MapUtil::sanitize('') |
|
| 71 | + ); |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + public function testSanitizeAlreadySanitized() { |
|
| 75 | + $this->assertEquals( |
|
| 76 | + 'This is already sanitized', |
|
| 77 | + MapUtil::sanitize('This is already sanitized') |
|
| 78 | + ); |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + public function testSanitizeSlashN() { |
|
| 82 | + $this->assertEquals( |
|
| 83 | + 'String to be sanitized', |
|
| 84 | + MapUtil::sanitize("String\n to be sanitized") |
|
| 85 | + ); |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + public function testSanitizeSlashT() { |
|
| 89 | + $this->assertEquals( |
|
| 90 | + 'String to be sanitized', |
|
| 91 | + MapUtil::sanitize("String\t to be sanitized") |
|
| 92 | + ); |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + public function testSanitizeSlashR() { |
|
| 96 | + $this->assertEquals( |
|
| 97 | + 'String to be sanitized', |
|
| 98 | + MapUtil::sanitize("String\r to be sanitized") |
|
| 99 | + ); |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + /** |
|
| 103 | + * A single marker for the Member should appear in the UJS map data |
|
| 104 | + */ |
|
| 105 | + public function testSingularMappableItemMarkerUJSExists() { |
|
| 106 | + Member::add_extension('MapExtension'); |
|
| 107 | + $member = new Member(); |
|
| 108 | + $member->Lat = 12.847; |
|
| 109 | + $member->Lon = 29.24; |
|
| 110 | + |
|
| 111 | + // because we are not writing, set this manually |
|
| 112 | + $member->MapPinEdited = true; |
|
| 113 | + $list = new ArrayList(); |
|
| 114 | + $list->push($member); |
|
| 115 | + $map = MapUtil::get_map($list, array()); |
|
| 116 | + $html = $map->forTemplate(); |
|
| 117 | + $markerExpected = 'data-mapmarkers=\'[{"latitude":12.847,"longitude":29.24,"html":"MEMBER: ","category":"default","icon":false}]\''; |
|
| 118 | + $this->assertContains($markerExpected, $html); |
|
| 119 | + Member::remove_extension('MapExtension'); |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + private function htmlForMap() { |
|
| 123 | + $map = MapUtil::get_map(new ArrayList(), array()); |
|
| 124 | + $html = $map->forTemplate(); |
|
| 125 | + return $html; |
|
| 126 | + } |
|
| 127 | + |
|
| 128 | + public function test_set_center() { |
|
| 129 | + MapUtil::set_center('Klong Tan, Bangkok, Thailand'); |
|
| 130 | + $html = $this->htmlForMap(); |
|
| 131 | + //coordinates of Klong Tan in Bangkok |
|
| 132 | + $expected = 'data-centre=\'{"lat":13.7243075,"lng":100.5718086}'; |
|
| 133 | + $this->assertContains($expected, $html); |
|
| 134 | + } |
|
| 135 | + |
|
| 136 | + public function test_set_map_type() { |
|
| 137 | + $mapTypes = array( |
|
| 138 | + 'road' => 'road', |
|
| 139 | + 'satellite' => 'satellite', |
|
| 140 | + 'hybrid' => 'hybrid', |
|
| 141 | + 'terrain' => 'terrain', |
|
| 142 | + 'google.maps.MapTypeId.ROADMAP' => 'road', |
|
| 143 | + 'google.maps.MapTypeId.SATELLITE' => 'satellite', |
|
| 144 | + 'google.maps.MapTypeId.G_HYBRID_MAP' => 'hybrid', |
|
| 145 | + 'google.maps.MapTypeId.G_PHYSICAL_MAP' => 'terrain', |
|
| 146 | + 'custom_layer' => 'custom_layer' |
|
| 147 | + |
|
| 148 | + ); |
|
| 149 | + |
|
| 150 | + foreach (array_keys($mapTypes) as $mapType) { |
|
| 151 | + MapUtil::set_map_type($mapType); |
|
| 152 | + $expected = "data-maptype='".$mapTypes[$mapType]."'"; |
|
| 153 | + $html = $this->htmlForMap(); |
|
| 154 | + $this->assertContains($expected, $html); |
|
| 155 | + } |
|
| 156 | + } |
|
| 157 | 157 | } |
@@ -2,16 +2,16 @@ |
||
| 2 | 2 | |
| 3 | 3 | class MapLayerTest extends SapphireTest |
| 4 | 4 | { |
| 5 | - public function testCMSFields() { |
|
| 6 | - $layer = new MapLayer(); |
|
| 7 | - $fields = $layer->getCMSFields(); |
|
| 8 | - $tab = $fields->findOrMakeTab('Root.Main'); |
|
| 9 | - $fields = $tab->FieldList(); |
|
| 10 | - $names = array(); |
|
| 11 | - foreach ($fields as $field) { |
|
| 12 | - $names[] = $field->getName(); |
|
| 13 | - } |
|
| 14 | - $expected = array('Title', 'KmlFile'); |
|
| 15 | - $this->assertEquals($expected, $names); |
|
| 16 | - } |
|
| 5 | + public function testCMSFields() { |
|
| 6 | + $layer = new MapLayer(); |
|
| 7 | + $fields = $layer->getCMSFields(); |
|
| 8 | + $tab = $fields->findOrMakeTab('Root.Main'); |
|
| 9 | + $fields = $tab->FieldList(); |
|
| 10 | + $names = array(); |
|
| 11 | + foreach ($fields as $field) { |
|
| 12 | + $names[] = $field->getName(); |
|
| 13 | + } |
|
| 14 | + $expected = array('Title', 'KmlFile'); |
|
| 15 | + $this->assertEquals($expected, $names); |
|
| 16 | + } |
|
| 17 | 17 | } |
@@ -2,24 +2,24 @@ |
||
| 2 | 2 | |
| 3 | 3 | class MapMarkerSetsExtensionTest extends SapphireTest { |
| 4 | 4 | |
| 5 | - public function setUpOnce() { |
|
| 6 | - $this->requiredExtensions = array( |
|
| 7 | - 'Member' => array('MapExtension', 'MapMarkerSetsExtension') |
|
| 8 | - ); |
|
| 9 | - parent::setupOnce(); |
|
| 10 | - } |
|
| 5 | + public function setUpOnce() { |
|
| 6 | + $this->requiredExtensions = array( |
|
| 7 | + 'Member' => array('MapExtension', 'MapMarkerSetsExtension') |
|
| 8 | + ); |
|
| 9 | + parent::setupOnce(); |
|
| 10 | + } |
|
| 11 | 11 | |
| 12 | - public function testCMSFields() { |
|
| 13 | - $instance = new Member(); |
|
| 14 | - $fields = $instance->getCMSFields(); |
|
| 15 | - $tab = $fields->findOrMakeTab('Root.MapMarkerSets'); |
|
| 16 | - $fields = $tab->FieldList(); |
|
| 17 | - $names = array(); |
|
| 18 | - foreach ($fields as $field) { |
|
| 19 | - $names[] = $field->getName(); |
|
| 20 | - } |
|
| 21 | - $expected = array('MapMarkerSets'); |
|
| 22 | - $this->assertEquals($expected, $names); |
|
| 23 | - } |
|
| 12 | + public function testCMSFields() { |
|
| 13 | + $instance = new Member(); |
|
| 14 | + $fields = $instance->getCMSFields(); |
|
| 15 | + $tab = $fields->findOrMakeTab('Root.MapMarkerSets'); |
|
| 16 | + $fields = $tab->FieldList(); |
|
| 17 | + $names = array(); |
|
| 18 | + foreach ($fields as $field) { |
|
| 19 | + $names[] = $field->getName(); |
|
| 20 | + } |
|
| 21 | + $expected = array('MapMarkerSets'); |
|
| 22 | + $this->assertEquals($expected, $names); |
|
| 23 | + } |
|
| 24 | 24 | |
| 25 | 25 | } |
@@ -2,41 +2,41 @@ discard block |
||
| 2 | 2 | |
| 3 | 3 | class MappableDataObjectSetTest extends SapphireTest { |
| 4 | 4 | |
| 5 | - public function setUpOnce() { |
|
| 6 | - $this->requiredExtensions = array( |
|
| 7 | - 'Member' => array('MapExtension') |
|
| 8 | - ); |
|
| 5 | + public function setUpOnce() { |
|
| 6 | + $this->requiredExtensions = array( |
|
| 7 | + 'Member' => array('MapExtension') |
|
| 8 | + ); |
|
| 9 | 9 | |
| 10 | - parent::setupOnce(); |
|
| 11 | - } |
|
| 10 | + parent::setupOnce(); |
|
| 11 | + } |
|
| 12 | 12 | |
| 13 | - public function setUp() { |
|
| 14 | - MapUtil::reset(); |
|
| 15 | - parent::setUp(); |
|
| 16 | - } |
|
| 13 | + public function setUp() { |
|
| 14 | + MapUtil::reset(); |
|
| 15 | + parent::setUp(); |
|
| 16 | + } |
|
| 17 | 17 | |
| 18 | - public function testSetMarkerTemplateValues() { |
|
| 19 | - $instance1 = $this->getInstance(); |
|
| 20 | - $instance1->MapPinEdited = true; |
|
| 21 | - $instance1->write(); |
|
| 18 | + public function testSetMarkerTemplateValues() { |
|
| 19 | + $instance1 = $this->getInstance(); |
|
| 20 | + $instance1->MapPinEdited = true; |
|
| 21 | + $instance1->write(); |
|
| 22 | 22 | |
| 23 | - $instance2 = $this->getInstance(); |
|
| 24 | - $instance2->Lat = 7.12; |
|
| 25 | - $instance2->Lon = 23.4; |
|
| 26 | - $instance2->MapPinEdited = true; |
|
| 27 | - $instance2->write(); |
|
| 23 | + $instance2 = $this->getInstance(); |
|
| 24 | + $instance2->Lat = 7.12; |
|
| 25 | + $instance2->Lon = 23.4; |
|
| 26 | + $instance2->MapPinEdited = true; |
|
| 27 | + $instance2->write(); |
|
| 28 | 28 | |
| 29 | - // Mappable list has MappableDataObjectSet enabled by default |
|
| 30 | - // Items in the list are Mappable via the MapExtension |
|
| 31 | - $mappableList = new ArrayList(); |
|
| 32 | - $mappableList->push($instance1); |
|
| 33 | - $mappableList->push($instance2); |
|
| 29 | + // Mappable list has MappableDataObjectSet enabled by default |
|
| 30 | + // Items in the list are Mappable via the MapExtension |
|
| 31 | + $mappableList = new ArrayList(); |
|
| 32 | + $mappableList->push($instance1); |
|
| 33 | + $mappableList->push($instance2); |
|
| 34 | 34 | |
| 35 | - $vals = array('TestKey' => ' TestKeyValMDOS'); |
|
| 36 | - $mappableList->setMarkerTemplateValues($vals); |
|
| 35 | + $vals = array('TestKey' => ' TestKeyValMDOS'); |
|
| 36 | + $mappableList->setMarkerTemplateValues($vals); |
|
| 37 | 37 | |
| 38 | - $html = $mappableList->getRenderableMap(300, 800, 2)->setDivId('testmap')->forTemplate()->getValue(); |
|
| 39 | - $expected = <<<HTML |
|
| 38 | + $html = $mappableList->getRenderableMap(300, 800, 2)->setDivId('testmap')->forTemplate()->getValue(); |
|
| 39 | + $expected = <<<HTML |
|
| 40 | 40 | |
| 41 | 41 | |
| 42 | 42 | <div id="testmap" data-google-map-lang="en" style="width:300; height: 800;" |
@@ -61,18 +61,18 @@ discard block |
||
| 61 | 61 | </div> |
| 62 | 62 | |
| 63 | 63 | HTML; |
| 64 | - $this->assertEquals($expected, $html); |
|
| 65 | - } |
|
| 64 | + $this->assertEquals($expected, $html); |
|
| 65 | + } |
|
| 66 | 66 | |
| 67 | 67 | |
| 68 | 68 | |
| 69 | - private function getInstance() { |
|
| 70 | - $instance = new Member(); |
|
| 71 | - $instance->Lat = 13.8188931; |
|
| 72 | - $instance->Lon = 100.5005558; |
|
| 73 | - $instance->FirstName = 'Test'; |
|
| 74 | - $instance->Surname = 'User'; |
|
| 75 | - return $instance; |
|
| 76 | - } |
|
| 69 | + private function getInstance() { |
|
| 70 | + $instance = new Member(); |
|
| 71 | + $instance->Lat = 13.8188931; |
|
| 72 | + $instance->Lon = 100.5005558; |
|
| 73 | + $instance->FirstName = 'Test'; |
|
| 74 | + $instance->Surname = 'User'; |
|
| 75 | + return $instance; |
|
| 76 | + } |
|
| 77 | 77 | |
| 78 | 78 | } |