function deleteTask($id, $editor) { // read global var $app global $app; // check user permission exists if (checkUserPermission($editor, "removeTask") == true) { if (array_key_exists($id, $app['tasks'])) { unset($app['tasks'][$id]); saveTasks(); } else { throw new Exception("Can't delete this task", 2); } } else { throw new Exception("Permission denied!", 1); } }
public function testSaveTasks() { // save in Trash (will not break our future test !) global $app; $app['param']['db_path_tasks'] = $this->trashFile; // try to save $caught = false; try { saveTasks(); } catch (\Exception $e) { $caught = true; } $this->assertFalse($caught); // try to load this file (see if json is correct) $caught = false; try { $fileDatas = loadJson($this->trashFile); } catch (\Exception $e) { $caught = true; } $this->assertFalse($caught); // test datas in file are good one $this->assertEquals($fileDatas, $app['tasks']); }