Completed
Pull Request — 3.1 (#3)
by Gordon
02:49
created

PointOfInterestTest::testShowGuideMarkers()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 38
Code Lines 29

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 38
rs 8.8571
cc 2
eloc 29
nc 2
nop 0
1
<?php
2
3
class PointOfInterestTest extends SapphireTest
4
{
5
    protected static $fixture_file = 'mappable-poi/tests/pointsofinterest.yml';
6
7
    public function testUpdateCMSFields()
8
    {
9
        $poi = new PointOfInterest();
10
        $fields = $poi->getCMSFields();
11
        $tab = $fields->findOrMakeTab('Root.Main');
12
        $fields = $tab->FieldList();
13
        $names = array();
14
        foreach ($fields as $field) {
15
            $names[] = $field->getName();
16
        }
17
18
        $this->assertEquals(array('Name'), $names);
19
    }
20
21
    public function testShowGuideMarkers()
22
    {
23
        $layer = $this->objFromFixture('PointsOfInterestLayer', 'BTS');
24
        error_log('LAYER: '.$layer->Name);
25
        $pois = $layer->PointsOfInterest();
26
        $poi = $pois->first();
27
28
        // guidemarkers off, expect null returned
29
        $layer->ShowGuideMarkers = 0;
30
        $layer->write();
31
        $poi->getCMSFields();
32
        $guidepoints = $poi->getMapField()->getGuidePoints();
33
        $this->assertNull($guidepoints);
34
35
        // guidemarkers on, convert datalist to an array of coordinates
36
        $layer->ShowGuideMarkers = 1;
37
        $layer->write();
38
        $poi->getCMSFields();
39
        $guidepoints = $poi->getMapField()->getGuidePoints();
40
        $expected = array();
41
        $coors = array();
42
        foreach ($guidepoints as $gp) {
43
            $coors[] = array($gp->Lat, $gp->Lon);
44
        }
45
46
        $expected = array(
47
            array(13.77965803301, 100.54461523531),
48
            array(13.744081610619, 100.54311513861),
49
            array(13.802594511242, 100.55379467004),
50
            array(13.74054138487, 100.55545772112),
51
            array(13.756924089277, 100.53381164654),
52
            array(13.751846080459, 100.53157277536),
53
            array(13.772614550915, 100.54209276599),
54
            array(13.793846082833, 100.54974883766),
55
            array(13.762764662241, 100.53706848861),
56
        );
57
        $this->assertEquals($expected, $coors);
58
    }
59
}
60