ver. 0.308: kolory statusow zamowien + poprawki bezpieczenstwa
- Kolorowe badge statusow na liscie zamowien (pp_shop_statuses.color) - Walidacja hex koloru z DB (regex), sanityzacja HTML transport - Polaczenie 2 zapytan SQL w jedno orderStatusData() - Path-based form submit w table-list.php (admin URL routing) - 11 nowych testow (750 total, 2114 assertions) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -29,6 +29,66 @@ class OrderRepositoryTest extends TestCase
|
||||
$this->assertSame('W realizacji', $statuses[4]);
|
||||
}
|
||||
|
||||
public function testOrderStatusDataReturnsBothNamesAndColors(): void
|
||||
{
|
||||
$mockDb = $this->createMock(\medoo::class);
|
||||
$mockDb->method('select')
|
||||
->willReturnCallback(function ($table, $columns, $where) {
|
||||
if ($table === 'pp_shop_statuses') {
|
||||
return [
|
||||
['id' => 0, 'status' => 'Nowe', 'color' => '#ff0000'],
|
||||
['id' => 4, 'status' => 'W realizacji', 'color' => '#00ff00'],
|
||||
['id' => 5, 'status' => 'Wysłane', 'color' => ''],
|
||||
];
|
||||
}
|
||||
return [];
|
||||
});
|
||||
|
||||
$repository = new OrderRepository($mockDb);
|
||||
$data = $repository->orderStatusData();
|
||||
|
||||
$this->assertArrayHasKey('names', $data);
|
||||
$this->assertArrayHasKey('colors', $data);
|
||||
$this->assertSame('Nowe', $data['names'][0]);
|
||||
$this->assertSame('W realizacji', $data['names'][4]);
|
||||
$this->assertSame('Wysłane', $data['names'][5]);
|
||||
$this->assertSame('#ff0000', $data['colors'][0]);
|
||||
$this->assertSame('#00ff00', $data['colors'][4]);
|
||||
$this->assertArrayNotHasKey(5, $data['colors']);
|
||||
}
|
||||
|
||||
public function testOrderStatusDataFiltersInvalidHexColors(): void
|
||||
{
|
||||
$mockDb = $this->createMock(\medoo::class);
|
||||
$mockDb->method('select')
|
||||
->willReturn([
|
||||
['id' => 1, 'status' => 'OK', 'color' => '#abc'],
|
||||
['id' => 2, 'status' => 'Bad', 'color' => 'red'],
|
||||
['id' => 3, 'status' => 'XSS', 'color' => '#000" onclick="alert(1)'],
|
||||
['id' => 4, 'status' => 'Valid', 'color' => '#AABBCC'],
|
||||
]);
|
||||
|
||||
$repository = new OrderRepository($mockDb);
|
||||
$data = $repository->orderStatusData();
|
||||
|
||||
$this->assertSame('#abc', $data['colors'][1]);
|
||||
$this->assertArrayNotHasKey(2, $data['colors']);
|
||||
$this->assertArrayNotHasKey(3, $data['colors']);
|
||||
$this->assertSame('#AABBCC', $data['colors'][4]);
|
||||
}
|
||||
|
||||
public function testOrderStatusDataReturnsEmptyOnDbFailure(): void
|
||||
{
|
||||
$mockDb = $this->createMock(\medoo::class);
|
||||
$mockDb->method('select')->willReturn(false);
|
||||
|
||||
$repository = new OrderRepository($mockDb);
|
||||
$data = $repository->orderStatusData();
|
||||
|
||||
$this->assertSame([], $data['names']);
|
||||
$this->assertSame([], $data['colors']);
|
||||
}
|
||||
|
||||
public function testNextAndPrevOrderIdReturnNullForInvalidInput(): void
|
||||
{
|
||||
$mockDb = $this->createMock(\medoo::class);
|
||||
|
||||
Reference in New Issue
Block a user