FluentSiteStateTest   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Importance

Changes 6
Bugs 0 Features 0
Metric Value
eloc 28
c 6
b 0
f 0
dl 0
loc 59
rs 10
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A testAppliesTo() 0 5 1
A testCurrentState() 0 7 1
A testDefaultState() 0 5 1
A testIsApplicable() 0 5 1
A testUpdateQuery() 0 27 1
1
<?php
2
3
4
namespace Firesphere\SolrFluent\Tests;
5
6
use Firesphere\SolrFluent\States\FluentSiteState;
7
use Firesphere\SolrSearch\Queries\BaseQuery;
8
use SilverStripe\CMS\Model\SiteTree;
9
use SilverStripe\Dev\SapphireTest;
10
use TractorCow\Fluent\State\FluentState;
11
12
class FluentSiteStateTest extends SapphireTest
13
{
14
    public function testAppliesTo()
15
    {
16
        $state = new FluentSiteState();
17
18
        $this->assertFalse($state->appliesTo(SiteTree::class));
19
    }
20
21
    public function testIsApplicable()
22
    {
23
        $state = new FluentSiteState();
24
25
        $this->assertFalse($state->stateIsApplicable('en_US'));
26
    }
27
28
    public function testCurrentState()
29
    {
30
        $state = new FluentSiteState();
31
32
        $this->assertNull($state->activateState('en_US'));
33
34
        $this->assertEquals('en_US', $state->currentState());
35
    }
36
37
    public function testDefaultState()
38
    {
39
        $state = new FluentSiteState();
40
41
        $this->assertNull($state->setDefaultState('en_US'));
42
    }
43
44
    public function testUpdateQuery()
45
    {
46
        $query = new BaseQuery();
47
        FluentState::singleton()->setLocale('');
48
        $query->addTerm('Test');
49
        $terms = $query->getTerms();
50
        $query->addFilter('TestField', 'Value');
51
        $state = new FluentSiteState();
52
        $this->assertNull($state->updateQuery($query));
0 ignored issues
show
Bug introduced by
Are you sure the usage of $state->updateQuery($query) targeting Firesphere\SolrFluent\St...iteState::updateQuery() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
53
54
        $this->assertEquals($terms, $query->getTerms());
55
56
        FluentState::singleton()->setLocale('en_NZ');
57
58
        $query->addTerm('Test2', ['TestField']);
59
        $query->addField('MyField');
60
        $state->updateQuery($query);
61
62
        $filters = $query->getFilter();
63
        $fields = $query->getFields();
64
        $terms = $query->getTerms();
65
66
        $this->assertArrayHasKey('TestField_en_NZ', $filters);
67
68
        $this->assertEquals('MyField_en_NZ', $fields[0]);
69
70
        $this->assertEquals(['TestField_en_NZ'], $terms[1]['fields']);
71
    }
72
}
73