Completed
Push — master ( dd845a...c89ab0 )
by Jason
12s
created

tests/LocatorTest.php (8 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace Dynamic\Locator\Tests;
4
5
use Dynamic\Locator\Location;
6
use Dynamic\Locator\Locator;
7
use Dynamic\Locator\LocatorController;
8
use Dynamic\SilverStripeGeocoder\GoogleGeocoder;
9
use SilverStripe\Core\Config\Config;
10
use SilverStripe\Dev\FunctionalTest;
11
12
/**
13
 * Class LocatorTest
14
 */
15
class LocatorTest extends FunctionalTest
16
{
17
    /**
18
     * @var string
19
     */
20
    protected static $fixture_file = 'locator/tests/fixtures.yml';
21
22
    /**
23
     *
24
     */
25
    public function testGetCMSFields()
26
    {
27
        $locator = singleton('Dynamic\\Locator\\Locator');
28
        $this->assertInstanceOf('SilverStripe\\Forms\\FieldList', $locator->getCMSFields());
29
    }
30
31
    /**
32
     *
33
     */
34
    public function testLocations()
35
    {
36
        $filter = Config::inst()->get(LocatorController::class, 'base_filter');
37
        $filterAny = Config::inst()->get(LocatorController::class, 'base_filter_any');
38
        $exclude = Config::inst()->get(LocatorController::class, 'base_exclude');
39
        $locations = Locator::get_locations($filter, $filterAny, $exclude);
40
        $locations2 = Location::get()->filter($filter)->filterAny($filterAny)->exclude($exclude);
41
        $this->assertEquals($locations->count(), $locations2->count());
0 ignored issues
show
The method assertEquals() does not seem to exist on object<Dynamic\Locator\Tests\LocatorTest>.

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...
42
    }
43
44
    /**
45
     *
46
     */
47
    public function testGetAllCategories()
48
    {
49
50
        $this->assertEquals(Locator::get_all_categories()->count(), 4);
0 ignored issues
show
The method assertEquals() does not seem to exist on object<Dynamic\Locator\Tests\LocatorTest>.

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...
51
    }
52
53
    /**
54
     *
55
     */
56
    public function testGetPageCategories()
57
    {
58
        $locator = $this->objFromFixture('Dynamic\\Locator\\Locator', 'locator1');
59
        $this->assertEquals($locator->getPageCategories()->count(), 2);
0 ignored issues
show
The method assertEquals() does not seem to exist on object<Dynamic\Locator\Tests\LocatorTest>.

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...
60
    }
61
62
    /**
63
     *
64
     */
65
    public function testLocatorCategoriesByLocator()
66
    {
67
68
        $locator = $this->objFromFixture('Dynamic\\Locator\\Locator', 'locator1');
69
        $this->assertEquals(Locator::locator_categories_by_locator($locator->ID)->count(), 2);
0 ignored issues
show
The method assertEquals() does not seem to exist on object<Dynamic\Locator\Tests\LocatorTest>.

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...
70
71
        $newLocator = Locator::create();
72
        $newLocator->Title = 'Locator 2';
73
        $newLocator->write();
74
75
        $this->assertEquals(Locator::locator_categories_by_locator($newLocator->ID)->count(), 0);
0 ignored issues
show
The method assertEquals() does not seem to exist on object<Dynamic\Locator\Tests\LocatorTest>.

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...
76
77
    }
78
79
    /**
80
     *
81
     */
82
    public function testInit()
83
    {
84
    }
85
86
    /**
87
     *
88
     */
89
    public function testIndex()
90
    {
91
        $locator = $this->objFromFixture('Dynamic\\Locator\\Locator', 'locator1');
92
        $controller = LocatorController::create($locator);
93
        $this->assertInstanceOf('SilverStripe\\View\\ViewableData', $controller->index($controller->request));
94
    }
95
96
    /**
97
     *
98
     */
99
    public function testXml()
100
    {
101
        $locator = $this->objFromFixture('Dynamic\\Locator\\Locator', 'locator1');
102
        $controller = LocatorController::create($locator);
103
        $this->assertInstanceOf('SilverStripe\\ORM\\FieldType\\DBHTMLText', $controller->xml($controller->request));
104
    }
105
106
    /**
107
     *
108
     */
109
    public function testLocationSearch()
110
    {
111
        $locator = $this->objFromFixture('Dynamic\\Locator\\Locator', 'locator1');
112
        $object = LocatorController::create($locator);
113
        $form = $object->LocationSearch();
114
        $this->assertTrue(is_a($form, 'SilverStripe\\Forms\\Form'));
0 ignored issues
show
The method assertTrue() does not seem to exist on object<Dynamic\Locator\Tests\LocatorTest>.

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...
115
116
        $category = $this->objFromFixture('Dynamic\\Locator\\LocationCategory', 'service');
117
        $category2 = $this->objFromFixture('Dynamic\\Locator\\LocationCategory', 'manufacturing');
118
        $locator->Categories()->add($category);
119
        $locator->Categories()->add($category2);
120
121
        $form = $object->LocationSearch();
122
        $fields = $form->Fields();
123
        $this->assertInstanceOf('SilverStripe\\Forms\\FieldList', $fields);
124
    }
125
126
    /**
127
     *
128
     */
129
    public function testLocationInfoTemplates()
130
    {
131
        $this->assertEquals('locator/templates/location-list-description.html', Config::inst()->get(LocatorController::class, 'list_template_path'));
0 ignored issues
show
The method assertEquals() does not seem to exist on object<Dynamic\Locator\Tests\LocatorTest>.

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...
132
        $this->assertEquals('locator/templates/infowindow-description.html', Config::inst()->get(LocatorController::class, 'info_window_template_path'));
0 ignored issues
show
The method assertEquals() does not seem to exist on object<Dynamic\Locator\Tests\LocatorTest>.

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...
133
    }
134
135
}
136