Passed
Pull Request — master (#40)
by Robbie
02:47
created

ResourceTest   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 13
dl 0
loc 25
rs 10
c 0
b 0
f 0
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A testFieldsAndFiltersAreRemovedAfterChangingIdentifier() 0 21 1
1
<?php
2
3
namespace SilverStripe\CKANRegistry\Tests\Model;
4
5
use SilverStripe\CKANRegistry\Model\Resource;
6
use SilverStripe\Dev\SapphireTest;
7
8
class ResourceTest extends SapphireTest
9
{
10
    protected static $fixture_file = 'ResourceTest.yml';
11
12
    public function testFieldsAndFiltersAreRemovedAfterChangingIdentifier()
13
    {
14
        /** @var Resource $resource */
15
        $resource = $this->objFromFixture(Resource::class, 'teachers');
16
17
        $this->assertGreaterThan(0, $resource->Fields()->count(), 'Fixtures should load relationships');
18
        $this->assertGreaterThan(0, $resource->Filters()->count(), 'Fixtures should load relationships');
19
20
        // Change name, relationships should be retained
21
        $resource->Name = 'Primary Teachers';
0 ignored issues
show
Bug Best Practice introduced by
The property Name does not exist on SilverStripe\CKANRegistry\Model\Resource. Since you implemented __set, consider adding a @property annotation.
Loading history...
22
        $resource->write();
23
24
        $this->assertGreaterThan(0, $resource->Fields()->count(), 'Changing name should not affect relations');
25
        $this->assertGreaterThan(0, $resource->Filters()->count(), 'Changing name should not affect relations');
26
27
        // Change identifier, relationships should be removed
28
        $resource->Identifier = 'something-different';
0 ignored issues
show
Bug Best Practice introduced by
The property Identifier does not exist on SilverStripe\CKANRegistry\Model\Resource. Since you implemented __set, consider adding a @property annotation.
Loading history...
29
        $resource->write();
30
31
        $this->assertCount(0, $resource->Fields(), 'Changing identifier should clear fields');
32
        $this->assertCount(0, $resource->Filters(), 'Changing identifier should clear filters');
33
    }
34
}
35