parent
6c0ae1f28a
commit
af17da7ecc
|
@ -27,6 +27,8 @@ class BlogCategory extends DataObject implements CategorisationObject
|
||||||
*/
|
*/
|
||||||
const DUPLICATE_EXCEPTION = 'DUPLICATE';
|
const DUPLICATE_EXCEPTION = 'DUPLICATE';
|
||||||
|
|
||||||
|
const EMPTY_TITLE_EXCEPTION = 'EMPTY_TITLE';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
* @var string
|
* @var string
|
||||||
|
|
|
@ -72,6 +72,10 @@ trait BlogObject
|
||||||
$validation->addError($this->getDuplicateError(), self::DUPLICATE_EXCEPTION);
|
$validation->addError($this->getDuplicateError(), self::DUPLICATE_EXCEPTION);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(empty($this->Title)) {
|
||||||
|
$validation->addError($this->getEmptyTitleError(), self::EMPTY_TITLE_EXCEPTION);
|
||||||
|
}
|
||||||
|
|
||||||
return $validation;
|
return $validation;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -244,4 +248,14 @@ trait BlogObject
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
abstract protected function getDuplicateError();
|
abstract protected function getDuplicateError();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns an error message for this object when it tries to write with an empty title.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
protected function getEmptyTitleError()
|
||||||
|
{
|
||||||
|
return _t(__CLASS__ . '.EmptyTitle', 'Title must not be empty');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,6 +27,8 @@ class BlogTag extends DataObject implements CategorisationObject
|
||||||
*/
|
*/
|
||||||
const DUPLICATE_EXCEPTION = 'DUPLICATE';
|
const DUPLICATE_EXCEPTION = 'DUPLICATE';
|
||||||
|
|
||||||
|
const EMPTY_TITLE_EXCEPTION = 'EMPTY_TITLE';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
* @var string
|
* @var string
|
||||||
|
|
|
@ -167,4 +167,23 @@ class BlogCategoryTest extends FunctionalTest
|
||||||
$this->assertEquals(BlogTag::DUPLICATE_EXCEPTION, $messages[0]['messageType']);
|
$this->assertEquals(BlogTag::DUPLICATE_EXCEPTION, $messages[0]['messageType']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testEmptyTitle()
|
||||||
|
{
|
||||||
|
$blog = $this->objFromFixture(Blog::class, 'FirstBlog');
|
||||||
|
|
||||||
|
$category = new BlogCategory();
|
||||||
|
$category->Title = '';
|
||||||
|
$category->BlogID = $blog->ID;
|
||||||
|
$category->URLSegment = 'test';
|
||||||
|
|
||||||
|
try {
|
||||||
|
$category->write();
|
||||||
|
$this->fail('BlogCategory with empty title is written');
|
||||||
|
} catch (ValidationException $e) {
|
||||||
|
$messages = $e->getResult()->getMessages();
|
||||||
|
$this->assertCount(1, $messages);
|
||||||
|
$this->assertEquals(BlogCategory::EMPTY_TITLE_EXCEPTION, $messages[0]['messageType']);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -195,4 +195,23 @@ class BlogTagTest extends FunctionalTest
|
||||||
$tag->write();
|
$tag->write();
|
||||||
$this->assertEquals($tag->URLSegment, "another-test");
|
$this->assertEquals($tag->URLSegment, "another-test");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testEmptyTitle()
|
||||||
|
{
|
||||||
|
$blog = $this->objFromFixture(Blog::class, 'FirstBlog');
|
||||||
|
|
||||||
|
$tag = new BlogTag();
|
||||||
|
$tag->Title = '';
|
||||||
|
$tag->BlogID = $blog->ID;
|
||||||
|
$tag->URLSegment = 'test';
|
||||||
|
|
||||||
|
try {
|
||||||
|
$tag->write();
|
||||||
|
$this->fail('BlogTag with empty title is written');
|
||||||
|
} catch (ValidationException $e) {
|
||||||
|
$messages = $e->getResult()->getMessages();
|
||||||
|
$this->assertCount(1, $messages);
|
||||||
|
$this->assertEquals(BlogTag::EMPTY_TITLE_EXCEPTION, $messages[0]['messageType']);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue