1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Dynamic\DynamicBlocks\Test; |
4
|
|
|
|
5
|
|
|
use Dynamic\DynamicBlocks\Model\PhotoGalleryBlockImage; |
6
|
|
|
use SilverStripe\Dev\SapphireTest; |
7
|
|
|
use SilverStripe\Forms\FieldList; |
8
|
|
|
use SilverStripe\Security\Member; |
9
|
|
|
|
10
|
|
|
class PhotoGalleryBlockImageTest extends SapphireTest |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* @var string |
14
|
|
|
*/ |
15
|
|
|
protected static $fixture_file = 'dynamic-blocks/tests/Fixtures.yml'; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* |
19
|
|
|
*/ |
20
|
|
|
public function testGetCMSFields() |
21
|
|
|
{ |
22
|
|
|
$object = $this->objFromFixture(PhotoGalleryBlockImage::class, 'one'); |
23
|
|
|
$fields = $object->getCMSFields(); |
24
|
|
|
$this->assertInstanceOf(FieldList::class, $fields); |
25
|
|
|
$this->assertNull($fields->dataFieldByName('PhotoGalleryID')); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* |
30
|
|
|
*/ |
31
|
|
|
public function testCanView() |
32
|
|
|
{ |
33
|
|
|
$object = $this->objFromFixture(PhotoGalleryBlockImage::class, 'one'); |
34
|
|
|
$admin = $this->objFromFixture(Member::class, 'admin'); |
35
|
|
|
$this->assertTrue($object->canView($admin)); |
|
|
|
|
36
|
|
|
$member = $this->objFromFixture(Member::class, 'default'); |
37
|
|
|
$this->assertTrue($object->canView($member)); |
|
|
|
|
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* |
42
|
|
|
*/ |
43
|
|
|
public function testCanEdit() |
44
|
|
|
{ |
45
|
|
|
$object = $this->objFromFixture(PhotoGalleryBlockImage::class, 'one'); |
46
|
|
|
$admin = $this->objFromFixture(Member::class, 'admin'); |
47
|
|
|
$this->assertTrue($object->canEdit($admin)); |
|
|
|
|
48
|
|
|
$member = $this->objFromFixture(Member::class, 'default'); |
49
|
|
|
$this->assertTrue($object->canEdit($member)); |
|
|
|
|
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* |
54
|
|
|
*/ |
55
|
|
|
public function testCanDelete() |
56
|
|
|
{ |
57
|
|
|
$object = $this->objFromFixture(PhotoGalleryBlockImage::class, 'one'); |
58
|
|
|
$admin = $this->objFromFixture(Member::class, 'admin'); |
59
|
|
|
$this->assertTrue($object->canDelete($admin)); |
|
|
|
|
60
|
|
|
$member = $this->objFromFixture(Member::class, 'default'); |
61
|
|
|
$this->assertTrue($object->canDelete($member)); |
|
|
|
|
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* |
66
|
|
|
*/ |
67
|
|
|
public function testCanCreate() |
68
|
|
|
{ |
69
|
|
|
$object = $this->objFromFixture(PhotoGalleryBlockImage::class, 'one'); |
70
|
|
|
$admin = $this->objFromFixture(Member::class, 'admin'); |
71
|
|
|
$this->assertTrue($object->canCreate($admin)); |
|
|
|
|
72
|
|
|
$member = $this->objFromFixture(Member::class, 'default'); |
73
|
|
|
$this->assertTrue($object->canCreate($member)); |
|
|
|
|
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.