|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace PanicHD\PanicHD\Tests\Feature; |
| 4 | + |
| 5 | +use PanicHD\PanicHD\Models\Ticket; |
| 6 | +use PanicHD\PanicHD\Tests\TestCase; |
| 7 | + |
| 8 | +class TicketsTest extends TestCase |
| 9 | +{ |
| 10 | + /* |
| 11 | + * Check that we don't have access without auth() Member |
| 12 | + */ |
| 13 | + public function testNoAuth() |
| 14 | + { |
| 15 | + $this->load_vars(); |
| 16 | + |
| 17 | + if ($this->status == "Installed" and !is_null($this->main_route)){ |
| 18 | + // Main route |
| 19 | + $response = $this->get($this->main_route); |
| 20 | + $response->assertRedirect('/login'); |
| 21 | + |
| 22 | + // Ticket creation |
| 23 | + $response = $this->get(route($this->main_route . '.create')); |
| 24 | + $response->assertRedirect('/login'); |
| 25 | + } |
| 26 | + } |
| 27 | + |
| 28 | + /* |
| 29 | + * Access to the main route |
| 30 | + */ |
| 31 | + public function testMainRoute() |
| 32 | + { |
| 33 | + $this->load_vars(); |
| 34 | + |
| 35 | + if ($this->status == "Installed" and !is_null($this->main_route)){ |
| 36 | + // Member access |
| 37 | + if(!is_null($this->member)){ |
| 38 | + $response = $this->actingAs($this->member)->get($this->main_route); |
| 39 | + $response->assertStatus(200); |
| 40 | + } |
| 41 | + |
| 42 | + // Agent access |
| 43 | + if(!is_null($this->agent)){ |
| 44 | + $response = $this->actingAs($this->agent)->get($this->main_route); |
| 45 | + $response->assertStatus(200); |
| 46 | + } |
| 47 | + |
| 48 | + // Admin access |
| 49 | + if(!is_null($this->admin)){ |
| 50 | + $response = $this->actingAs($this->admin)->get($this->main_route); |
| 51 | + $response->assertStatus(200); |
| 52 | + } |
| 53 | + } |
| 54 | + } |
| 55 | + |
| 56 | + /* |
| 57 | + * Ticket creation |
| 58 | + */ |
| 59 | + public function testTicketCreate() |
| 60 | + { |
| 61 | + $this->load_vars(); |
| 62 | + |
| 63 | + if ($this->status == "Installed" and !is_null($this->main_route)){ |
| 64 | + // Member access |
| 65 | + if(!is_null($this->member)){ |
| 66 | + $response = $this->actingAs($this->member)->get(route($this->main_route . '.create')); |
| 67 | + } |
| 68 | + |
| 69 | + // Agent access |
| 70 | + if(!is_null($this->agent)){ |
| 71 | + $response = $this->actingAs($this->agent)->get(route($this->main_route . '.create')); |
| 72 | + } |
| 73 | + |
| 74 | + // Admin access |
| 75 | + if(!is_null($this->admin)){ |
| 76 | + $response = $this->actingAs($this->admin)->get(route($this->main_route . '.create')); |
| 77 | + } |
| 78 | + } |
| 79 | + } |
| 80 | + |
| 81 | + /* |
| 82 | + * Access a Ticket Card |
| 83 | + */ |
| 84 | + public function testTicketShow() |
| 85 | + { |
| 86 | + $this->load_vars(); |
| 87 | + |
| 88 | + if ($this->status == "Installed" and !is_null($this->main_route)){ |
| 89 | + // Member access |
| 90 | + if(!is_null($this->member)){ |
| 91 | + // Visible ticket |
| 92 | + $ticket = clone $this->member_tickets_builder; |
| 93 | + $ticket = $ticket->notHidden()->first(); |
| 94 | + $response = $this->actingAs($this->member)->get(route($this->main_route . '.show', ['id' => $ticket->id])); |
| 95 | + $response->assertStatus(200); |
| 96 | + |
| 97 | + // Hidden ticket without $this->member in notifications |
| 98 | + $ticket = clone $this->member_tickets_builder; |
| 99 | + $member = $this->member; |
| 100 | + $ticket = $ticket->hidden() |
| 101 | + ->whereDoesntHave('commentNotifications', function($query)use($member){ |
| 102 | + $query->where('member_id', $member->id); |
| 103 | + }) |
| 104 | + ->first(); |
| 105 | + if(!is_null($ticket)){ |
| 106 | + $response = $this->actingAs($this->member)->get(route($this->main_route . '.show', ['id' => $ticket->id])); |
| 107 | + $response->assertStatus(302); |
| 108 | + } |
| 109 | + } |
| 110 | + |
| 111 | + // Agent access |
| 112 | + if(!is_null($this->agent)){ |
| 113 | + $ticket = $this->agent->agentTickets()->inRandomOrder()->first(); |
| 114 | + |
| 115 | + $response = $this->actingAs($this->agent)->get(route($this->main_route . '.show', ['id' => $ticket->id])); |
| 116 | + $response->assertStatus(200); |
| 117 | + } |
| 118 | + |
| 119 | + // Admin access |
| 120 | + if(!is_null($this->admin)){ |
| 121 | + $ticket_build = Ticket::inRandomOrder(); |
| 122 | + |
| 123 | + // Newest ticket |
| 124 | + $build = clone $ticket_build; |
| 125 | + $ticket = $build->newest()->first(); |
| 126 | + |
| 127 | + if (!is_null($ticket)){ |
| 128 | + $response = $this->actingAs($this->admin)->get(route($this->main_route . '.show', ['id' => $ticket->id])); |
| 129 | + $response->assertStatus(200); |
| 130 | + } |
| 131 | + |
| 132 | + // Active ticket |
| 133 | + $build = clone $ticket_build; |
| 134 | + $ticket = $build->active()->first(); |
| 135 | + |
| 136 | + if (!is_null($ticket)){ |
| 137 | + $response = $this->actingAs($this->admin)->get(route($this->main_route . '.show', ['id' => $ticket->id])); |
| 138 | + $response->assertStatus(200); |
| 139 | + } |
| 140 | + |
| 141 | + // Complete ticket |
| 142 | + $build = clone $ticket_build; |
| 143 | + $ticket = $build->complete()->first(); |
| 144 | + |
| 145 | + if (!is_null($ticket)){ |
| 146 | + $response = $this->actingAs($this->admin)->get(route($this->main_route . '.show', ['id' => $ticket->id])); |
| 147 | + $response->assertStatus(200); |
| 148 | + } |
| 149 | + } |
| 150 | + } |
| 151 | + } |
| 152 | +} |
0 commit comments