61 lines
2.2 KiB
PHP
61 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature;
|
|
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Tests\TestCase;
|
|
|
|
class AdminPlatformOrderIndexSummaryStatusLinksShouldHaveDataRoleAndKeepBackTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
protected function loginAsPlatformAdmin(): void
|
|
{
|
|
$this->seed();
|
|
|
|
$this->post('/admin/login', [
|
|
'email' => 'platform.admin@demo.local',
|
|
'password' => 'Platform@123456',
|
|
])->assertRedirect('/admin');
|
|
}
|
|
|
|
public function test_platform_orders_index_summary_status_links_should_have_data_role_and_keep_back(): void
|
|
{
|
|
$this->loginAsPlatformAdmin();
|
|
|
|
$res = $this->get('/admin/platform-orders?merchant_id=1&back=/admin&page=2');
|
|
$res->assertOk();
|
|
|
|
$html = (string) $res->getContent();
|
|
|
|
$cases = [
|
|
['role' => 'po-summary-link-paid-orders', 'expect' => ['payment_status' => 'paid']],
|
|
['role' => 'po-summary-link-activated-orders', 'expect' => ['status' => 'activated']],
|
|
['role' => 'po-summary-link-synced-orders', 'expect' => ['sync_status' => 'synced']],
|
|
['role' => 'po-summary-link-unsynced-orders', 'expect' => ['sync_status' => 'unsynced']],
|
|
['role' => 'po-summary-link-sync-failed-orders', 'expect' => ['sync_status' => 'failed']],
|
|
];
|
|
|
|
foreach ($cases as $c) {
|
|
$role = (string) ($c['role'] ?? '');
|
|
$re = '/<a[^>]*data-role="' . preg_quote($role, '/') . '"[^>]*href="([^"]+)"/u';
|
|
$this->assertMatchesRegularExpression($re, $html);
|
|
preg_match($re, $html, $m);
|
|
|
|
$rawHref = (string) ($m[1] ?? '');
|
|
$this->assertStringNotContainsString('&back=', $rawHref);
|
|
|
|
$href = html_entity_decode($rawHref);
|
|
$query = parse_url($href, PHP_URL_QUERY) ?: '';
|
|
parse_str($query, $q);
|
|
|
|
foreach (($c['expect'] ?? []) as $k => $v) {
|
|
$this->assertSame((string) $v, (string) ($q[$k] ?? ''), $role . ' missing expected ' . $k);
|
|
}
|
|
|
|
$this->assertSame('/admin', (string) ($q['back'] ?? ''));
|
|
$this->assertArrayNotHasKey('page', $q);
|
|
}
|
|
}
|
|
}
|