Source of file MappableDataTest.php
Size: 7,636 Bytes - Last Modified: 2021-12-23T10:58:57+00:00
/var/www/docs.ssmods.com/process/src/tests/MappableDataTest.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209 | <?php class MappableDataTest extends SapphireTest { public function setUpOnce() { $this->requiredExtensions = array( 'Member' => array('MapExtension'), ); parent::setupOnce(); } public function setUp() { MapUtil::reset(); parent::setUp(); } public function testGetRenderableMapSetNoMarkerValues() { $instance = $this->getInstance(); $instance->MapPinEdited = true; $html = $instance->getRenderableMap(300, 800, 2)->setDivId('testmap')->forTemplate()->getValue(); $expected = <<<HTML <div id="testmap" data-google-map-lang="en" style="width:300; height: 800;" class=" mappable" data-map data-centre='{"lat":13.8188931,"lng":100.5005558}' data-zoom=2 data-maptype='road' data-allowfullscreen='1' data-clusterergridsize=50, data-clusterermaxzoom=17, data-enableautocentrezoom=false data-enablewindowzoom=false data-infowindowzoom=13 data-mapmarkers='[{"latitude":13.8188931,"longitude":100.5005558,"html":"MEMBER: Test User","category":"default","icon":false}]' data-defaulthidemarker=false data-lines='[]' data-kmlfiles='[]' data-mapstyles='[]' data-useclusterer=false > </div> HTML; $this->assertEquals($expected, $html); } /** * The existenve of 'TestKeyVal' in the markers is the test here. * * FIXME: Leading blank space */ public function testSetMarkerTemplateValues() { $instance = $this->getInstance(); $instance->MapPinEdited = true; $vals = array('TestKey' => ' TestKeyVal'); $instance->setMarkerTemplateValues($vals); $html = $instance->getRenderableMap(300, 800, 2)->setDivId('testmap')->forTemplate()->getValue(); $expected = <<<HTML <div id="testmap" data-google-map-lang="en" style="width:300; height: 800;" class=" mappable" data-map data-centre='{"lat":13.8188931,"lng":100.5005558}' data-zoom=2 data-maptype='road' data-allowfullscreen='1' data-clusterergridsize=50, data-clusterermaxzoom=17, data-enableautocentrezoom=false data-enablewindowzoom=false data-infowindowzoom=13 data-mapmarkers='[{"latitude":13.8188931,"longitude":100.5005558,"html":"MEMBER: Test User TestKeyVal","category":"default","icon":false}]' data-defaulthidemarker=false data-lines='[]' data-kmlfiles='[]' data-mapstyles='[]' data-useclusterer=false > </div> HTML; $this->assertEquals($expected, $html); } public function testStaticMapChangeLocation() { $instance = $this->getInstance(); $instance->Lat = 13.84; $instance->Lon = 100.52; $html = $instance->StaticMap(300, 800); $expected = '<img src="//maps.googleapis.com/maps/api/staticmap?center=' .'13.84%2C100.52&markers=13.84%2C100.52' .'&zoom=13&size=300x800&sensor=false&mapt' .'ype=roadmap" width="300" height="800" alt="User" />'; $this->assertEquals($expected, $html); } public function testStaticMapVarySize() { $instance = $this->getInstance(); $instance->Lat = 13.8188931; $instance->Lon = 100.5005558; $html = $instance->StaticMap(300, 800); $expected = '<img src="//maps.googleapis.com/maps/api/staticmap?center=' .'13.8188931%2C100.5005558&markers=13.8188931%2C100.5005' .'558&zoom=13&size=300x800&sensor=false&mapt' .'ype=roadmap" width="300" height="800" alt="User" />'; $this->assertEquals($expected, $html); $html = $instance->StaticMap(310, 810); $expected = '<img src="//maps.googleapis.com/maps/api/staticmap?center=' .'13.8188931%2C100.5005558&markers=13.8188931%2C100.5005' .'558&zoom=13&size=310x810&sensor=false&mapt' .'ype=roadmap" width="310" height="810" alt="User" />'; $this->assertEquals($expected, $html); } public function testStaticMapVaryTerrain() { $instance = $this->getInstance(); $instance->Lat = 13.8188931; $instance->Lon = 100.5005558; $html = $instance->StaticMap(300, 800, null, 'satellite'); $expected = '<img src="//maps.googleapis.com/maps/api/staticmap?center=' .'13.8188931%2C100.5005558&markers=13.8188931%2C100.5005' .'558&zoom=13&size=300x800&sensor=false&mapt' .'ype=satellite" width="300" height="800" alt="User" />'; $this->assertEquals($expected, $html); $html = $instance->StaticMap(300, 800, null, 'terrain'); $expected = '<img src="//maps.googleapis.com/maps/api/staticmap?center=' .'13.8188931%2C100.5005558&markers=13.8188931%2C100.5005' .'558&zoom=13&size=300x800&sensor=false&mapt' .'ype=terrain" width="300" height="800" alt="User" />'; $html = $instance->StaticMap(300, 800, null, 'hybrid'); $expected = '<img src="//maps.googleapis.com/maps/api/staticmap?center=' .'13.8188931%2C100.5005558&markers=13.8188931%2C100.5005' .'558&zoom=13&size=300x800&sensor=false&mapt' .'ype=hybrid" width="300" height="800" alt="User" />'; $this->assertEquals($expected, $html); } public function testStaticMapVaryZoom() { $instance = $this->getInstance(); $html = $instance->StaticMap(300, 800, 2); $expected = '<img src="//maps.googleapis.com/maps/api/staticmap?center=' .'13.8188931%2C100.5005558&markers=13.8188931%2C100.5005' .'558&zoom=2&size=300x800&sensor=false&mapt' .'ype=roadmap" width="300" height="800" alt="User" />'; $this->assertEquals($expected, $html); $html = $instance->StaticMap(300, 800, 12); $expected = '<img src="//maps.googleapis.com/maps/api/staticmap?center=' .'13.8188931%2C100.5005558&markers=13.8188931%2C100.5005' .'558&zoom=12&size=300x800&sensor=false&mapt' .'ype=roadmap" width="300" height="800" alt="User" />'; $this->assertEquals($expected, $html); } public function testStaticMapWithMapPin() { $instance = $this->getInstance(); $this->addMapPinToInstance($instance); $html = $instance->StaticMap(300, 800, 2); $this->assertStringStartsWith('<img src="//maps.googleapis.com/maps/api/staticmap?center=13.8188931%2C100.5005558&markers=icon%3A', $html); $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); } private function getInstance() { $instance = new Member(); $instance->Lat = 13.8188931; $instance->Lon = 100.5005558; $instance->FirstName = 'Test'; $instance->Surname = 'User'; return $instance; } /** * @param Member $instance */ private function addMapPinToInstance(&$instance) { // Create a pin $copied = copy('mappable/tests/images/mapicontest.png', 'assets/mapicontest.png'); $this->assertTrue($copied); $imageFile = new Image(array('Name' => 'mapicontest.png', 'Filename' => 'assets/mapicontest.png')); $imageFile->write(); $instance->MapPinIconID = $imageFile->ID; $instance->write(); } } |