ProductCategoryTest   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
eloc 18
c 1
b 0
f 0
dl 0
loc 42
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testGetCMSFields() 0 5 1
A testGetProductList() 0 22 1
1
<?php
2
3
namespace Dynamic\Products\Test\Page;
4
5
use Dynamic\Products\Page\ProductCategory;
6
use SilverStripe\Dev\SapphireTest;
7
use SilverStripe\Forms\FieldList;
8
use SilverStripe\Security\Member;
9
10
class ProductCategoryTest extends SapphireTest
11
{
12
    /**
13
     * @var string
14
     */
15
    protected static $fixture_file = '../fixtures.yml';
16
17
    /**
18
     *
19
     */
20
    public function testGetCMSFields()
21
    {
22
        $object = $this->objFromFixture(ProductCategory::class, 'default');
23
        $fields = $object->getCMSFields();
24
        $this->assertInstanceOf(FieldList::class, $fields);
25
    }
26
27
    /**
28
     *
29
     */
30
    public function testGetProductList()
31
    {
32
        $this->markTestSkipped('Currently doesn\'t seem to respect the groups/members in automated tests');
33
34
        $this->logOut();
35
        $member = $this->objFromFixture(Member::class, 'author');
36
        $this->logInAs(Member::get()->byID($member->ID));
37
        $categoryID = $this->objFromFixture(ProductCategory::class, 'restricted')->ID;
38
        /** @var ProductCategory $category */
39
        $category = ProductCategory::get()->byID($categoryID);
40
41
        $this->assertEquals(2, $category->getProductList()->count());
42
43
        $this->logOut();
44
        $member = $this->objFromFixture(Member::class, 'default');
45
        $this->logInAs(Member::get()->byID($member->ID));
46
        /** @var ProductCategory $category */
47
        $category = ProductCategory::get()->byID($categoryID);
48
49
        $this->assertEquals(1, $category->getProductList()->count());
50
51
        $this->logOut();
52
    }
53
}
54