|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Tests\Feature\Api; |
| 4 | + |
| 5 | +use PHPUnit\Framework\Attributes\Group as TestGroup; |
| 6 | +use ProcessMaker\Models\ProcessRequest; |
| 7 | +use ProcessMaker\Models\ProcessRequestToken; |
| 8 | +use ProcessMaker\Models\User; |
| 9 | +use Tests\Feature\Shared\RequestHelper; |
| 10 | +use Tests\TestCase; |
| 11 | + |
| 12 | +/** |
| 13 | + * Regression for tasks index 1052 (ambiguous user_id) when a non-admin |
| 14 | + * lists tasks ordered by process_requests.case_title. |
| 15 | + */ |
| 16 | +#[TestGroup('process_tests')] |
| 17 | +class TaskListNonAdminCaseTitleOrderTest extends TestCase |
| 18 | +{ |
| 19 | + use RequestHelper; |
| 20 | + |
| 21 | + public function testNonAdminCanListTasksOrderedByCaseTitleDesc() |
| 22 | + { |
| 23 | + $this->user = User::factory()->create([ |
| 24 | + 'is_administrator' => false, |
| 25 | + 'status' => 'ACTIVE', |
| 26 | + ]); |
| 27 | + $otherUser = User::factory()->create([ |
| 28 | + 'is_administrator' => false, |
| 29 | + 'status' => 'ACTIVE', |
| 30 | + ]); |
| 31 | + |
| 32 | + $zetaRequest = ProcessRequest::factory()->create(); |
| 33 | + $alphaRequest = ProcessRequest::factory()->create(); |
| 34 | + $otherRequest = ProcessRequest::factory()->create(); |
| 35 | + $zetaRequest->forceFill(['case_title' => 'Zeta mandate'])->saveQuietly(); |
| 36 | + $alphaRequest->forceFill(['case_title' => 'Alpha mandate'])->saveQuietly(); |
| 37 | + $otherRequest->forceFill(['case_title' => 'Omega mandate'])->saveQuietly(); |
| 38 | + |
| 39 | + $zetaTask = ProcessRequestToken::factory()->create([ |
| 40 | + 'user_id' => $this->user->id, |
| 41 | + 'process_id' => $zetaRequest->process_id, |
| 42 | + 'process_request_id' => $zetaRequest->id, |
| 43 | + 'element_type' => 'task', |
| 44 | + 'status' => 'ACTIVE', |
| 45 | + 'is_self_service' => false, |
| 46 | + 'is_priority' => true, |
| 47 | + 'completed_at' => null, |
| 48 | + ]); |
| 49 | + $alphaTask = ProcessRequestToken::factory()->create([ |
| 50 | + 'user_id' => $this->user->id, |
| 51 | + 'process_id' => $alphaRequest->process_id, |
| 52 | + 'process_request_id' => $alphaRequest->id, |
| 53 | + 'element_type' => 'task', |
| 54 | + 'status' => 'ACTIVE', |
| 55 | + 'is_self_service' => false, |
| 56 | + 'is_priority' => true, |
| 57 | + 'completed_at' => null, |
| 58 | + ]); |
| 59 | + ProcessRequestToken::factory()->create([ |
| 60 | + 'user_id' => $otherUser->id, |
| 61 | + 'process_id' => $otherRequest->process_id, |
| 62 | + 'process_request_id' => $otherRequest->id, |
| 63 | + 'element_type' => 'task', |
| 64 | + 'status' => 'ACTIVE', |
| 65 | + 'is_self_service' => false, |
| 66 | + 'is_priority' => true, |
| 67 | + 'completed_at' => null, |
| 68 | + ]); |
| 69 | + |
| 70 | + $response = $this->apiCall('GET', '/tasks', [ |
| 71 | + 'page' => 1, |
| 72 | + 'include' => 'process,processRequest,processRequest.user,user', |
| 73 | + 'pmql' => '(user_id = ' . $this->user->id . ')', |
| 74 | + 'per_page' => 15, |
| 75 | + 'order_by' => 'process_requests.case_title', |
| 76 | + 'order_direction' => 'desc', |
| 77 | + 'non_system' => true, |
| 78 | + 'processesIManage' => 'false', |
| 79 | + 'advanced_filter' => json_encode([ |
| 80 | + [ |
| 81 | + 'subject' => ['type' => 'Status'], |
| 82 | + 'operator' => '=', |
| 83 | + 'value' => 'In Progress', |
| 84 | + ], |
| 85 | + [ |
| 86 | + 'subject' => ['type' => 'Field', 'value' => 'is_priority'], |
| 87 | + 'operator' => '=', |
| 88 | + 'value' => true, |
| 89 | + ], |
| 90 | + ]), |
| 91 | + ]); |
| 92 | + |
| 93 | + $response->assertStatus(200); |
| 94 | + |
| 95 | + $rows = $response->json('data'); |
| 96 | + $this->assertCount(2, $rows); |
| 97 | + $this->assertSame( |
| 98 | + [$zetaTask->id, $alphaTask->id], |
| 99 | + array_column($rows, 'id') |
| 100 | + ); |
| 101 | + $this->assertSame( |
| 102 | + ['Zeta mandate', 'Alpha mandate'], |
| 103 | + array_map(fn ($row) => $row['process_request']['case_title'] ?? null, $rows) |
| 104 | + ); |
| 105 | + } |
| 106 | + |
| 107 | + public function testNonAdminCanListTasksOrderedByCaseTitleDescAndFulltextSearch() |
| 108 | + { |
| 109 | + $this->user = User::factory()->create([ |
| 110 | + 'is_administrator' => false, |
| 111 | + 'status' => 'ACTIVE', |
| 112 | + ]); |
| 113 | + $otherUser = User::factory()->create([ |
| 114 | + 'is_administrator' => false, |
| 115 | + 'status' => 'ACTIVE', |
| 116 | + ]); |
| 117 | + |
| 118 | + $zetaRequest = ProcessRequest::factory()->create(); |
| 119 | + $alphaRequest = ProcessRequest::factory()->create(); |
| 120 | + $otherRequest = ProcessRequest::factory()->create(); |
| 121 | + $zetaRequest->forceFill(['case_title' => 'Zeta mandate'])->saveQuietly(); |
| 122 | + $alphaRequest->forceFill(['case_title' => 'Alpha mandate'])->saveQuietly(); |
| 123 | + $otherRequest->forceFill(['case_title' => 'Omega mandate'])->saveQuietly(); |
| 124 | + |
| 125 | + $zetaTask = ProcessRequestToken::factory()->create([ |
| 126 | + 'user_id' => $this->user->id, |
| 127 | + 'process_id' => $zetaRequest->process_id, |
| 128 | + 'process_request_id' => $zetaRequest->id, |
| 129 | + 'element_name' => 'Review of the client name', |
| 130 | + 'element_type' => 'task', |
| 131 | + 'status' => 'ACTIVE', |
| 132 | + 'is_self_service' => false, |
| 133 | + 'is_priority' => true, |
| 134 | + 'completed_at' => null, |
| 135 | + ]); |
| 136 | + $alphaTask = ProcessRequestToken::factory()->create([ |
| 137 | + 'user_id' => $this->user->id, |
| 138 | + 'process_id' => $alphaRequest->process_id, |
| 139 | + 'process_request_id' => $alphaRequest->id, |
| 140 | + 'element_type' => 'task', |
| 141 | + 'status' => 'ACTIVE', |
| 142 | + 'is_self_service' => false, |
| 143 | + 'is_priority' => true, |
| 144 | + 'completed_at' => null, |
| 145 | + ]); |
| 146 | + ProcessRequestToken::factory()->create([ |
| 147 | + 'user_id' => $otherUser->id, |
| 148 | + 'process_id' => $otherRequest->process_id, |
| 149 | + 'process_request_id' => $otherRequest->id, |
| 150 | + 'element_type' => 'task', |
| 151 | + 'status' => 'ACTIVE', |
| 152 | + 'is_self_service' => false, |
| 153 | + 'is_priority' => true, |
| 154 | + 'completed_at' => null, |
| 155 | + ]); |
| 156 | + |
| 157 | + $response = $this->apiCall('GET', '/tasks', [ |
| 158 | + 'page' => 1, |
| 159 | + 'include' => 'process,processRequest,processRequest.user,user', |
| 160 | + 'pmql' => '(user_id = ' . $this->user->id . ') AND (fulltext LIKE "%Review of the client name%") ', |
| 161 | + 'per_page' => 15, |
| 162 | + 'order_by' => 'process_requests.case_title', |
| 163 | + 'order_direction' => 'desc', |
| 164 | + 'non_system' => true, |
| 165 | + 'processesIManage' => 'false', |
| 166 | + 'advanced_filter' => json_encode([ |
| 167 | + [ |
| 168 | + 'subject' => ['type' => 'Status'], |
| 169 | + 'operator' => '=', |
| 170 | + 'value' => 'In Progress', |
| 171 | + ], |
| 172 | + [ |
| 173 | + 'subject' => ['type' => 'Field', 'value' => 'is_priority'], |
| 174 | + 'operator' => '=', |
| 175 | + 'value' => true, |
| 176 | + ], |
| 177 | + ]), |
| 178 | + ]); |
| 179 | + |
| 180 | + $response->assertStatus(200); |
| 181 | + |
| 182 | + $rows = $response->json('data'); |
| 183 | + $this->assertCount(1, $rows); |
| 184 | + $this->assertSame( |
| 185 | + [$zetaTask->id], |
| 186 | + array_column($rows, 'id') |
| 187 | + ); |
| 188 | + $this->assertSame( |
| 189 | + ['Zeta mandate'], |
| 190 | + array_map(fn ($row) => $row['process_request']['case_title'] ?? null, $rows) |
| 191 | + ); |
| 192 | + } |
| 193 | +} |
0 commit comments