1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Dynamic\Foxy\Test\Model; |
4
|
|
|
|
5
|
|
|
use Dynamic\Foxy\Model\FoxyCategory; |
6
|
|
|
use Dynamic\Foxy\Test\TestOnly\TestProduct; |
7
|
|
|
use SilverStripe\Core\Injector\Injector; |
8
|
|
|
use SilverStripe\Dev\SapphireTest; |
9
|
|
|
use SilverStripe\Forms\FieldList; |
10
|
|
|
use SilverStripe\ORM\ValidationException; |
11
|
|
|
use SilverStripe\Security\Member; |
12
|
|
|
|
13
|
|
|
class FoxyCategoryTest extends SapphireTest |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* @var string |
17
|
|
|
*/ |
18
|
|
|
protected static $fixture_file = '../fixtures.yml'; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* |
22
|
|
|
*/ |
23
|
|
|
public function testGetCMSFields() |
24
|
|
|
{ |
25
|
|
|
$object = $this->objFromFixture(FoxyCategory::class, 'one'); |
26
|
|
|
$fields = $object->getCMSFields(); |
27
|
|
|
$this->assertInstanceOf(FieldList::class, $fields); |
28
|
|
|
|
29
|
|
|
$object = Injector::inst()->create(FoxyCategory::class); |
30
|
|
|
$object->Code = 'DEFAULT'; |
31
|
|
|
$object->write(); |
32
|
|
|
$fields = $object->getCMSFields(); |
33
|
|
|
$this->assertInstanceOf(FieldList::class, $fields); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* |
38
|
|
|
*/ |
39
|
|
|
public function testValidateCode() |
40
|
|
|
{ |
41
|
|
|
$object = $this->objFromFixture(FoxyCategory::class, 'one'); |
42
|
|
|
$object->Code = ''; |
43
|
|
|
$this->setExpectedException(ValidationException::class); |
|
|
|
|
44
|
|
|
$object->write(); |
45
|
|
|
|
46
|
|
|
$object = $this->objFromFixture(FoxyCategory::class, 'one'); |
47
|
|
|
$object->Code = 'DEFAULT'; |
48
|
|
|
$this->setExpectedException(ValidationException::class); |
|
|
|
|
49
|
|
|
$object->write(); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* |
54
|
|
|
*/ |
55
|
|
|
public function testCanCreate() |
56
|
|
|
{ |
57
|
|
|
/** @var FoxyCategory $object */ |
58
|
|
|
$object = singleton(FoxyCategory::class); |
59
|
|
|
/** @var \SilverStripe\Security\Member $admin */ |
60
|
|
|
$admin = $this->objFromFixture(Member::class, 'admin'); |
61
|
|
|
/** @var \SilverStripe\Security\Member $siteOwner */ |
62
|
|
|
$siteOwner = $this->objFromFixture(Member::class, 'site-owner'); |
63
|
|
|
/** @var \SilverStripe\Security\Member $default */ |
64
|
|
|
$default = $this->objFromFixture(Member::class, 'default'); |
65
|
|
|
|
66
|
|
|
$this->assertFalse($object->canCreate($default)); |
67
|
|
|
$this->assertTrue($object->canCreate($admin)); |
68
|
|
|
$this->assertTrue($object->canCreate($siteOwner)); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* |
73
|
|
|
*/ |
74
|
|
|
public function testCanEdit() |
75
|
|
|
{ |
76
|
|
|
/** @var FoxyCategory $object */ |
77
|
|
|
$object = singleton(FoxyCategory::class); |
78
|
|
|
/** @var \SilverStripe\Security\Member $admin */ |
79
|
|
|
$admin = $this->objFromFixture(Member::class, 'admin'); |
80
|
|
|
/** @var \SilverStripe\Security\Member $siteOwner */ |
81
|
|
|
$siteOwner = $this->objFromFixture(Member::class, 'site-owner'); |
82
|
|
|
/** @var \SilverStripe\Security\Member $default */ |
83
|
|
|
$default = $this->objFromFixture(Member::class, 'default'); |
84
|
|
|
|
85
|
|
|
$this->assertFalse($object->canEdit($default)); |
86
|
|
|
$this->assertTrue($object->canEdit($admin)); |
87
|
|
|
$this->assertTrue($object->canEdit($siteOwner)); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* |
92
|
|
|
*/ |
93
|
|
|
public function testCanDelete() |
94
|
|
|
{ |
95
|
|
|
/** @var FoxyCategory $object */ |
96
|
|
|
$object = singleton(FoxyCategory::class); |
97
|
|
|
/** @var \SilverStripe\Security\Member $admin */ |
98
|
|
|
$admin = $this->objFromFixture(Member::class, 'admin'); |
99
|
|
|
/** @var \SilverStripe\Security\Member $siteOwner */ |
100
|
|
|
$siteOwner = $this->objFromFixture(Member::class, 'site-owner'); |
101
|
|
|
/** @var \SilverStripe\Security\Member $default */ |
102
|
|
|
$default = $this->objFromFixture(Member::class, 'default'); |
103
|
|
|
|
104
|
|
|
$this->assertFalse($object->canDelete($default)); |
105
|
|
|
$this->assertTrue($object->canDelete($admin)); |
106
|
|
|
$this->assertTrue($object->canDelete($siteOwner)); |
107
|
|
|
} |
108
|
|
|
} |
109
|
|
|
|
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.