File tree 5 files changed +56
-0
lines changed
5 files changed +56
-0
lines changed Original file line number Diff line number Diff line change @@ -27,6 +27,8 @@ class BlogCategory extends DataObject implements CategorisationObject
27
27
*/
28
28
const DUPLICATE_EXCEPTION = 'DUPLICATE ' ;
29
29
30
+ const EMPTY_TITLE_EXCEPTION = 'EMPTY_TITLE ' ;
31
+
30
32
/**
31
33
* {@inheritDoc}
32
34
* @var string
Original file line number Diff line number Diff line change @@ -72,6 +72,10 @@ public function validate()
72
72
$ validation ->addError ($ this ->getDuplicateError (), self ::DUPLICATE_EXCEPTION );
73
73
}
74
74
75
+ if (empty ($ this ->Title )) {
76
+ $ validation ->addError ($ this ->getEmptyTitleError (), self ::EMPTY_TITLE_EXCEPTION );
77
+ }
78
+
75
79
return $ validation ;
76
80
}
77
81
@@ -244,4 +248,14 @@ abstract protected function getListUrlSegment();
244
248
* @return string
245
249
*/
246
250
abstract protected function getDuplicateError ();
251
+
252
+ /**
253
+ * Returns an error message for this object when it tries to write with an empty title.
254
+ *
255
+ * @return string
256
+ */
257
+ protected function getEmptyTitleError ()
258
+ {
259
+ return _t (__CLASS__ . '.EmptyTitle ' , 'Title must not be empty ' );
260
+ }
247
261
}
Original file line number Diff line number Diff line change @@ -27,6 +27,8 @@ class BlogTag extends DataObject implements CategorisationObject
27
27
*/
28
28
const DUPLICATE_EXCEPTION = 'DUPLICATE ' ;
29
29
30
+ const EMPTY_TITLE_EXCEPTION = 'EMPTY_TITLE ' ;
31
+
30
32
/**
31
33
* {@inheritDoc}
32
34
* @var string
Original file line number Diff line number Diff line change @@ -167,4 +167,23 @@ public function testDuplicateCategories()
167
167
$ this ->assertEquals (BlogTag::DUPLICATE_EXCEPTION , $ messages [0 ]['messageType ' ]);
168
168
}
169
169
}
170
+
171
+ public function testEmptyTitle ()
172
+ {
173
+ $ blog = $ this ->objFromFixture (Blog::class, 'FirstBlog ' );
174
+
175
+ $ category = new BlogCategory ();
176
+ $ category ->Title = '' ;
177
+ $ category ->BlogID = $ blog ->ID ;
178
+ $ category ->URLSegment = 'test ' ;
179
+
180
+ try {
181
+ $ category ->write ();
182
+ $ this ->fail ('BlogCategory with empty title is written ' );
183
+ } catch (ValidationException $ e ) {
184
+ $ messages = $ e ->getResult ()->getMessages ();
185
+ $ this ->assertCount (1 , $ messages );
186
+ $ this ->assertEquals (BlogCategory::EMPTY_TITLE_EXCEPTION , $ messages [0 ]['messageType ' ]);
187
+ }
188
+ }
170
189
}
Original file line number Diff line number Diff line change @@ -195,4 +195,23 @@ public function testBlogTagUrlSegmentsAreAutomaticallyUpdated()
195
195
$ tag ->write ();
196
196
$ this ->assertEquals ($ tag ->URLSegment , "another-test " );
197
197
}
198
+
199
+ public function testEmptyTitle ()
200
+ {
201
+ $ blog = $ this ->objFromFixture (Blog::class, 'FirstBlog ' );
202
+
203
+ $ tag = new BlogTag ();
204
+ $ tag ->Title = '' ;
205
+ $ tag ->BlogID = $ blog ->ID ;
206
+ $ tag ->URLSegment = 'test ' ;
207
+
208
+ try {
209
+ $ tag ->write ();
210
+ $ this ->fail ('BlogTag with empty title is written ' );
211
+ } catch (ValidationException $ e ) {
212
+ $ messages = $ e ->getResult ()->getMessages ();
213
+ $ this ->assertCount (1 , $ messages );
214
+ $ this ->assertEquals (BlogTag::EMPTY_TITLE_EXCEPTION , $ messages [0 ]['messageType ' ]);
215
+ }
216
+ }
198
217
}
You can’t perform that action at this time.
0 commit comments