testGetRenderableMapSetNoMarkerValues()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 33

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 33
ccs 7
cts 7
cp 1
rs 9.392
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
class MappableDataTest extends SapphireTest
4
{
5
    public function setUpOnce()
6
    {
7
        $this->requiredExtensions = array(
8
            'Member' => array('MapExtension'),
9
        );
10
11
        parent::setupOnce();
12
    }
13
14 7
    public function setUp()
15
    {
16 7
        MapUtil::reset();
17 7
        parent::setUp();
18 7
    }
19
20 1
    public function testGetRenderableMapSetNoMarkerValues()
21
    {
22 1
        $instance = $this->getInstance();
23 1
        $instance->MapPinEdited = true;
24 1
        $html = $instance->getRenderableMap(300, 800, 2)->setDivId('testmap')->forTemplate()->getValue();
25
26
        $expected = <<<HTML
27
28
29
<div id="testmap" data-google-map-lang="en"  style="width:300; height: 800;"
30
 class=" mappable"
31
data-map
32
data-centre='{"lat":13.8188931,"lng":100.5005558}'
33
data-zoom=2
34
data-maptype='road'
35
data-allowfullscreen='1'
36
data-clusterergridsize=50,
37
data-clusterermaxzoom=17,
38
data-enableautocentrezoom=false
39
data-enablewindowzoom=false
40
data-infowindowzoom=13
41
data-mapmarkers='[{"latitude":13.8188931,"longitude":100.5005558,"html":"MEMBER: Test User","category":"default","icon":false}]'
42
data-defaulthidemarker=false
43
data-lines='[]'
44
data-kmlfiles='[]'
45
data-mapstyles='[]'
46
data-useclusterer=false
47
>
48
</div>
49
50 1
HTML;
51 1
        $this->assertEquals($expected, $html);
52 1
    }
53
54
    /**
55
     * The existenve of 'TestKeyVal' in the markers is the test here.
56
     *
57
     * FIXME: Leading blank space
58
     */
59 1
    public function testSetMarkerTemplateValues()
60
    {
61 1
        $instance = $this->getInstance();
62 1
        $instance->MapPinEdited = true;
63 1
        $vals = array('TestKey' => ' TestKeyVal');
64 1
        $instance->setMarkerTemplateValues($vals);
65 1
        $html = $instance->getRenderableMap(300, 800, 2)->setDivId('testmap')->forTemplate()->getValue();
66
        $expected = <<<HTML
67
68
69
<div id="testmap" data-google-map-lang="en"  style="width:300; height: 800;"
70
 class=" mappable"
71
data-map
72
data-centre='{"lat":13.8188931,"lng":100.5005558}'
73
data-zoom=2
74
data-maptype='road'
75
data-allowfullscreen='1'
76
data-clusterergridsize=50,
77
data-clusterermaxzoom=17,
78
data-enableautocentrezoom=false
79
data-enablewindowzoom=false
80
data-infowindowzoom=13
81
data-mapmarkers='[{"latitude":13.8188931,"longitude":100.5005558,"html":"MEMBER: Test User TestKeyVal","category":"default","icon":false}]'
82
data-defaulthidemarker=false
83
data-lines='[]'
84
data-kmlfiles='[]'
85
data-mapstyles='[]'
86
data-useclusterer=false
87
>
88
</div>
89
90 1
HTML;
91
92 1
        $this->assertEquals($expected, $html);
93 1
    }
94
95 1
    public function testStaticMapChangeLocation()
96
    {
97 1
        $instance = $this->getInstance();
98 1
        $instance->Lat = 13.84;
99 1
        $instance->Lon = 100.52;
100 1
        $html = $instance->StaticMap(300, 800);
101
        $expected = '<img src="//maps.googleapis.com/maps/api/staticmap?center='
102
                  .'13.84%2C100.52&amp;markers=13.84%2C100.52'
103 1
                  .'&amp;zoom=13&amp;size=300x800&amp;sensor=false&amp;mapt'
104 1
                  .'ype=roadmap" width="300" height="800" alt="User" />';
105 1
        $this->assertEquals($expected, $html);
106 1
    }
107
108 1
    public function testStaticMapVarySize()
109
    {
110 1
        $instance = $this->getInstance();
111 1
        $instance->Lat = 13.8188931;
112 1
        $instance->Lon = 100.5005558;
113 1
        $html = $instance->StaticMap(300, 800);
114
        $expected = '<img src="//maps.googleapis.com/maps/api/staticmap?center='
115
                  .'13.8188931%2C100.5005558&amp;markers=13.8188931%2C100.5005'
116 1
                  .'558&amp;zoom=13&amp;size=300x800&amp;sensor=false&amp;mapt'
117 1
                  .'ype=roadmap" width="300" height="800" alt="User" />';
118 1
        $this->assertEquals($expected, $html);
119
120 1
        $html = $instance->StaticMap(310, 810);
121
        $expected = '<img src="//maps.googleapis.com/maps/api/staticmap?center='
122
                  .'13.8188931%2C100.5005558&amp;markers=13.8188931%2C100.5005'
123 1
                  .'558&amp;zoom=13&amp;size=310x810&amp;sensor=false&amp;mapt'
124 1
                  .'ype=roadmap" width="310" height="810" alt="User" />';
125 1
        $this->assertEquals($expected, $html);
126 1
    }
127
128 1
    public function testStaticMapVaryTerrain()
129
    {
130 1
        $instance = $this->getInstance();
131 1
        $instance->Lat = 13.8188931;
132 1
        $instance->Lon = 100.5005558;
133 1
        $html = $instance->StaticMap(300, 800, null, 'satellite');
134
        $expected = '<img src="//maps.googleapis.com/maps/api/staticmap?center='
135
                  .'13.8188931%2C100.5005558&amp;markers=13.8188931%2C100.5005'
136 1
                  .'558&amp;zoom=13&amp;size=300x800&amp;sensor=false&amp;mapt'
137 1
                  .'ype=satellite" width="300" height="800" alt="User" />';
138 1
        $this->assertEquals($expected, $html);
139
140 1
        $html = $instance->StaticMap(300, 800, null, 'terrain');
0 ignored issues
show
Unused Code introduced by
$html is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
141
        $expected = '<img src="//maps.googleapis.com/maps/api/staticmap?center='
0 ignored issues
show
Unused Code introduced by
$expected is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
142
                  .'13.8188931%2C100.5005558&amp;markers=13.8188931%2C100.5005'
143 1
                  .'558&amp;zoom=13&amp;size=300x800&amp;sensor=false&amp;mapt'
144 1
                  .'ype=terrain" width="300" height="800" alt="User" />';
145
146 1
        $html = $instance->StaticMap(300, 800, null, 'hybrid');
147
        $expected = '<img src="//maps.googleapis.com/maps/api/staticmap?center='
148
                  .'13.8188931%2C100.5005558&amp;markers=13.8188931%2C100.5005'
149 1
                  .'558&amp;zoom=13&amp;size=300x800&amp;sensor=false&amp;mapt'
150 1
                  .'ype=hybrid" width="300" height="800" alt="User" />';
151 1
        $this->assertEquals($expected, $html);
152 1
    }
153
154 1
    public function testStaticMapVaryZoom()
155
    {
156 1
        $instance = $this->getInstance();
157
158 1
        $html = $instance->StaticMap(300, 800, 2);
159
        $expected = '<img src="//maps.googleapis.com/maps/api/staticmap?center='
160
                  .'13.8188931%2C100.5005558&amp;markers=13.8188931%2C100.5005'
161 1
                  .'558&amp;zoom=2&amp;size=300x800&amp;sensor=false&amp;mapt'
162 1
                  .'ype=roadmap" width="300" height="800" alt="User" />';
163 1
        $this->assertEquals($expected, $html);
164
165 1
        $html = $instance->StaticMap(300, 800, 12);
166
        $expected = '<img src="//maps.googleapis.com/maps/api/staticmap?center='
167
                  .'13.8188931%2C100.5005558&amp;markers=13.8188931%2C100.5005'
168 1
                  .'558&amp;zoom=12&amp;size=300x800&amp;sensor=false&amp;mapt'
169 1
                  .'ype=roadmap" width="300" height="800" alt="User" />';
170 1
        $this->assertEquals($expected, $html);
171 1
    }
172
173 1
    public function testStaticMapWithMapPin()
174
    {
175 1
        $instance = $this->getInstance();
176 1
        $this->addMapPinToInstance($instance);
177
178 1
        $html = $instance->StaticMap(300, 800, 2);
179
180 1
        $this->assertStringStartsWith('<img src="//maps.googleapis.com/maps/api/staticmap?center=13.8188931%2C100.5005558&amp;markers=icon%3A', $html);
181 1
        $this->assertStringEndsWith('%2Fassets%2Fmapicontest.png%7C13.8188931%2C100.5005558&amp;zoom=2&amp;size=300x800&amp;sensor=false&amp;maptype=roadmap" width="300" height="800" alt="User, Test" />', $html);
182 1
    }
183
184 7 View Code Duplication
    private function getInstance()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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

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

Loading history...
185
    {
186 7
        $instance = new Member();
187 7
        $instance->Lat = 13.8188931;
188 7
        $instance->Lon = 100.5005558;
189 7
        $instance->FirstName = 'Test';
190 7
        $instance->Surname = 'User';
191
192 7
        return $instance;
193
    }
194
195
    /**
196
     * @param Member $instance
197
     */
198 1 View Code Duplication
    private function addMapPinToInstance(&$instance)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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

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

Loading history...
199
    {
200
        // Create a pin
201 1
        $copied = copy('mappable/tests/images/mapicontest.png', 'assets/mapicontest.png');
202 1
        $this->assertTrue($copied);
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<MappableDataTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
203 1
        $imageFile = new Image(array('Name' => 'mapicontest.png', 'Filename' => 'assets/mapicontest.png'));
204 1
        $imageFile->write();
205 1
        $instance->MapPinIconID = $imageFile->ID;
206 1
        $instance->write();
207 1
    }
208
}
209