public function testSimpleUserImportWhereAllRowsSucceed() { Yii::app()->user->userModel = User::getByUsername('super'); $tasks = Task::getAll(); $this->assertEquals(0, count($tasks)); $import = new Import(); $serializedData['importRulesType'] = 'Tasks'; $serializedData['firstRowIsHeaderRow'] = true; $import->serializedData = serialize($serializedData); $this->assertTrue($import->save()); ImportTestHelper::createTempTableByFileNameAndTableName('simpleImportTest.csv', $import->getTempTableName(), Yii::getPathOfAlias('application.modules.tasks.tests.unit.files')); $this->assertEquals(4, ImportDatabaseUtil::getCount($import->getTempTableName())); // includes header rows. $mappingData = array('column_0' => ImportMappingUtil::makeStringColumnMappingData('name'), 'column_1' => ImportMappingUtil::makeDateTimeColumnMappingData('dueDateTime'), 'column_2' => ImportMappingUtil::makeDateTimeColumnMappingData('completedDateTime'), 'column_3' => ImportMappingUtil::makeBooleanColumnMappingData('completed'), 'column_4' => ImportMappingUtil::makeModelDerivedColumnMappingData('AccountDerived'), 'column_5' => ImportMappingUtil::makeModelDerivedColumnMappingData('ContactDerived'), 'column_6' => ImportMappingUtil::makeModelDerivedColumnMappingData('OpportunityDerived'), 'column_7' => ImportMappingUtil::makeTextAreaColumnMappingData('description')); $importRules = ImportRulesUtil::makeImportRulesByType('Tasks'); $page = 0; $config = array('pagination' => array('pageSize' => 50)); //This way all rows are processed. $dataProvider = new ImportDataProvider($import->getTempTableName(), true, $config); $dataProvider->getPagination()->setCurrentPage($page); $importResultsUtil = new ImportResultsUtil($import); $actionDateTime = substr(DateTimeUtil::convertTimestampToDbFormatDateTime(time()), 0, -3); $messageLogger = new ImportMessageLogger(); ImportUtil::importByDataProvider($dataProvider, $importRules, $mappingData, $importResultsUtil, new ExplicitReadWriteModelPermissions(), $messageLogger); $importResultsUtil->processStatusAndMessagesForEachRow(); //Confirm that 3 models where created. $tasks = Task::getAll(); $this->assertEquals(3, count($tasks)); $tasks = Task::getByName('task1'); $this->assertEquals(1, count($tasks[0])); $this->assertEquals(1, count($tasks[0]->activityItems)); $this->assertEquals('testAccount', $tasks[0]->activityItems[0]->name); $this->assertEquals('Account', get_class($tasks[0]->activityItems[0])); $this->assertNull($tasks[0]->completed); $this->assertEquals($actionDateTime, substr($tasks[0]->latestDateTime, 0, -3)); $tasks = Task::getByName('task2'); $this->assertEquals(1, count($tasks[0])); $this->assertEquals(1, count($tasks[0]->activityItems)); $this->assertEquals('testContact', $tasks[0]->activityItems[0]->firstName); $this->assertEquals('Contact', get_class($tasks[0]->activityItems[0])); $this->assertEquals(1, $tasks[0]->completed); $this->assertEquals('2011-12-22 06:03', substr($tasks[0]->latestDateTime, 0, -3)); $tasks = Task::getByName('task3'); $this->assertEquals(1, count($tasks[0])); $this->assertEquals(1, count($tasks[0]->activityItems)); $this->assertEquals('testOpportunity', $tasks[0]->activityItems[0]->name); $this->assertEquals('Opportunity', get_class($tasks[0]->activityItems[0])); $this->assertNull($tasks[0]->completed); $this->assertEquals($actionDateTime, substr($tasks[0]->latestDateTime, 0, -3)); //Confirm 10 rows were processed as 'created'. $this->assertEquals(3, ImportDatabaseUtil::getCount($import->getTempTableName(), "status = " . ImportRowDataResultsUtil::CREATED)); //Confirm that 0 rows were processed as 'updated'. $this->assertEquals(0, ImportDatabaseUtil::getCount($import->getTempTableName(), "status = " . ImportRowDataResultsUtil::UPDATED)); //Confirm 2 rows were processed as 'errors'. $this->assertEquals(0, ImportDatabaseUtil::getCount($import->getTempTableName(), "status = " . ImportRowDataResultsUtil::ERROR)); $beansWithErrors = ImportDatabaseUtil::getSubset($import->getTempTableName(), "status = " . ImportRowDataResultsUtil::ERROR); $this->assertEquals(0, count($beansWithErrors)); }
static function find($search_id) { $found_task = null; $tasks = Task::getAll(); foreach ($tasks as $task) { $task_id = $task->getId(); if ($task_id == $search_id) { $found_task = $task; } } return $found_task; }
function test_deleteAll() { $description = "Wash the dog"; $description2 = "Water the lawn"; $test_Task = new Task($description); $test_Task->save(); $test_Task2 = new Task($description2); $test_Task2->save(); Task::deleteAll(); $result = Task::getAll(); $this->assertEquals([], $result); }
function test_getAll() { //Arrange $description = "Wash the dog"; $description2 = "Water the lawn"; $test_task = new Task($description); $test_task->save(); $test_task2 = new Task($description2); $test_task2->save(); //Act $result = Task::getAll(); //Assert $this->assertEquals([$test_task, $test_task2], $result); }
function test_save() { //Arrange $name = "Home stuff"; $id = null; $test_category = new Category($name, $id); $test_category->save(); $due_date = "2015-10-12"; $description = "Wash the dog"; $category_id = $test_category->getId(); $test_task = new Task($description, $due_date, $id, $category_id); //Act $test_task->save(); //Assert $result = Task::getAll(); var_dump($result); $this->assertEquals($test_task, $result[0]); }
function test_deleteAll() { //Arrange $description = "Wash the dog"; $due_date = '2015-01-01'; $id = 1; $test_task = new Task($description, $id, $due_date); $test_task->save(); $description2 = "Water the lawn"; $id2 = 2; $due_date = '2015-01-02'; $test_task2 = new Task($description2, $id, $due_date); $test_task2->save(); //Act Task::deleteAll(); //Asser $result = Task::getAll(); $this->assertEquals([], $result); }
function test_deleteAll() { // Arrange $name = "Home stuff"; $id = null; $test_category = new Category($name, $id); $description = "Wash the dog"; $category_id = $test_category->getId(); $test_task = new Task($description, $id, $category_id); $test_task->save(); $description2 = "Water the lawn"; $test_task2 = new Task($description2, $id, $category_id); $test_task2->save(); // Act Task::deleteAll(); // Assert $result = Task::getAll(); $this->assertEquals([], $result); }
function test_deleteAll() { $name = "Home stuff"; $id = null; $test_category = new Category($name, $id); $test_category->save(); $description = "Wash the dog"; $date_due = "9/25/1990"; $time_due = "9:00am"; $category_id = $test_category->getId(); $test_task = new Task($id, $description, $date_due, $time_due, $category_id); $test_task->save(); $description2 = "Water the Lawn"; $date_due2 = "3/28/2000"; $time_due2 = "10:00am"; $test_task2 = new Task($id, $description2, $date_due2, $time_due2, $category_id); $test_task2->save(); Task::deleteAll(); $result = Task::getAll(); $this->assertEquals([], $result); }
// Copyright 2008 - 2010 all rights reserved, SQLFusion LLC, info@sqlfusion.com /** Ofuz Open Source version is released under the GNU Affero General Public License, please read the full license at: http://www.gnu.org/licenses/agpl-3.0.html **/ $pageTitle = 'Ofuz'; $Author = 'SQLFusion LLC'; $Keywords = 'Keywords for search engine'; $Description = 'Description for search engine'; $background_color = 'white'; include_once 'config.php'; include_once 'includes/ofuz_check_access.script.inc.php'; include_once 'includes/header.inc.php'; // $do_notes = new ContactNotes($GLOBALS['conx']); // $do_contact = new Contact($GLOBALS['conx']); // $do_company = new Company($GLOBALS['conx']); // $do_task = new Task($GLOBALS['conx']); // $do_task_category = new TaskCategory($GLOBALS['conx']); // $do_contact_task = new Contact(); // $do_notes->sessionPersistent("ContactNotesEditSave", "index.php", 3600); $tmp_task = new Task(); $tmp_task_cat = new TaskCategory(); $tmp_task_update = new Task(); $tmp_task->getAll(); while ($tmp_task->next()) { if ($tmp_task->category) { $category = $tmp_task_cat->getTaskCategoryName($tmp_task->category); $tmp_task_update->tmpUpdateTaskCat($tmp_task->idtask, $category); } } ?> Hello </body> </html>
function testDeleteTask() { //Arrange $id = 1; $description = "Wash the dog"; $date_due = "1990-12-11"; $time_due = "09:00:00"; $test_task = new Task($id, $description, $date_due, $time_due); $test_task->save(); $id2 = 2; $description2 = "Water the lawn"; $date_due2 = "1990-11-11"; $time_due2 = "09:01:00"; $test_task2 = new Task($id2, $description2, $date_due2, $time_due2); $test_task2->save(); //Act $test_task->delete(); //Assert $this->assertEquals([$test_task2], Task::getAll()); }
public function checkTasks() { TaskRunner::checkAndRunTasks(Task::getAll()); }
/** * gets documentation sub tasks and folders of a task * */ public static function getDocuTasks($project_id, $parent_task_id = NULL) { $tasks = array(); $tmp_options = array('use_collapsed' => true, 'order_by' => 'order_id, i.id', 'parent_task' => $parent_task_id, 'status_min' => 0, 'status_max' => 100, 'project' => $project_id, 'category_in' => array(TCATEGORY_DOCU, TCATEGORY_FOLDER)); foreach ($pages = Task::getAll($tmp_options) as $p) { ### filter only folders with docu ### if ($p->category == TCATEGORY_FOLDER) { $found_docu = $p->show_folder_as_documentation; foreach ($subtasks = $p->getSubtasksRecursive() as $subtask) { if ($subtask->category == TCATEGORY_DOCU) { $found_docu = true; break; } } if ($found_docu) { $tasks[] = $p; } } else { $tasks[] = $p; } } return $tasks; }
/** * print a complete list as html * - use filters * - use check list style (tree, list, grouped) * - check customization-values * - check sorting * - get objects from database * */ public function print_automatic() { require_once confGet('DIR_STREBER') . 'render/render_wiki.inc.php'; global $PH; if (!($this->active_block_function = $this->getBlockStyleFromCookie())) { $this->active_block_function = 'list'; } $this->initOrderQueryOption(); ### grouped view ### if ($this->active_block_function == 'grouped') { $this->group_by = get("blockstyle_{$PH->cur_page->id}_{$this->id}_grouping"); /** * @@@ later use only once... * * $this->columns= filterOptions($this->columns,"CURPAGE.BLOCKS[{$this->id}].STYLE[{$this->active_block_function}].COLUMNS"); */ if (isset($this->columns[$this->group_by])) { unset($this->columns[$this->group_by]); } ### prepend key to sorting ### if (isset($this->query_options['order_by'])) { $this->query_options['order_by'] = $this->groupings->getActiveFromCookie() . "," . $this->query_options['order_by']; } else { $this->query_options['order_by'] = $this->groupings->getActiveFromCookie(); } } $versions = Task::getAll($this->query_options); $this->render_list($versions); }
function ajaxUserTasks() { $q = asCleanString(getOnePassedId("q")); $prj = intval(getOnePassedId("prj")); if ($prj == 0) { $prj = NULL; } if ($q == "") { $q = NULL; } $tasks = Task::getAll(array('search' => $q, 'project' => $prj)); $result = array(); foreach ($tasks as $t) { $result[] = array('name' => $t->name, 'id' => $t->id); } echo json_encode($result); }
public function testSuperUserAllDefaultControllerActions() { $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super'); $superAccountId = self::getModelIdByModelNameAndName('Account', 'superAccount'); $superAccountId2 = self::getModelIdByModelNameAndName('Account', 'superAccount2'); $superContactId = self::getModelIdByModelNameAndName('Contact', 'superContact superContactson'); $account = Account::getById($superAccountId); $account2 = Account::getById($superAccountId2); $contact = Contact::getById($superContactId); //confirm no existing activities exist $activities = Activity::getAll(); $this->assertEquals(0, count($activities)); //Test just going to the create from relation view. $this->setGetArray(array('relationAttributeName' => 'Account', 'relationModelId' => $superAccountId, 'relationModuleId' => 'accounts', 'redirectUrl' => 'someRedirect')); $this->runControllerWithNoExceptionsAndGetContent('tasks/default/createFromRelation'); //add related task for account using createFromRelation action $activityItemPostData = array('Account' => array('id' => $superAccountId)); $this->setGetArray(array('relationAttributeName' => 'Account', 'relationModelId' => $superAccountId, 'relationModuleId' => 'accounts', 'redirectUrl' => 'someRedirect')); $this->setPostArray(array('ActivityItemForm' => $activityItemPostData, 'Task' => array('name' => 'myTask'))); $this->runControllerWithRedirectExceptionAndGetContent('tasks/default/createFromRelation'); //now test that the new task exists, and is related to the account. $tasks = Task::getAll(); $this->assertEquals(1, count($tasks)); $this->assertEquals('myTask', $tasks[0]->name); $this->assertEquals(1, $tasks[0]->activityItems->count()); $activityItem1 = $tasks[0]->activityItems->offsetGet(0); $this->assertEquals($account, $activityItem1); //test viewing the existing task in a details view $this->setGetArray(array('id' => $tasks[0]->id)); $this->resetPostArray(); $this->runControllerWithNoExceptionsAndGetContent('tasks/default/details'); //test editing an existing task and saving. Add a second relation, to a contact. //First just go to the edit view and confirm it loads ok. $this->setGetArray(array('id' => $tasks[0]->id, 'redirectUrl' => 'someRedirect')); $this->resetPostArray(); $this->runControllerWithNoExceptionsAndGetContent('tasks/default/edit'); //Save changes via edit action. $activityItemPostData = array('Account' => array('id' => $superAccountId), 'Contact' => array('id' => $superContactId)); $this->setGetArray(array('id' => $tasks[0]->id, 'redirectUrl' => 'someRedirect')); $this->setPostArray(array('ActivityItemForm' => $activityItemPostData, 'Task' => array('name' => 'myTaskX'))); $this->runControllerWithRedirectExceptionAndGetContent('tasks/default/edit'); //Confirm changes applied correctly. $tasks = Task::getAll(); $this->assertEquals(1, count($tasks)); $this->assertEquals('myTaskX', $tasks[0]->name); $this->assertEquals(2, $tasks[0]->activityItems->count()); $activityItem1 = $tasks[0]->activityItems->offsetGet(0); $activityItem2 = $tasks[0]->activityItems->offsetGet(1); $this->assertEquals($account, $activityItem1); $this->assertEquals($contact, $activityItem2); //Remove contact relation. Switch account relation to a different account. $activityItemPostData = array('Account' => array('id' => $superAccountId2)); $this->setGetArray(array('id' => $tasks[0]->id)); $this->setPostArray(array('ActivityItemForm' => $activityItemPostData, 'Task' => array('name' => 'myTaskX'))); $this->runControllerWithRedirectExceptionAndGetContent('tasks/default/edit'); //Confirm changes applied correctly. $tasks = Task::getAll(); $this->assertEquals(1, count($tasks)); $this->assertEquals('myTaskX', $tasks[0]->name); $this->assertEquals(1, $tasks[0]->activityItems->count()); $activityItem1 = $tasks[0]->activityItems->offsetGet(0); $this->assertEquals($account2, $activityItem1); //test removing a task. $this->setGetArray(array('id' => $tasks[0]->id)); $this->resetPostArray(); $this->runControllerWithRedirectExceptionAndGetContent('tasks/default/delete'); //Confirm no more tasks exist. $tasks = Task::getAll(); $this->assertEquals(0, count($tasks)); }
require_once __DIR__ . "/../src/Category.php"; $app = new Silex\Application(); $app['debug'] = true; //SQL Server $server = 'mysql:host=localhost;dbname=to_do'; $username = '******'; $password = '******'; $DB = new PDO($server, $username, $password); //Twig Path $app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . '/../views')); //Route and Controller $app->get("/", function () use($app) { return $app['twig']->render('index.html.twig'); }); $app->get("/tasks", function () use($app) { $all_tasks = Task::getAll(); return $app['twig']->render('tasks.html.twig', array('tasks' => $all_tasks)); }); $app->get("/categories", function () use($app) { return $app['twig']->render('categories.html.twig', array('categories' => Category::getAll())); }); //Post Get Methods $app->post("/categories", function () use($app) { $category = new Category($_POST['name']); $category->save(); return $app['twig']->render('create_category.html.twig', array('newcategory' => $category)); }); $app->post("/tasks", function () use($app) { $task = new Task($_POST['description']); $task->save(); return $app['twig']->render('create_task.html.twig', array('newtask' => $task));
$category = Category::find($id); return $app['twig']->render('category.html.twig', array('category' => $category, 'tasks' => $category->getTasks())); }); $app->post("/tasks", function () use($app) { $description = $_POST['description']; $category_id = $_POST['category_id']; $due_date = $_POST['due_date']; $task = new Task($description, $id = null, $category_id, $due_date); $task->save(); $category = Category::find($category_id); return $app['twig']->render('category.html.twig', array('category' => $category, 'tasks' => $category->getTasks())); }); $app->post("/categories", function () use($app) { $category = new Category($_POST['name']); $category->save(); return $app['twig']->render('index.html.twig', array('categories' => Category::getAll())); }); $app->post("/delete_categories", function () use($app) { Task::deleteAll(); Category::deleteAll(); return $app['twig']->render('index.html.twig', array('categories' => Category::getAll())); }); $app->post("/delete_tasks", function () use($app) { $category_id = $_POST['category_id']; Task::deleteTasks($category_id); return $app['twig']->render('index.html.twig', array('categories' => Category::getAll())); }); $app->get("/all_tasks", function () use($app) { return $app['twig']->render('all_tasks.html.twig', array('tasks' => Task::getAll(), 'categories' => Category::getAll())); }); return $app;
function testDeleteTask() { //Arrange $due_date = "2015-10-12"; $description = "Wash the dog"; $test_task = new Task($description, $due_date, 1); $test_task->save(); $description2 = "Water the lawn"; $test_task2 = new Task($description2, $due_date, 2); $test_task2->save(); //Act $test_task->delete(); //Assert $this->assertEquals([$test_task2], Task::getAll()); }
/** * @depends testInlineCreateCommentFromAjax */ public function testSuperUserModalAllDefaultFromRelationAction() { $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super'); $accountId = self::getModelIdByModelNameAndName('Account', 'superAccount'); $this->setGetArray(array('relationAttributeName' => 'Account', 'relationModelId' => $accountId, 'relationModuleId' => 'accounts', 'modalId' => 'relatedModalContainer-tasks', 'portletId' => '12', 'uniqueLayoutId' => 'AccountDetailsAndRelationsView_12')); $this->runControllerWithNoExceptionsAndGetContent('tasks/default/modalCreateFromRelation'); $tasks = Task::getAll(); $this->assertEquals(5, count($tasks)); $this->setGetArray(array('relationAttributeName' => 'Account', 'relationModelId' => $accountId, 'relationModuleId' => 'accounts', 'portletId' => '12', 'uniqueLayoutId' => 'AccountDetailsAndRelationsView_12')); $this->setPostArray(array('Task' => array('name' => 'Task for test cases'), 'ActivityItemForm' => array('Account' => array('id' => $accountId)))); $content = $this->runControllerWithNoExceptionsAndGetContent('tasks/default/modalSaveFromRelation'); $this->assertContains('Task for test cases', $content); $tasks = Task::getAll(); $this->assertEquals(6, count($tasks)); $this->setGetArray(array('id' => $tasks[5]->id)); $content = $this->runControllerWithNoExceptionsAndGetContent('tasks/default/modalDetails'); $this->assertContains('Task for test cases', $content); $this->setGetArray(array('id' => $tasks[5]->id)); $content = $this->runControllerWithNoExceptionsAndGetContent('tasks/default/modalEdit'); $this->setGetArray(array('id' => $tasks[5]->id)); unset($_POST['Task']); $content = $this->runControllerWithNoExceptionsAndGetContent('tasks/default/modalCopy'); $this->assertContains('Task for test cases', $content); }
/** * Submit changes to a task * * @ingroup pages */ function taskEditSubmit() { global $PH; global $auth; require_once confGet('DIR_STREBER') . 'db/class_taskperson.inc.php'; /** * keep a list of items linking to this task, task is new * we have to change the linking id after(!) inserting the task */ $link_items = array(); ### temporary object or from database? ### $tsk_id = getOnePassedId('tsk', '', true, 'invalid id'); if ($tsk_id == 0) { $task = new Task(array('id' => 0, 'project' => get('task_project'))); $was_category = 0; # undefined category for new tasks $was_resolved_version = 0; } else { if (!($task = Task::getVisiblebyId($tsk_id))) { $PH->abortWarning("invalid task-id"); } $was_category = $task->category; $was_resolved_version = $task->resolved_version; $task->validateEditRequestTime(); } ### cancel? ### if (get('form_do_cancel')) { if (!$PH->showFromPage()) { $PH->show('taskView', array('tsk' => $task->id)); } exit; } ### Validate integrety ### if (!validateFormCrc()) { $PH->abortWarning(__('Invalid checksum for hidden form elements')); } validateFormCaptcha(true); $was_a_folder = $task->category == TCATEGORY_FOLDER ? true : false; $was_released_as = $task->is_released; ### get project ### if (!($project = Project::getVisiblebyId($task->project))) { $PH->abortWarning("task without project?"); } /** * adding comment (from quick edit) does only require view right... */ $added_comment = false; ### check for request feedback if ($request_feedback = get('request_feedback')) { $team_members_by_nickname = array(); foreach ($project->getProjectPeople() as $pp) { $team_members_by_nickname[$pp->getPerson()->nickname] = $pp->getPerson(); } $requested_people = array(); foreach (explode('\\s*,\\s*', $request_feedback) as $nickname) { ### now check if this nickname is a team member if ($nickname = trim($nickname)) { if (isset($team_members_by_nickname[$nickname])) { $person = $team_members_by_nickname[$nickname]; ### update to itemperson table... if ($view = ItemPerson::getAll(array('person' => $person->id, 'item' => $task->id))) { $view[0]->feedback_requested_by = $auth->cur_user->id; $view[0]->update(); } else { $new_view = new ItemPerson(array('item' => $task->id, 'person' => $person->id, 'feedback_requested_by' => $auth->cur_user->id)); $new_view->insert(); } $requested_people[] = "<b>" . asHtml($nickname) . "</b>"; } else { new FeedbackWarning(sprintf(__("Nickname not known in this project: %s"), "<b>" . asHtml($nickname) . "</b>")); } } } if ($requested_people) { new FeedbackMessage(sprintf(__('Requested feedback from: %s.'), join($requested_people, ", "))); } } ### only insert the comment, when comment name or description are valid if (get('comment_name') || get('comment_description')) { require_once confGet('DIR_STREBER') . 'pages/comment.inc.php'; $valid_comment = true; ### new object? ### $comment = new Comment(array('name' => get('comment_name'), 'description' => get('comment_description'), 'project' => $task->project, 'task' => $task->id)); validateNotSpam($comment->name . $comment->description); ### write to db ### if ($valid_comment) { if (!$comment->insert()) { new FeedbackWarning(__("Failed to add comment")); } else { ### change task update modification date ### if (isset($task)) { ### Check if now longer new ### if ($task->status == STATUS_NEW) { global $auth; if ($task->created < $auth->cur_user->last_login) { $task->status = STATUS_OPEN; } } $task->update(array('modified', 'status')); } $added_comment = true; } } } if ($task->id != 0 && !Task::getEditableById($task->id)) { if ($added_comment) { ### display taskView #### if (!$PH->showFromPage()) { $PH->show('home', array()); } exit; } else { $PH->abortWarning(__("Not enough rights to edit task")); } } $task->validateEditRequestTime(); $status_old = $task->status; # retrieve all possible values from post-data (with field->view_in_forms == true) # NOTE: # - this could be an security-issue. # @@@ TODO: as some kind of form-edit-behaviour to field-definition foreach ($task->fields as $f) { $name = $f->name; $f->parseForm($task); } $task->fields['parent_task']->parseForm($task); ### category ### $was_of_category = $task->category; if (!is_null($c = get('task_category'))) { global $g_tcategory_names; if (isset($g_tcategory_names[$c])) { $task->category = $c; } else { trigger_error("ignoring unknown task category '{$c}'", E_USER_NOTICE); } } /** * @@@pixtur 2006-11-17: actually this has been depreciated. is_folder updated * for backward compatibility only. */ $task->is_folder = $task->category == TCATEGORY_FOLDER ? 1 : 0; ### Check if now longer new ### if ($status_old == $task->status && $task->status == STATUS_NEW) { global $auth; if ($task->created < $auth->cur_user->last_login) { $task->status = STATUS_OPEN; } } $assigned_people = array(); $task_assignments = array(); if ($task->id) { foreach ($task->getAssignedPeople() as $p) { $assigned_people[$p->id] = $p; } foreach ($task->getAssignments() as $ta) { $task_assignments[$ta->person] = $ta; } } $team = array(); foreach ($project->getPeople() as $p) { $team[$p->id] = $p; } $new_task_assignments = array(); # store assigments after(!) validation $forwarded = 0; $forward_comment = ''; $old_task_assignments = array(); if (isset($task_assignments)) { foreach ($task_assignments as $id => $t_old) { $id_new = get('task_assigned_to_' . $id); $forward_state = get('task_forward_to_' . $id); if ($forward_state) { $forwarded = 1; } else { $forwarded = 0; } $forward_comment = get('task_forward_comment_to_' . $id); if ($id_new === NULL) { log_message("failure. Can't change no longer existing assigment (person-id={$id} item-id={$t_old->id})", LOG_MESSAGE_DEBUG); #$PH->abortWarning("failure. Can't change no longer existing assigment",ERROR_NOTE); continue; } if ($id == $id_new) { if ($tp = TaskPerson::getTaskPeople(array('person' => $id, 'task' => $task->id))) { $tp[0]->forward = $forwarded; $tp[0]->forward_comment = $forward_comment; $old_task_assignments[] = $tp[0]; } #echo " [$id] {$team[$id]->name} still assigned<br>"; continue; } if ($id_new == 0) { if (!$t_old) { continue; } #echo " [$id] {$team[$id]->name} unassigned<br>"; $t_old->delete(); continue; } #$t_new= $task_assignments[$id_new]; $p_new = @$team[$id_new]; if (!isset($p_new)) { $PH->abortWarning("failure during form-value passing", ERROR_BUG); } #echo " [$id] assignment changed from {$team[$id]->name} to {$team[$id_new]->name}<br>"; $t_old->comment = sprintf(__("unassigned to %s", "task-assignment comment"), $team[$id_new]->name); $t_old->update(); $t_old->delete(); $new_assignment = new TaskPerson(array('person' => $team[$id_new]->id, 'task' => $task->id, 'comment' => sprintf(__("formerly assigned to %s", "task-assigment comment"), $team[$id]->name), 'project' => $project->id, 'forward' => $forwarded, 'forward_comment' => $forward_comment)); $new_task_assignments[] = $new_assignment; $link_items[] = $new_assignment; } } ### check new assigments ### $count = 0; while ($id_new = get('task_assign_to_' . $count)) { $forward_state = get('task_forward_to_' . $count); if ($forward_state) { $forwarded = 1; } else { $forwarded = 0; } $forward_comment = get('task_forward_comment_to_' . $count); $count++; ### check if already assigned ### if (isset($task_assignments[$id_new])) { if ($tp = TaskPerson::getTaskPeople(array('person' => $id_new, 'task' => $task->id))) { $tp[0]->forward = $forwarded; $tp[0]->forward_comment = $forward_comment; $old_task_assignments[] = $tp[0]; } #new FeedbackMessage(sprintf(__("task was already assigned to %s"),$team[$id_new]->name)); } else { if (!isset($team[$id_new])) { $PH->abortWarning("unknown person id {$id_new}", ERROR_DATASTRUCTURE); } $new_assignment = new TaskPerson(array('person' => $team[$id_new]->id, 'task' => $task->id, 'comment' => "", 'project' => $project->id, 'forward' => $forwarded, 'forward_comment' => $forward_comment)); /** * BUG? * - inserting the new assigment before sucessfully validating the * task will lead to double-entries in the database. */ $new_task_assignments[] = $new_assignment; #$new_assignment->insert(); $link_items[] = $new_assignment; } } if ($task->isOfCategory(array(TCATEGORY_VERSION, TCATEGORY_MILESTONE))) { if ($is_released = get('task_is_released')) { if (!is_null($is_released)) { $task->is_released = $is_released; } } } ### pub level ### if ($pub_level = get('task_pub_level')) { if ($task->id) { if ($pub_level > $task->getValidUserSetPublicLevels()) { $PH->abortWarning('invalid data', ERROR_RIGHTS); } } #else { # #@@@ check for person create rights #} $task->pub_level = $pub_level; } ### check project ### if ($task->id == 0) { if (!($task->project = get('task_project'))) { $PH->abortWarning("task requires project to be set"); } } ### get parent_task ### $is_ok = true; $parent_task = NULL; if ($task->parent_task) { $parent_task = Task::getVisibleById($task->parent_task); } ### validate ### if (!$task->name) { new FeedbackWarning(__("Task requires name")); $task->fields['name']->required = true; $task->fields['name']->invalid = true; $is_ok = false; } else { if ($task->id == 0) { $other_tasks = array(); if ($parent_task) { $other_tasks = Task::getAll(array('project' => $project->id, 'parent_task' => $parent_task->id, 'status_min' => STATUS_NEW, 'status_max' => STATUS_CLOSED, 'visible_only' => false)); } else { $other_tasks = Task::getAll(array('project' => $project->id, 'parent_task' => 0, 'status_min' => STATUS_NEW, 'status_max' => STATUS_CLOSED, 'visible_only' => false)); } foreach ($other_tasks as $ot) { if (!strcasecmp($task->name, $ot->name)) { $is_ok = false; new FeedbackWarning(sprintf(__('Task called %s already exists'), $ot->getLink(false))); break; } } } } ### automatically close resolved tasks ### if ($task->resolve_reason && $task->status < STATUS_COMPLETED) { $task->status = STATUS_COMPLETED; new FeedbackMessage(sprintf(__('Because task is resolved, its status has been changed to completed.'))); } ### Check if resolved tasks should be completed ### if ($task->resolved_version != 0 && $task->status < STATUS_COMPLETED) { new FeedbackWarning(sprintf(__('Task has resolved version but is not completed?'))); $task->fields['resolved_version']->invalid = true; $task->fields['status']->invalid = true; $is_ok = false; } ### Check if completion should be 100% ### if ($task->status >= STATUS_COMPLETED) { $task->completion = 100; } ### repeat form if invalid data ### if (!$is_ok) { $PH->show('taskEdit', NULL, $task); exit; } #--- write to database ----------------------------------------------------------------------- #--- be sure parent-task is folder --- if ($parent_task) { if ($parent_task->isMilestoneOrVersion()) { if ($parent_task->is_folder) { $parent_task->is_folder = 0; $parent_task->update(array('is_folder'), false); } $PH->abortWarning(__("Milestones may not have sub tasks")); } else { if ($parent_task->category != TCATEGORY_FOLDER) { $parent_task->category = TCATEGORY_FOLDER; $parent_task->is_folder = 1; if ($parent_task->update()) { new FeedbackMessage(__("Turned parent task into a folder. Note, that folders are only listed in tree")); } else { trigger_error(__("Failed, adding to parent-task"), E_USER_WARNING); $PH->abortWarning(__("Failed, adding to parent-task")); } } } } ### ungroup child tasks? ### if ($was_a_folder && $task->category != TCATEGORY_FOLDER) { $num_subtasks = $task->ungroupSubtasks(); # @@@ does this work??? /** * note: ALSO invisible tasks should be updated, so do not check for visibility here. */ $parent = Task::getById($task->parent_task); $parent_str = $parent ? $parent->name : __('Project'); if ($num_subtasks) { new FeedbackMessage(sprintf(__("NOTICE: Ungrouped %s subtasks to <b>%s</b>"), $num_subtasks, $parent_str)); } } if ($task->id && !get('task_issue_report')) { $task_issue_report = $task->issue_report; } else { if ($task->issue_report != get('task_issue_report')) { trigger_error("Requesting invalid issue report id for task!", E_USER_WARNING); $task_issue_report = get('task_issue_report'); } else { $task_issue_report = 0; } } ### consider issue-report? ### #$task_issue_report= get('task_issue_report'); if ($task->category == TCATEGORY_BUG || isset($task_issue_report) && $task_issue_report) { ### new report as / temporary ### if ($task_issue_report == 0 || $task_issue_report == -1) { $issue = new Issue(array('id' => 0, 'project' => $project->id, 'task' => $task->id)); ### querry form-information ### foreach ($issue->fields as $f) { $name = $f->name; $f->parseForm($issue); } global $g_reproducibility_names; if (!is_null($rep = get('issue_reproducibility'))) { if (isset($g_reproducibility_names[$rep])) { $issue->reproducibility = intval($rep); } else { $issue->reproducibility = REPRODUCIBILITY_UNDEFINED; } } global $g_severity_names; if (!is_null($sev = get('issue_severity'))) { if (isset($g_severity_names[$sev])) { $issue->severity = intval($sev); } else { $issue->severity = SEVERITY_UNDEFINED; } } ### write to db ### if (!$issue->insert()) { trigger_error("Failed to insert issue to db", E_USER_WARNING); } else { $link_items[] = $issue; $task->issue_report = $issue->id; } } else { if ($issue = Issue::getById($task_issue_report)) { ### querry form-information ### foreach ($issue->fields as $f) { $name = $f->name; $f->parseForm($issue); } global $g_reproducibility_names; if (!is_null($rep = get('issue_reproducibility'))) { if (isset($g_reproducibility_names[$rep])) { $issue->reproducibility = intval($rep); } else { $issue->reproducibility = REPRODUCIBILITY_UNDEFINED; } } global $g_severity_names; if (!is_null($sev = get('issue_severity'))) { if (isset($g_severity_names[$sev])) { $issue->severity = intval($sev); } else { $issue->severity = SEVERITY_UNDEFINED; } } ### write to db ### if (!$issue->update()) { trigger_error("Failed to write issue to DB (id={$issue->id})", E_USER_WARNING); } if ($task->issue_report != $issue->id) { # additional check, actually not necessary trigger_error("issue-report as invalid id ({$issue->id}). Should be ({$task->issue_report}) Please report this bug.", E_USER_WARNING); } } else { trigger_error("Could not get issue with id {$task->issue_report} from database", E_USER_WARNING); } } } ### write to db ### if ($task->id == 0) { $task->insert(); ### write task-assigments ### foreach ($new_task_assignments as $nta) { $nta->insert(); } ### now we now the id of the new task, link the other items foreach ($link_items as $i) { $i->task = $task->id; $i->update(); } new FeedbackMessage(sprintf(__("Created %s %s with ID %s", "Created <type> <name> with ID <id>..."), $task->getLabel(), $task->getLink(false), $task->id)); } else { ### write task-assigments ### foreach ($new_task_assignments as $nta) { $nta->insert(); } foreach ($old_task_assignments as $ota) { $ota->update(); } new FeedbackMessage(sprintf(__("Changed %s %s with ID %s", "type,link,id"), $task->getLabel(), $task->getLink(false), $task->id)); $task->update(); $project->update(array(), true); } ### add any recently resolved tasks if this is a just released version ### if ($task->category == TCATEGORY_VERSION && $was_category != TCATEGORY_VERSION) { if ($resolved_tasks = Task::getAll(array('project' => $task->project, 'status_min' => 0, 'status_max' => 10, 'resolved_version' => RESOLVED_IN_NEXT_VERSION))) { foreach ($resolved_tasks as $rt) { $rt->resolved_version = $task->id; $rt->update(array('resolved_version')); } new FeedbackMessage(sprintf(__('Marked %s tasks to be resolved in this version.'), count($resolved_tasks))); } } ### notify on change ### $task->nowChangedByUser(); ### create another task ### if (get('create_another')) { ### build dummy form ### $newtask = new Task(array('id' => 0, 'name' => __('Name'), 'project' => $task->project, 'state' => 1, 'prio' => $task->prio, 'label' => $task->label, 'parent_task' => $task->parent_task, 'for_milestone' => $task->for_milestone, 'category' => $task->category)); $PH->show('taskEdit', array('tsk' => $newtask->id), $newtask); } else { ### go to task, if new if ($tsk_id == 0) { $PH->show('taskView', array('tsk' => $task->id)); exit; } else { if (!$PH->showFromPage()) { $PH->show('home', array()); } } } }
return $app['twig']->render('index.html.twig', array('categories' => Category::getAll())); }); $app->get("/tasks", function () use($app) { return $app['twig']->render('tasks.html.twig', array('tasks' => Task::getAll())); }); $app->get("/categories/{id}", function ($id) use($app) { $category = Category::find($id); return $app['twig']->render('category.html.twig', array('category' => $category, 'tasks' => $category->getTasks())); }); $app->post("/tasks", function () use($app) { $description = $_POST['description']; $category_id = $_POST['category_id']; $task = new Task($description, $id = null, $category_id); $task->save(); $category = Category::find($category_id); return $app['twig']->render('category.html.twig', array('category' => $category, 'tasks' => Task::getAll())); }); $app->post("/delete_tasks", function () use($app) { Task::deleteAll(); return $app['twig']->render('index.html.twig'); }); $app->post("/categories", function () use($app) { $category = new Category($_POST['name']); $category->save(); return $app['twig']->render('index.html.twig', array('categories' => Category::getAll())); }); $app->post("/delete_categories", function () use($app) { Category::deleteAll(); return $app['twig']->render('index.html.twig'); }); return $app;
static function renderLinkFromTargetName($target, $name) { measure_start("BlockLink::renderLinkFromTargetName"); global $PH; global $g_replace_list; global $g_wiki_project; $html = ""; /** * start with looking for tasks... */ $decoded_name = strtr($target, array_flip(get_html_translation_table(HTML_SPECIALCHARS, ENT_QUOTES))); measure_start("BlockLink::renderLinkFromTargetName::getTasks"); if ($g_wiki_project) { $tasks = Task::getAll(array('name' => $decoded_name, 'project' => $g_wiki_project->id, 'status_max' => STATUS_CLOSED)); } else { $tasks = Task::getAll(array('name' => $decoded_name, 'status_max' => STATUS_CLOSED)); } measure_stop("BlockLink::renderLinkFromTargetName::getTasks"); if (count($tasks) == 1) { ### matches name ### if (!strcasecmp(asHtml($tasks[0]->name), $target)) { $style_isdone = $tasks[0]->status >= STATUS_COMPLETED ? 'isDone' : ''; if ($name) { $html = "<a class='item task {$style_isdone}' href='" . $PH->getUrl('taskView', array('tsk' => intval($tasks[0]->id))) . "'>" . asHtml($name) . "</a>"; global $g_replace_list; $g_replace_list[$target] = '#' . $tasks[0]->id . '|' . $name; } else { $html = "<a class='item task {$style_isdone}' href='" . $PH->getUrl('taskView', array('tsk' => intval($tasks[0]->id))) . "'>" . asHtml($tasks[0]->name) . "</a>"; global $g_replace_list; $g_replace_list[$target] = '#' . $tasks[0]->id . '|' . $tasks[0]->name; } } else { if (!strcasecmp($tasks[0]->short, $target)) { $style_isdone = $tasks[0]->status >= STATUS_COMPLETED ? 'isDone' : ''; if ($name) { $html = "<a class='item task {$style_isdone}' href='" . $PH->getUrl('taskView', array('tsk' => intval($tasks[0]->id))) . "'>" . asHtml($name) . "</a>"; global $g_replace_list; $g_replace_list[$target] = '#' . $tasks[0]->id . '|' . $name; } else { $html = "<a class='item task {$style_isdone}' href='" . $PH->getUrl('taskView', array('tsk' => intval($tasks[0]->id))) . "'>" . asHtml($tasks[0]->name) . "</a>"; global $g_replace_list; $g_replace_list[$target] = '#' . $tasks[0]->id . '|' . $tasks[0]->short; } } else { $title = __('No task matches this name exactly'); $title2 = __('This task seems to be related'); $html = "<span title='{$title}' class=not_found>{$name}</span>" . "<a href='" . $PH->getUrl('taskView', array('tsk' => intval($tasks[0]->id))) . "' title='{$title2}'>?</a>"; } } } else { if (count($tasks) > 1) { measure_start("BlockLink::renderLinkFromTargetName::iterateSeveralTasks"); $matches = array(); $best = -1; $best_rate = 0; foreach ($tasks as $t) { if (!strcasecmp($t->name, $target) && $g_wiki_project && $t->project == $g_wiki_project->id) { $matches[] = $t; } else { if (!strcasecmp($t->short, $target)) { $matches[] = $t; } } } if (count($matches) == 1) { $html = "<a href='" . $PH->getUrl('taskView', array('tsk' => intval($matches[0]->id))) . "'>" . $matches[0]->name . "</a>"; } else { if (count($matches) > 1) { $title = __('No item excactly matches this name.'); $title2 = sprintf(__('List %s related tasks'), count($tasks)); $html = "<a class=not_found title= '{$title2}' href='" . $PH->getUrl('search', array('search_query' => $target)) . "'> " . $target . " (" . count($matches) . ' ' . __('identical') . ")</a>"; } else { if ($g_wiki_project) { $title = __('No item matches this name. Create new task with this name?'); $url = $PH->getUrl('taskNew', asHtml($target), array('prj' => $g_wiki_project->id)); $html = "<a href='{$url}' title='{$title}' class=not_found>{$target}</a>"; } else { $title = __('No item matches this name...'); $html = "<span title='{$title}' class=not_found>{$target}</span>"; } } } measure_stop("BlockLink::renderLinkFromTargetName::iterateSeveralTasks"); } else { if (0 == count($tasks)) { measure_start("BlockLink::renderLinkFromTargetName::notATaskItem"); /** * now check for team-members... */ if ($g_wiki_project) { $people = Person::getPeople(array('project' => $g_wiki_project->id, 'search' => $target)); if (count($people) == 1) { return "<a class='item person' title= '" . asHtml($people[0]->name) . "' href='" . $PH->getUrl('personView', array('person' => $people[0]->id)) . "'>" . asHtml($target) . "</a>"; } measure_stop("BlockLink::renderLinkFromTargetName::getPeople"); } /** * Link to create new task or topic */ if ($g_wiki_project) { $title = __('No item matches this name. Create new task with this name?'); global $g_wiki_task; if (isset($g_wiki_task) && $g_wiki_task->type == ITEM_TASK) { if ($g_wiki_task->category == TCATEGORY_FOLDER) { $parent_task = $g_wiki_task->id; } else { $parent_task = $g_wiki_task->parent_task; } } else { $parent_task = 0; } $url = $PH->getUrl('taskNew', array('prj' => $g_wiki_project->id, 'new_name' => urlencode($target), 'parent_task' => $parent_task)); $html = "<a href='{$url}' title='{$title}' class=not_found>{$target}</a>"; } else { $title = __('No item matches this name'); $html = "<span title='{$title}' class=not_found>{$target}</span>"; trigger_error('g_wiki_project was not defined. Could not provide create-link.', E_USER_NOTICE); } measure_stop("BlockLink::renderLinkFromTargetName::notATaskItem"); } } } measure_stop("BlockLink::renderLinkFromTargetName"); return $html; }
function testDeleteTask() { //Arrange $description = "Wash the dog"; $id = 1; $test_task = new Task($description, $id); $test_task->save(); $description2 = "Water the lawn"; $id2 = 2; $test_task2 = new Task($description2, $id2); $test_task2->save(); //Act $test_task->delete(); //Assert $this->assertEquals([$test_task2], Task::getAll()); }
<?php require_once __DIR__ . "/../vendor/autoload.php"; require_once __DIR__ . "/../src/Task.php"; session_start(); if (empty($_SESSION['list_of_tasks'])) { $_SESSION['list_of_tasks'] = array(); } $app = new Silex\Application(); $app->get("/", function () { $output = ""; $all_tasks = Task::getAll(); if (!empty($all_tasks)) { $output = $output . "\n <h1>Here's what you need to do</h1>\n "; foreach (Task::getAll() as $task) { $output = $output . "<p>" . $task->getDescription() . "</p>"; } } $output = $output . "\n <form action='/tasks' method='post'>\n <label for='description'>Task Description</label>\n <input id='description' name='description' type='text'>\n\n <button type='submit'>Add Task</button>\n </form>\n "; $output .= "\n <form action ='/delete_tasks' method='post'>\n <button type='submit'>DELETE!</button>\n </form>\n "; return $output; }); $app->post("/tasks", function () { $task = new Task($_POST['description']); $task->save(); return "\n <h1>You made a Task!</h1>\n <p>" . $task->getDescription() . "</p>\n <p><a href='/'> View your list of things to do.</a></p>\n "; }); $app->post("/delete_tasks", function () { Task::deleteAll(); return "\n <h1> ALL DONE!</a1>\n <p><a href='/'>Back to Work!</a></p>\n "; });
function testDeleteCategoryTasks() { //Arrange $name = "Work stuff"; $id = null; $test_category = new Category($name, $id); $test_category->save(); $description = "Build website"; $category_id = $test_category->getId(); $test_task = new Task($description, $id, $category_id); $test_task->save(); //Act $test_category->delete(); //Assert $this->assertEquals([], Task::getAll()); }
/** * build list of milestones / versions for drop downselection planned "for_milestone" * * -- undefined -- * milestone 1 * milestone 2 * -- already released versions --- * version 1 * version 2 */ public function buildPlannedForMilestoneList() { $tmp_milestonelist = array(NO_OPTION_GROUP => array('0' => '-- ' . __('undefined') . ' --')); $milestone_options = array(); $closed_milestone_options = array(); foreach (Task::getAll(array('category' => TCATEGORY_MILESTONE, 'project' => $this->id, 'status_min' => 0, 'status_max' => 10, 'order_by' => "name")) as $milestone) { if ($milestone->status >= STATUS_COMPLETED) { $closed_milestone_options[$milestone->id] = $milestone->name; } else { $milestone_options[$milestone->id] = $milestone->name; } } if ($milestone_options) { $tmp_milestonelist[__('Milestones')] = $milestone_options; } if ($closed_milestone_options) { $tmp_milestonelist[__('Milestones (closed)')] = $closed_milestone_options; } $version_options = array(); if ($versions = Task::getAll(array('category' => TCATEGORY_VERSION, 'project' => $this->id, 'status_min' => 0, 'status_max' => 10, 'order_by' => "name"))) { #$tmp_milestonelist[('-- ' . __('Released versions') . ' --')] = '-2'; foreach ($versions as $version) { $version_options[$version->id] = $version->name; } } if ($version_options) { $tmp_milestonelist[__('Versions')] = $version_options; } return $tmp_milestonelist; }
}); $app->patch("/tasks/{id}", function ($id) use($app) { $task = Task::find($id); $task->update($_POST['description'], $_POST['due_date']); return $app['twig']->render('tasks.html.twig', array('tasks' => Task::getAll())); }); $app->delete("/tasks/{id}", function ($id) use($app) { $task = Task::find($id); $task->delete(); return $app['twig']->render('tasks.html.twig', array('tasks' => Task::getAll())); }); $app->post("/add_categories", function () use($app) { $category = Category::find($_POST['category_id']); $task = Task::find($_POST['task_id']); $task->addCategory($category); return $app['twig']->render('task.html.twig', array('task' => $task, 'tasks' => Task::getAll(), 'categories' => $task->getCategories(), 'all_categories' => Category::getAll())); }); $app->get("/categories/{id}/edit", function ($id) use($app) { $category = Category::find($id); return $app['twig']->render('category_edit.html.twig', array('category' => $category)); }); $app->patch("/categories/{id}", function ($id) use($app) { $category = Category::find($id); $category->update($_POST['name']); return $app['twig']->render('categories.html.twig', array('categories' => Category::getAll())); }); $app->delete("/categories/{id}", function ($id) use($app) { $category = Category::find($id); $category->delete(); return $app['twig']->render('categories.html.twig', array('categories' => Category::getAll())); });
/** * @depends testUpdateTaskFromForm */ public function testDeleteTask() { Yii::app()->user->userModel = User::getByUsername('super'); $tasks = Task::getAll(); $this->assertEquals(2, count($tasks)); $tasks[0]->delete(); $tasks = Task::getAll(); $this->assertEquals(1, count($tasks)); }
$password = '******'; $DB = new PDO($server, $username, $password); $app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . '/../views')); $app->get("/", function () use($app) { return $app['twig']->render('index.html.twig'); }); $app->get("/tasks", function () use($app) { return $app['twig']->render('tasks.html.twig', array('tasks' => Task::getAll())); }); $app->get("/categories", function () use($app) { return $app['twig']->render('categories.html.twig', array('categories' => Category::getAll())); }); $app->post("/tasks", function () use($app) { $task = new task($_POST['description']); $task->save(); return $app['twig']->render('tasks.html.twig', array('tasks' => Task::getAll())); }); $app->post("/delete_tasks", function () use($app) { Task::deleteAll(); return $app['twig']->render('index.html.twig'); }); $app->post("/categories", function () use($app) { $category = new Category($_POST['name']); $category->save(); return $app['twig']->render('categories.html.twig', array('categories' => Category::getAll())); }); $app->post("/delete_categories", function () use($app) { Category::deleteAll(); return $app['twig']->render('index.html.twig'); }); return $app;
function testDeleteTask() { //Arrange $description = "Wash the dog"; $id = null; $due_date = "01-01-2016"; $test_task = new Task($description, $id, $due_date); $test_task->save(); $description2 = "Water the lawn"; $id2 = null; $due_date2 = "01-02-2016"; $test_task2 = new Task($description2, $id2, $due_date2); $test_task2->save(); //Act $test_task->delete(); //Assert $this->assertEquals([$test_task2], Task::getAll()); }