Example #1
0
 public function testCanUpdateTask()
 {
     $date = new \DateTimeImmutable();
     $string = 'this is a description ' . microtime(true);
     $statement = $this->pdo->prepare('INSERT INTO task (description, dueDate) values (:description, :dueDate)');
     $statement->execute(array(':description' => $string, ':dueDate' => $date->format('Y-m-d H:i:s')));
     $id = $this->pdo->lastInsertId();
     $this->assertNotNull($id);
     $this->task->addSpecification(new TaskFutureDueDate());
     $taskExistSpecification = new TaskExists();
     $taskExistSpecification->setRepository($this->repository);
     $this->task->addSpecification($taskExistSpecification);
     $updateString = 'another description ' . microtime(true);
     $this->task->setId(new Id($id));
     $this->task->setDescription(new TaskDescription($updateString));
     $this->task->setDueDate($date);
     $this->task->setStatus(new Status(0));
     $this->task->setDeleted(new Status(1));
     $deletedDate = $this->task->getDeleteDate();
     $this->assertNotNull($deletedDate);
     $this->assertTrue($this->task->validate());
     $this->task->save();
     //fetch updated entry for testing
     $stmt = $this->pdo->prepare('SELECT * FROM task WHERE id = :id');
     $stmt->execute(array(':id' => $id));
     $updated = $stmt->fetch();
     $this->assertNotNull($updated);
     $this->assertEquals($updateString, $updated['description']);
     $this->assertEquals($date->format('Y-m-d H:i:s'), $updated['dueDate']);
     $this->assertEquals(0, $updated['status']);
     $this->assertEquals(1, $updated['deleted']);
     $this->assertEquals($deletedDate->format('Y-m-d H:i:s'), $updated['deletedDate']);
     //remove data
     $stmt = $this->pdo->prepare('DELETE FROM task WHERE id = :id');
     $stmt->execute(array(':id' => $id));
 }
Example #2
0
 public function changeTaskStatus(Request $request)
 {
     if ($request->isPost()) {
         $requestTask = $request->getData();
         if (!isset($requestTask->id)) {
             return $this->response(false, array('No id was specified.'));
         }
         $task = $this->getFactory()->buildTask();
         $taskExistsSpecification = new TaskExists();
         $taskExistsSpecification->setRepository($task->getRepository());
         $task->addSpecification($taskExistsSpecification);
         $task->addSpecification(new TaskHasValidStatus());
         $messageCollector = $task->getMessageCollector();
         $task->setId(new Id($requestTask->id));
         if (!isset($requestTask->status)) {
             return $this->response(false, array('No status was specified.'));
         } else {
             try {
                 $status = new Status($requestTask->status);
                 $task->setStatus($status);
             } catch (\Exception $ex) {
                 return $this->response(false, array('Invalid status was specified.'));
             }
         }
         if ($task->validate()) {
             $task->save();
             $messageCollector->pushMessage('Status changed.');
             return $this->response(true, $messageCollector->getMessages());
         } else {
             return $this->response(false, $task->getMessageCollector()->getErrors());
         }
     } else {
         return $this->response(false, array('Invalid request method used!'));
     }
 }