Passed
Pull Request — master (#111)
by Jason
02:35
created

PurchasableTest::testGetIsAvailable()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 8
nc 1
nop 0
dl 0
loc 17
rs 10
c 0
b 0
f 0
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;
0 ignored issues
show
Bug introduced by
The type Dynamic\Foxy\Model\OptionType was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
use Dynamic\Foxy\Model\ProductOption;
0 ignored issues
show
Bug introduced by
The type Dynamic\Foxy\Model\ProductOption was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
9
use Dynamic\Foxy\Model\Setting;
10
use Dynamic\Foxy\Model\Variation;
11
use Dynamic\Foxy\Test\TestOnly\TestProduct;
12
use Dynamic\Foxy\Test\TestOnly\TestVariation;
13
use Dynamic\Foxy\Test\TestOnly\TestVariationDataExtension;
0 ignored issues
show
Bug introduced by
The type Dynamic\Foxy\Test\TestOn...tVariationDataExtension was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
14
use SilverStripe\Core\Config\Config;
15
use SilverStripe\Core\Injector\Injector;
16
use SilverStripe\Dev\Debug;
17
use SilverStripe\Dev\SapphireTest;
18
use SilverStripe\Forms\FieldList;
19
use SilverStripe\i18n\i18n;
20
use SilverStripe\ORM\ValidationException;
21
use SilverStripe\Security\Member;
22
23
/**
24
 * Class PurchasableTest
25
 * @package Dynamic\Foxy\Test\Extension
26
 */
27
class PurchasableTest extends SapphireTest
28
{
29
    /**
30
     * @var string
31
     */
32
    protected static $fixture_file = '../fixtures.yml';
33
34
    /**
35
     * @var array
36
     */
37
    protected static $extra_dataobjects = [
38
        TestProduct::class,
39
        TestVariation::class,
40
    ];
41
42
    /**
43
     * @var \string[][]
44
     */
45
    protected static $required_extensions = [
46
        TestProduct::class => [
47
            Purchasable::class,
48
        ],
49
    ];
50
51
    /**
52
     *
53
     */
54
    public function setUp()
55
    {
56
        Config::modify()->set(TestVariation::class, 'has_one', ['Product' => TestProduct::class]);
57
58
        return parent::setUp();
59
    }
60
61
    /**
62
     *
63
     */
64
    public function testUpdateCMSFields()
65
    {
66
        /** @var TestProduct $object */
67
        $object = $this->objFromFixture(TestProduct::class, 'one');
68
        $fields = $object->getCMSFields();
69
        $this->assertInstanceOf(FieldList::class, $fields);
70
    }
71
72
    /**
73
     *
74
     */
75
    public function testGetIsAvailable()
76
    {
77
        /** @var TestProduct $object */
78
        $object = $this->objFromFixture(TestProduct::class, 'one');
79
        $this->assertTrue($object->getIsAvailable());
0 ignored issues
show
Bug introduced by
The method getIsAvailable() does not exist on Dynamic\Foxy\Test\TestOnly\TestProduct. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

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

79
        $this->assertTrue($object->/** @scrutinizer ignore-call */ getIsAvailable());
Loading history...
80
81
        /** @var TestProduct $object */
82
        $object = $this->objFromFixture(TestProduct::class, 'two');
83
        $this->assertFalse($object->getIsAvailable());
84
85
        /** @var TestProduct $object */
86
        $object = $this->objFromFixture(TestProduct::class, 'three');
87
        $this->assertTrue($object->getIsAvailable());
88
89
        /** @var TestProduct $object */
90
        $object = $this->objFromFixture(TestProduct::class, 'four');
91
        $this->assertFalse($object->getIsAvailable());
92
    }
93
94
    /**
95
     *
96
     */
97
    public function testIsProduct()
98
    {
99
        /** @var TestProduct $object */
100
        $object = $this->objFromFixture(TestProduct::class, 'one');
101
        $this->assertTrue($object->isProduct());
0 ignored issues
show
Bug introduced by
The method isProduct() does not exist on Dynamic\Foxy\Test\TestOnly\TestProduct. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

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

101
        $this->assertTrue($object->/** @scrutinizer ignore-call */ isProduct());
Loading history...
102
    }
103
104
    /**
105
     *
106
     */
107
    public function testProvidePermissions()
108
    {
109
        /** @var TestProduct $object */
110
        $object = singleton(Purchasable::class);
111
112
        i18n::set_locale('en');
113
        $expected = [
114
            'MANAGE_FOXY_PRODUCTS' => [
115
                'name' => 'Manage products',
116
                'category' => 'Foxy',
117
                'help' => 'Manage products and related settings',
118
                'sort' => 400
119
            ]
120
        ];
121
        $this->assertEquals($expected, $object->providePermissions());
122
    }
123
124
    /**
125
     *
126
     */
127
    public function testCanCreate()
128
    {
129
        /** @var TestProduct $object */
130
        $object = singleton(TestProduct::class);
131
        /** @var \SilverStripe\Security\Member $admin */
132
        $admin = $this->objFromFixture(Member::class, 'admin');
133
        /** @var \SilverStripe\Security\Member $siteOwner */
134
        $siteOwner = $this->objFromFixture(Member::class, 'site-owner');
135
        /** @var \SilverStripe\Security\Member $default */
136
        $default = $this->objFromFixture(Member::class, 'default');
137
138
        $this->assertFalse($object->canCreate($default));
139
        $this->assertTrue($object->canCreate($admin));
140
        $this->assertTrue($object->canCreate($siteOwner));
141
    }
142
143
    /**
144
     *
145
     */
146
    public function testCanEdit()
147
    {
148
        /** @var TestProduct $object */
149
        $object = singleton(TestProduct::class);
150
        /** @var \SilverStripe\Security\Member $admin */
151
        $admin = $this->objFromFixture(Member::class, 'admin');
152
        /** @var \SilverStripe\Security\Member $siteOwner */
153
        $siteOwner = $this->objFromFixture(Member::class, 'site-owner');
154
        /** @var \SilverStripe\Security\Member $default */
155
        $default = $this->objFromFixture(Member::class, 'default');
156
157
        $this->assertFalse($object->canEdit($default));
158
        $this->assertTrue($object->canEdit($admin));
159
        $this->assertTrue($object->canEdit($siteOwner));
160
    }
161
162
    /**
163
     *
164
     */
165
    public function testCanDelete()
166
    {
167
        /** @var TestProduct $object */
168
        $object = singleton(TestProduct::class);
169
        /** @var \SilverStripe\Security\Member $admin */
170
        $admin = $this->objFromFixture(Member::class, 'admin');
171
        /** @var \SilverStripe\Security\Member $siteOwner */
172
        $siteOwner = $this->objFromFixture(Member::class, 'site-owner');
173
        /** @var \SilverStripe\Security\Member $default */
174
        $default = $this->objFromFixture(Member::class, 'default');
175
176
        $this->assertFalse($object->canDelete($default));
177
        $this->assertTrue($object->canDelete($admin));
178
        $this->assertTrue($object->canDelete($siteOwner));
179
    }
180
181
    /**
182
     *
183
     */
184
    public function testCanUnpublish()
185
    {
186
        /** @var TestProduct $object */
187
        $object = singleton(TestProduct::class);
188
        /** @var \SilverStripe\Security\Member $admin */
189
        $admin = $this->objFromFixture(Member::class, 'admin');
190
        /** @var \SilverStripe\Security\Member $siteOwner */
191
        $siteOwner = $this->objFromFixture(Member::class, 'site-owner');
192
        /** @var \SilverStripe\Security\Member $default */
193
        $default = $this->objFromFixture(Member::class, 'default');
194
195
        $this->assertFalse($object->canUnpublish($default));
0 ignored issues
show
Bug introduced by
The method canUnpublish() does not exist on Dynamic\Foxy\Test\TestOnly\TestProduct. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

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

195
        $this->assertFalse($object->/** @scrutinizer ignore-call */ canUnpublish($default));
Loading history...
196
        $this->assertTrue($object->canUnpublish($admin));
197
        $this->assertTrue($object->canUnpublish($siteOwner));
198
    }
199
200
    /**
201
     *
202
     */
203
    public function testCanArchive()
204
    {
205
        /** @var TestProduct $object */
206
        $object = singleton(TestProduct::class);
207
        /** @var \SilverStripe\Security\Member $admin */
208
        $admin = $this->objFromFixture(Member::class, 'admin');
209
        /** @var \SilverStripe\Security\Member $siteOwner */
210
        $siteOwner = $this->objFromFixture(Member::class, 'site-owner');
211
        /** @var \SilverStripe\Security\Member $default */
212
        $default = $this->objFromFixture(Member::class, 'default');
213
214
        $this->assertFalse($object->canArchive($default));
0 ignored issues
show
Bug introduced by
The method canArchive() does not exist on Dynamic\Foxy\Test\TestOnly\TestProduct. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

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

214
        $this->assertFalse($object->/** @scrutinizer ignore-call */ canArchive($default));
Loading history...
215
        $this->assertTrue($object->canArchive($admin));
216
        $this->assertTrue($object->canArchive($siteOwner));
217
    }
218
}
219