1 | <?php |
||||
2 | |||||
3 | namespace Dynamic\FlexSlider\Test; |
||||
4 | |||||
5 | use Dynamic\FlexSlider\Model\SlideImage; |
||||
6 | use Sheadawson\Linkable\Forms\EmbeddedObjectField; |
||||
7 | use SilverStripe\AssetAdmin\Forms\UploadField; |
||||
8 | use SilverStripe\Core\Config\Config; |
||||
9 | use SilverStripe\Dev\SapphireTest; |
||||
10 | use SilverStripe\Forms\FieldList; |
||||
11 | use SilverStripe\Forms\TextareaField; |
||||
12 | use SilverStripe\Forms\TextField; |
||||
13 | use SilverStripe\ORM\FieldType\DBHTMLText; |
||||
14 | use SilverStripe\ORM\ValidationException; |
||||
15 | use SilverStripe\Security\Member; |
||||
16 | |||||
17 | /** |
||||
18 | * Class SlideImageTest |
||||
19 | * @package Dynamic\FlexSlider\Test |
||||
20 | */ |
||||
21 | class SlideImageTest extends SapphireTest |
||||
22 | { |
||||
23 | /** |
||||
24 | * @var string |
||||
25 | */ |
||||
26 | protected static $fixture_file = 'fixtures.yml'; |
||||
27 | |||||
28 | /** |
||||
29 | * |
||||
30 | */ |
||||
31 | public function testGetCMSFields() |
||||
32 | { |
||||
33 | $object = SlideImage::singleton(); |
||||
34 | $fields = $object->getCMSFields(); |
||||
35 | |||||
36 | $this->assertInstanceOf(FieldList::class, $fields); |
||||
37 | $this->assertInstanceOf(TextField::class, $fields->dataFieldByName('Name')); |
||||
38 | $this->assertInstanceOf(UploadField::class, $fields->dataFieldByName('Image')); |
||||
39 | $this->assertInstanceOf(EmbeddedObjectField::class, $fields->dataFieldByName('Video')); |
||||
40 | $this->assertInstanceOf(TextareaField::class, $fields->dataFieldByName('Description')); |
||||
41 | } |
||||
42 | |||||
43 | /** |
||||
44 | * @throws ValidationException |
||||
45 | */ |
||||
46 | public function testValidateName() |
||||
47 | { |
||||
48 | $object = $this->objFromFixture(SlideImage::class, 'slide1'); |
||||
49 | $object->Name = ''; |
||||
50 | $object->ImageID = 1; |
||||
51 | $this->setExpectedException(ValidationException::class); |
||||
0 ignored issues
–
show
|
|||||
52 | $object->write(); |
||||
53 | |||||
54 | $object->Name = 'Foo'; |
||||
55 | $this->assertGreaterThan(0, $object->write()); |
||||
56 | } |
||||
57 | |||||
58 | /** |
||||
59 | * @throws ValidationException |
||||
60 | */ |
||||
61 | public function testValidateImage() |
||||
62 | { |
||||
63 | $object = $this->objFromFixture(SlideImage::class, 'slide1'); |
||||
64 | $object->ImageID = null; |
||||
65 | $this->setExpectedException(ValidationException::class); |
||||
0 ignored issues
–
show
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
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 | $base->ImageID = 1; |
||||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||||
69 | $this->assertGreaterThan(0, $object->write()); |
||||
70 | } |
||||
71 | |||||
72 | /** |
||||
73 | * @throws ValidationException |
||||
74 | */ |
||||
75 | public function testValidateVideo() |
||||
76 | { |
||||
77 | $object = $this->objFromFixture(SlideImage::class, 'slide2'); |
||||
78 | $object->VideoID = null; |
||||
79 | $this->setExpectedException(ValidationException::class); |
||||
0 ignored issues
–
show
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
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...
|
|||||
80 | $object->write(); |
||||
81 | |||||
82 | $object->VideoID = 1; |
||||
83 | $this->assertGreaterThan(0, $object->write()); |
||||
84 | } |
||||
85 | |||||
86 | /** |
||||
87 | * @throws ValidationException |
||||
88 | */ |
||||
89 | public function testValidateText() |
||||
90 | { |
||||
91 | $object = $this->objFromFixture(SlideImage::class, 'slide3'); |
||||
92 | $description = $object->Description; |
||||
93 | |||||
94 | $object->Description = null; |
||||
95 | $this->setExpectedException(ValidationException::class); |
||||
0 ignored issues
–
show
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
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...
|
|||||
96 | $object->write(); |
||||
97 | |||||
98 | $object->Description = $description; |
||||
99 | $this->assertGreaterThan(0, $object->write()); |
||||
100 | } |
||||
101 | |||||
102 | /** |
||||
103 | * |
||||
104 | */ |
||||
105 | public function testProvidePermissions() |
||||
106 | { |
||||
107 | $object = SlideImage::singleton(); |
||||
108 | |||||
109 | $expected = [ |
||||
110 | 'Slide_EDIT' => 'Slide Edit', |
||||
111 | 'Slide_DELETE' => 'Slide Delete', |
||||
112 | 'Slide_CREATE' => 'Slide Create', |
||||
113 | ]; |
||||
114 | |||||
115 | $this->assertEquals($expected, $object->providePermissions()); |
||||
116 | } |
||||
117 | |||||
118 | /** |
||||
119 | * |
||||
120 | */ |
||||
121 | public function testCanCreate() |
||||
122 | { |
||||
123 | $object = $this->objFromFixture(SlideImage::class, 'slide1'); |
||||
124 | $admin = $this->objFromFixture(Member::class, 'admin'); |
||||
125 | $this->assertTrue($object->canCreate($admin)); |
||||
126 | |||||
127 | $author = $this->objFromFixture(Member::class, 'author'); |
||||
128 | $this->assertTrue($object->canCreate($author)); |
||||
129 | |||||
130 | $member = $this->objFromFixture(Member::class, 'default'); |
||||
131 | $this->assertFalse($object->canCreate($member)); |
||||
132 | } |
||||
133 | |||||
134 | /** |
||||
135 | * |
||||
136 | */ |
||||
137 | public function testCanEdit() |
||||
138 | { |
||||
139 | $object = $this->objFromFixture(SlideImage::class, 'slide1'); |
||||
140 | $admin = $this->objFromFixture(Member::class, 'admin'); |
||||
141 | $this->assertTrue($object->canEdit($admin)); |
||||
142 | |||||
143 | $author = $this->objFromFixture(Member::class, 'author'); |
||||
144 | $this->assertTrue($object->canEdit($author)); |
||||
145 | |||||
146 | $member = $this->objFromFixture(Member::class, 'default'); |
||||
147 | $this->assertFalse($object->canEdit($member)); |
||||
148 | } |
||||
149 | |||||
150 | /** |
||||
151 | * |
||||
152 | */ |
||||
153 | public function testCanDelete() |
||||
154 | { |
||||
155 | $object = $this->objFromFixture(SlideImage::class, 'slide1'); |
||||
156 | $admin = $this->objFromFixture(Member::class, 'admin'); |
||||
157 | $this->assertTrue($object->canDelete($admin)); |
||||
158 | |||||
159 | $author = $this->objFromFixture(Member::class, 'author'); |
||||
160 | $this->assertTrue($object->canDelete($author)); |
||||
161 | |||||
162 | $member = $this->objFromFixture(Member::class, 'default'); |
||||
163 | $this->assertFalse($object->canDelete($member)); |
||||
164 | } |
||||
165 | |||||
166 | /** |
||||
167 | * |
||||
168 | */ |
||||
169 | public function testCanView() |
||||
170 | { |
||||
171 | $object = $this->objFromFixture(SlideImage::class, 'slide1'); |
||||
172 | $admin = $this->objFromFixture(Member::class, 'admin'); |
||||
173 | $this->assertTrue($object->canView($admin)); |
||||
174 | |||||
175 | $author = $this->objFromFixture(Member::class, 'author'); |
||||
176 | $this->assertTrue($object->canView($author)); |
||||
177 | |||||
178 | $member = $this->objFromFixture(Member::class, 'default'); |
||||
179 | $this->assertTrue($object->canView($member)); |
||||
180 | } |
||||
181 | |||||
182 | /** |
||||
183 | * |
||||
184 | */ |
||||
185 | public function testImageSizeLimit() |
||||
186 | { |
||||
187 | $default = 512000; |
||||
188 | $this->assertEquals(Config::modify()->get(SlideImage::class, 'image_size_limit'), $default); |
||||
189 | |||||
190 | $new = 1024000; |
||||
191 | Config::modify()->update(SlideImage::class, 'image_size_limit', $new); |
||||
192 | $this->assertEquals(Config::modify()->get(SlideImage::class, 'image_size_limit'), $new); |
||||
193 | } |
||||
194 | |||||
195 | /** |
||||
196 | * |
||||
197 | */ |
||||
198 | public function testRenderWith() |
||||
199 | { |
||||
200 | $this->markTestSkipped("Todo SlideImageText::testRenderWith()"); |
||||
201 | //$slide = SlideImage::singleton(); |
||||
202 | |||||
203 | //$this->assertInstanceOf(DBHTMLText::class, $slide->renderWith()); |
||||
204 | } |
||||
205 | |||||
206 | /** |
||||
207 | * |
||||
208 | */ |
||||
209 | public function testForTemplate() |
||||
210 | { |
||||
211 | $this->markTestSkipped("Todo SlideImageText::testForTemplate()"); |
||||
212 | //$slide = SlideImage::singleton(); |
||||
213 | |||||
214 | //$this->assertInstanceOf(DBHTMLText::class, $slide->forTemplate()); |
||||
215 | } |
||||
216 | } |
||||
217 |
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.