1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Dynamic\FlexSlider\Tests; |
4
|
|
|
|
5
|
|
|
use Dynamic\FlexSlider\Model\SlideImage; |
6
|
|
|
use SilverStripe\Core\Config\Config; |
7
|
|
|
use SilverStripe\Dev\SapphireTest; |
8
|
|
|
use SilverStripe\Forms\FieldList; |
9
|
|
|
use SilverStripe\ORM\ValidationException; |
10
|
|
|
use SilverStripe\Security\Member; |
11
|
|
|
|
12
|
|
|
class SlideImageTest extends SapphireTest |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* @var string |
16
|
|
|
*/ |
17
|
|
|
protected static $fixture_file = 'flexslider/tests/fixtures.yml'; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* |
21
|
|
|
*/ |
22
|
|
|
public function testGetCMSFields() |
23
|
|
|
{ |
24
|
|
|
$object = new SlideImage(); |
25
|
|
|
$fieldset = $object->getCMSFields(); |
26
|
|
|
$this->assertInstanceOf(FieldList::class, $fieldset); |
27
|
|
|
$this->assertNotNull($fieldset->dataFieldByName('Name')); |
|
|
|
|
28
|
|
|
$this->assertNotNull($fieldset->dataFieldByName('Image')); |
|
|
|
|
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* |
33
|
|
|
*/ |
34
|
|
View Code Duplication |
public function testValidateName() |
|
|
|
|
35
|
|
|
{ |
36
|
|
|
$object = $this->objFromFixture(SlideImage::class, 'slide1'); |
37
|
|
|
$object->Name = ''; |
38
|
|
|
$this->setExpectedException(ValidationException::class); |
|
|
|
|
39
|
|
|
$object->write(); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* |
44
|
|
|
*/ |
45
|
|
View Code Duplication |
public function testValidateImage() |
|
|
|
|
46
|
|
|
{ |
47
|
|
|
$object = $this->objFromFixture(SlideImage::class, 'slide1'); |
48
|
|
|
$object->ImageID = ''; |
49
|
|
|
$this->setExpectedException(ValidationException::class); |
|
|
|
|
50
|
|
|
$object->write(); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* |
55
|
|
|
*/ |
56
|
|
|
public function testProvidePermissions() |
57
|
|
|
{ |
58
|
|
|
$object = singleton(SlideImage::class); |
59
|
|
|
$expected = array( |
60
|
|
|
'Slide_EDIT' => 'Slide Edit', |
61
|
|
|
'Slide_DELETE' => 'Slide Delete', |
62
|
|
|
'Slide_CREATE' => 'Slide Create', |
63
|
|
|
); |
64
|
|
|
$this->assertEquals($expected, $object->providePermissions()); |
|
|
|
|
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* |
69
|
|
|
*/ |
70
|
|
View Code Duplication |
public function testCanCreate() |
|
|
|
|
71
|
|
|
{ |
72
|
|
|
$object = $this->objFromFixture(SlideImage::class, 'slide1'); |
73
|
|
|
$admin = $this->objFromFixture(Member::class, 'admin'); |
74
|
|
|
$this->assertTrue($object->canCreate($admin)); |
|
|
|
|
75
|
|
|
|
76
|
|
|
$author = $this->objFromFixture(Member::class, 'author'); |
77
|
|
|
$this->assertTrue($object->canCreate($author)); |
|
|
|
|
78
|
|
|
|
79
|
|
|
$member = $this->objFromFixture(Member::class, 'default'); |
80
|
|
|
$this->assertFalse($object->canCreate($member)); |
|
|
|
|
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* |
85
|
|
|
*/ |
86
|
|
View Code Duplication |
public function testCanEdit() |
|
|
|
|
87
|
|
|
{ |
88
|
|
|
$object = $this->objFromFixture(SlideImage::class, 'slide1'); |
89
|
|
|
$admin = $this->objFromFixture(Member::class, 'admin'); |
90
|
|
|
$this->assertTrue($object->canEdit($admin)); |
|
|
|
|
91
|
|
|
|
92
|
|
|
$author = $this->objFromFixture(Member::class, 'author'); |
93
|
|
|
$this->assertTrue($object->canEdit($author)); |
|
|
|
|
94
|
|
|
|
95
|
|
|
$member = $this->objFromFixture(Member::class, 'default'); |
96
|
|
|
$this->assertFalse($object->canEdit($member)); |
|
|
|
|
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* |
101
|
|
|
*/ |
102
|
|
View Code Duplication |
public function testCanDelete() |
|
|
|
|
103
|
|
|
{ |
104
|
|
|
$object = $this->objFromFixture(SlideImage::class, 'slide1'); |
105
|
|
|
$admin = $this->objFromFixture(Member::class, 'admin'); |
106
|
|
|
$this->assertTrue($object->canDelete($admin)); |
|
|
|
|
107
|
|
|
|
108
|
|
|
$author = $this->objFromFixture(Member::class, 'author'); |
109
|
|
|
$this->assertTrue($object->canDelete($author)); |
|
|
|
|
110
|
|
|
|
111
|
|
|
$member = $this->objFromFixture(Member::class, 'default'); |
112
|
|
|
$this->assertFalse($object->canDelete($member)); |
|
|
|
|
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* |
117
|
|
|
*/ |
118
|
|
View Code Duplication |
public function testCanView() |
|
|
|
|
119
|
|
|
{ |
120
|
|
|
$object = $this->objFromFixture(SlideImage::class, 'slide1'); |
121
|
|
|
$admin = $this->objFromFixture(Member::class, 'admin'); |
122
|
|
|
$this->assertTrue($object->canView($admin)); |
|
|
|
|
123
|
|
|
|
124
|
|
|
$author = $this->objFromFixture(Member::class, 'author'); |
125
|
|
|
$this->assertTrue($object->canView($author)); |
|
|
|
|
126
|
|
|
|
127
|
|
|
$member = $this->objFromFixture(Member::class, 'default'); |
128
|
|
|
$this->assertTrue($object->canView($member)); |
|
|
|
|
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* |
133
|
|
|
*/ |
134
|
|
|
public function testImageSizeLimit() |
135
|
|
|
{ |
136
|
|
|
$default = 512000; |
137
|
|
|
$this->assertEquals(Config::modify()->get(SlideImage::class, 'image_size_limit'), $default); |
|
|
|
|
138
|
|
|
|
139
|
|
|
$new = 1024000; |
140
|
|
|
Config::modify()->update(SlideImage::class , 'image_size_limit', $new); |
141
|
|
|
$this->assertEquals(Config::modify()->get(SlideImage::class, 'image_size_limit'), $new); |
|
|
|
|
142
|
|
|
} |
143
|
|
|
} |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.