Passed
Pull Request — master (#174)
by Matthew
05:38
created

LocatorTest   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 89
Duplicated Lines 19.1 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 17
loc 89
rs 10
c 1
b 0
f 0
wmc 7

7 Methods

Rating   Name   Duplication   Size   Complexity  
A testGetCMSFields() 0 5 1
A testLocatorCategoriesByLocator() 0 11 1
A testGetAllCategories() 0 4 1
A testGetListTemplate() 8 8 1
A testGetInfoWindowTemplate() 8 8 1
A testLocations() 0 8 1
A testGetPageCategories() 0 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Dynamic\Locator\Tests;
4
5
use Dynamic\Locator\Location;
6
use Dynamic\Locator\LocationCategory;
7
use Dynamic\Locator\Locator;
8
use Dynamic\Locator\LocatorController;
9
use Dynamic\SilverStripeGeocoder\GoogleGeocoder;
10
use SilverStripe\Core\Config\Config;
11
use SilverStripe\Core\Injector\Injector;
12
use SilverStripe\Dev\FunctionalTest;
13
use SilverStripe\Forms\FieldList;
14
use SilverStripe\Forms\Form;
15
use SilverStripe\ORM\FieldType\DBHTMLText;
16
use SilverStripe\View\ViewableData;
17
18
/**
19
 * Class LocatorTest
20
 */
21
class LocatorTest extends FunctionalTest
22
{
23
    /**
24
     * @var string
25
     */
26
    protected static $fixture_file = '../fixtures.yml';
27
28
    /**
29
     *
30
     */
31
    public function testGetCMSFields()
32
    {
33
        /** @var Locator $locator */
34
        $locator = Injector::inst()->create(Locator::class);
35
        $this->assertInstanceOf(FieldList::class, $locator->getCMSFields());
36
    }
37
38
    /**
39
     *
40
     */
41
    public function testLocations()
42
    {
43
        $filter = Config::inst()->get(LocatorController::class, 'base_filter');
44
        $filterAny = Config::inst()->get(LocatorController::class, 'base_filter_any');
45
        $exclude = Config::inst()->get(LocatorController::class, 'base_exclude');
46
        $locations = Locator::get_locations($filter, $filterAny, $exclude);
47
        $locations2 = Location::get()->filter($filter)->filterAny($filterAny)->exclude($exclude);
48
        $this->assertEquals($locations->count(), $locations2->count());
49
    }
50
51
    /**
52
     *
53
     */
54
    public function testGetAllCategories()
55
    {
56
57
        $this->assertEquals(Locator::get_all_categories()->count(), 4);
58
    }
59
60
    /**
61
     *
62
     */
63
    public function testGetPageCategories()
64
    {
65
        $locator = $this->objFromFixture(Locator::class, 'locator1');
66
        $this->assertEquals($locator->getPageCategories()->count(), 2);
67
    }
68
69
    /**
70
     *
71
     */
72
    public function testLocatorCategoriesByLocator()
73
    {
74
75
        $locator = $this->objFromFixture(Locator::class, 'locator1');
76
        $this->assertEquals(Locator::locator_categories_by_locator($locator->ID)->count(), 2);
77
78
        $newLocator = Locator::create();
79
        $newLocator->Title = 'Locator 2';
80
        $newLocator->write();
81
82
        $this->assertEquals(Locator::locator_categories_by_locator($newLocator->ID)->count(), 0);
83
84
    }
85
86
    /**
87
     *
88
     */
89 View Code Duplication
    public function testGetInfoWindowTemplate()
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...
90
    {
91
        /** @var Locator $object */
92
        $object = Injector::inst()->create(Locator::class);
93
        $template = $object->getInfoWindowTemplate();
94
        // get rid of cache ending
95
        $template = preg_replace('/\?.*$/', '', $template);
96
        $this->assertStringEndsWith('client/infowindow-description.html', $template);
97
    }
98
99
    /**
100
     *
101
     */
102 View Code Duplication
    public function testGetListTemplate()
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...
103
    {
104
        /** @var Locator $object */
105
        $object = Injector::inst()->create(Locator::class);
106
        $template = $object->getListTemplate();
107
        // get rid of cache ending
108
        $template = preg_replace('/\?.*$/', '', $template);
109
        $this->assertStringEndsWith('client/location-list-description.html', $template);
110
    }
111
}
112