public function testUserCanDeleteATask() { $user = factory(User::class)->create(); $task = factory(Task::class)->create(['user_id' => $user->id]); $this->actingAs($user)->makeRequest('DELETE', "/tasks/{$task->id}"); $this->assertEmpty(Task::personal()->find($task->id)); }
public function destroy($task_id, $id, Request $request) { $task = Task::personal()->find($task_id); $note = $task->notes->find($id); $note->delete(); return redirect()->route('tasks.show', ['id' => $task_id])->with('info', 'The Note was deleted!'); }
public function testUserCanSaveANewTask() { $task = factory(Task::class)->make(); $this->actingAs($this->user)->makeRequest('post', '/tasks', ['name' => $task->name, 'description' => $task->description]); $actualtask = Task::personal()->get()->where('name', $task->name)->first(); $this->assertEquals($task->name, $actualtask->name); $this->assertEquals($task->status, $actualtask->status); $this->assertEquals($task->description, $actualtask->description); }
public function testUserCanSaveTheChanges() { $secondtask = factory(Task::class)->create(['status' => 'closed', 'user_id' => $this->user->id]); $this->actingAs($this->user)->makeRequest('put', "/tasks/{$this->task->id}", ['name' => $secondtask->name, 'status' => $secondtask->status, 'description' => $secondtask->description]); $task1 = Task::personal()->get()->where('id', $this->task->id)->first(); $this->assertEquals($secondtask->name, $task1->name); $this->assertEquals($secondtask->status, $task1->status); $this->assertEquals($secondtask->description, $task1->description); }
public function testTrackedTimeGetsSummarizedCorrectlyForTask() { $timediff_seconds1 = random_int(10, 9999); $now = date('Y-m-d H:i:s'); $start1 = new \DateTime($now); $stop1 = new \DateTime($now); $dateinterval1 = new \DateInterval("PT{$timediff_seconds1}S"); $stop1->add($dateinterval1); factory(Tracking::class)->create(['user_id' => $this->user->id, 'task_id' => $this->task1->id, 'started_at' => $start1->format('Y-m-d H:i:s'), 'stopped_at' => $stop1->format('Y-m-d H:i:s'), 'active' => false]); $timediff_seconds2 = random_int(10, 9999); $yesterday = date('Y-m-d H:i:s', mktime(date('H'), date('i'), date('s'), date('n'), date('j') - 1, date('Y'))); $start2 = new \DateTime($yesterday); $stop2 = new \DateTime($yesterday); $dateinterval2 = new \DateInterval("PT{$timediff_seconds2}S"); $stop2->add($dateinterval2); factory(Tracking::class)->create(['user_id' => $this->user->id, 'task_id' => $this->task1->id, 'started_at' => $start2->format('Y-m-d H:i:s'), 'stopped_at' => $stop2->format('Y-m-d H:i:s'), 'active' => false]); $timediff_seconds3 = random_int(10, 9999); $twodaysbefore = date('Y-m-d H:i:s', mktime(date('H'), date('i'), date('s'), date('n'), date('j') - 1, date('Y'))); $start3 = new \DateTime($twodaysbefore); $stop3 = new \DateTime($twodaysbefore); $dateinterval3 = new \DateInterval("PT{$timediff_seconds3}S"); $stop3->add($dateinterval3); factory(Tracking::class)->create(['user_id' => $this->user->id, 'task_id' => $this->task1->id, 'started_at' => $start3->format('Y-m-d H:i:s'), 'stopped_at' => $stop3->format('Y-m-d H:i:s'), 'active' => false]); $start_expected_calculation = new \DateTime($now); $stop_expected_calculation = new \DateTime($now); $stop_expected_calculation->add(new \DateInterval('PT' . ($timediff_seconds1 + $timediff_seconds2 + $timediff_seconds3) . 'S')); $expected_dateinterval = $start_expected_calculation->diff($stop_expected_calculation); $task = Task::where('id', 1); $this->assertEquals($expected_dateinterval, $this->task1->getTrackedTime()); }
public function destroy($id) { $task = Task::personal()->findOrFail($id); $task->delete(); return redirect()->route('tasks.index')->with('info', 'The Task was deleted!'); }