fix #22 tag & project validation

This commit is contained in:
DavidBadura 2015-06-28 13:34:51 +00:00
parent fb763a765e
commit 0a0a4f9788
2 changed files with 24 additions and 0 deletions

View File

@ -21,6 +21,8 @@ use JMS\Serializer\SerializerBuilder;
*/
class TaskManager
{
const PATTERN = '/^[\wäüö]*$/i';
/**
* @var Taskwarrior
*/
@ -216,6 +218,16 @@ class TaskManager
$errors[] = "A recurring task must also have a 'due' date.";
}
if (!preg_match(static::PATTERN, $task->getProject())) {
$errors[] = sprintf("Project with the name '%s' is not allowed", $task->getProject());
}
foreach ($task->getTags() as $tag) {
if (!preg_match(static::PATTERN, $tag)) {
$errors[] = sprintf("Tag with the name '%s' is not allowed", $tag);
}
}
return $errors;
}

View File

@ -549,6 +549,18 @@ class TaskManagerTest extends \PHPUnit_Framework_TestCase
$this->assertCount(1,$this->taskManager->filterPending('+später'));
}
public function testTagNameNotAllowed()
{
$this->setExpectedException('DavidBadura\Taskwarrior\Exception\TaskwarriorException',
"Tag with the name 'foo-bar' is not allowed");
$task1 = new Task();
$task1->setDescription('foo1');
$task1->addTag('foo-bar');
$this->taskManager->save($task1);
}
public function testWait()
{
$task1 = new Task();