Passed
Push — master ( 78bcd2...40c70a )
by Jason
02:20
created

PurchasableTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 82
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 33
dl 0
loc 82
rs 10
c 0
b 0
f 0
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A testValidate() 0 16 1
A isProduct() 0 4 1
A testUpdateCMSFields() 0 13 1
A testIsAvailable() 0 7 1
A setUp() 0 5 1
1
<?php
2
3
namespace Dynamic\Foxy\Test\Extension;
4
5
use Dynamic\Foxy\Extension\Purchasable;
6
use Dynamic\Foxy\Model\FoxyCategory;
7
use Dynamic\Foxy\Model\OptionType;
8
use Dynamic\Foxy\Test\TestOnly\TestProduct;
9
use SilverStripe\Core\Config\Config;
10
use SilverStripe\Core\Injector\Injector;
11
use SilverStripe\Dev\Debug;
12
use SilverStripe\Dev\SapphireTest;
13
use SilverStripe\Forms\FieldList;
14
use SilverStripe\ORM\ValidationException;
15
16
class PurchasableTest extends SapphireTest
17
{
18
    /**
19
     * @var string
20
     */
21
    protected static $fixture_file = '../fixtures.yml';
22
23
    /**
24
     * @var array
25
     */
26
    protected static $extra_dataobjects = [
27
        TestProduct::class,
28
    ];
29
30
    /**
31
     *
32
     */
33
    public function setUp()
34
    {
35
        Config::modify()->set(OptionType::class, 'has_one', ['TestProduct' => TestProduct::class]);
36
37
        return parent::setUp();
38
    }
39
40
    /**
41
     *
42
     */
43
    public function testUpdateCMSFields()
44
    {
45
        $object = Injector::inst()->create(TestProduct::class);
46
        $fields = $object->getCMSFields();
47
        $this->assertInstanceOf(FieldList::class, $fields);
48
49
        $object->Price = 10.00;
50
        $object->Code = 000123;
51
        $object->FoxyCategoryID = $this->objFromFixture(FoxyCategory::class, 'one')->ID;
52
53
        $object->write();
54
        $fields = $object->getCMSFields();
55
        $this->assertInstanceOf(FieldList::class, $fields);
56
    }
57
58
    /**
59
     *
60
     */
61
    public function testValidate()
62
    {
63
        $object = Injector::inst()->create(TestProduct::class);
64
        $object->Price = '';
65
        $this->setExpectedException(ValidationException::class);
0 ignored issues
show
Deprecated Code introduced by
The function PHPUnit_Framework_TestCase::setExpectedException() has been deprecated: Method deprecated since Release 5.2.0; use expectException() instead ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

65
        /** @scrutinizer ignore-deprecated */ $this->setExpectedException(ValidationException::class);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
66
        $object->write();
67
68
        $object->Price = '10.00';
69
        $object->Code = '';
70
        $this->setExpectedException(ValidationException::class);
0 ignored issues
show
Deprecated Code introduced by
The function PHPUnit_Framework_TestCase::setExpectedException() has been deprecated: Method deprecated since Release 5.2.0; use expectException() instead ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

70
        /** @scrutinizer ignore-deprecated */ $this->setExpectedException(ValidationException::class);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
71
        $object->write();
72
73
        $object->Code = '123';
74
        $object->FoxyCategoryID = '';
75
        $this->setExpectedException(ValidationException::class);
0 ignored issues
show
Deprecated Code introduced by
The function PHPUnit_Framework_TestCase::setExpectedException() has been deprecated: Method deprecated since Release 5.2.0; use expectException() instead ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

75
        /** @scrutinizer ignore-deprecated */ $this->setExpectedException(ValidationException::class);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
76
        $object->write();
77
    }
78
79
    /**
80
     *
81
     */
82
    public function testIsAvailable()
83
    {
84
        $object = Injector::inst()->create(TestProduct::class);
85
        $this->assertTrue($object->isAvailable());
86
87
        $object->Available = 0;
88
        $this->assertFalse($object->isAvailable());
89
    }
90
91
    /**
92
     *
93
     */
94
    public function isProduct()
95
    {
96
        $object = Injector::inst()->create(TestProduct::class);
97
        $this->assertTrue($object->isProduct());
98
    }
99
}
100