|
@@ -196,28 +196,76 @@ class BannerPublicationTest extends TestCase
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public function test_manual_status_takes_precedence_in_full_forms_and_status_requests(): void
|
|
|
|
|
|
|
+ public function test_status_takes_precedence_with_manual_status_as_fallback_in_forms_and_status_requests(): void
|
|
|
{
|
|
{
|
|
|
foreach ([
|
|
foreach ([
|
|
|
[['manual_status' => 0], 0],
|
|
[['manual_status' => 0], 0],
|
|
|
[['status' => 1], 1],
|
|
[['status' => 1], 1],
|
|
|
[['manual_status' => null], 1],
|
|
[['manual_status' => null], 1],
|
|
|
[['status' => 1, 'manual_status' => null], 1],
|
|
[['status' => 1, 'manual_status' => null], 1],
|
|
|
- [['status' => 0, 'manual_status' => 1], 1],
|
|
|
|
|
- [['status' => 1, 'manual_status' => 0], 0],
|
|
|
|
|
|
|
+ [['status' => 0, 'manual_status' => 1], 0],
|
|
|
|
|
+ [['status' => 1, 'manual_status' => 0], 1],
|
|
|
] as [$fields, $expected]) {
|
|
] as [$fields, $expected]) {
|
|
|
$result = $this->save($fields);
|
|
$result = $this->save($fields);
|
|
|
$this->assertSame(HttpStatus::OK, $result['code'], $result['msg']);
|
|
$this->assertSame(HttpStatus::OK, $result['code'], $result['msg']);
|
|
|
$id = DB::table('banner')->latest('id')->value('id');
|
|
$id = DB::table('banner')->latest('id')->value('id');
|
|
|
$this->assertSame($expected, (int) DB::table('banner')->where('id', $id)->value('status'));
|
|
$this->assertSame($expected, (int) DB::table('banner')->where('id', $id)->value('status'));
|
|
|
}
|
|
}
|
|
|
- foreach ([[0, 1], [1, 0]] as [$legacy, $manual]) {
|
|
|
|
|
- $result = $this->status(['id' => $id, 'status' => $legacy, 'manual_status' => $manual]);
|
|
|
|
|
|
|
+ foreach ([[0, 1], [1, 0]] as [$canonical, $manual]) {
|
|
|
|
|
+ $result = $this->status(['id' => $id, 'status' => $canonical, 'manual_status' => $manual]);
|
|
|
$this->assertSame(HttpStatus::OK, $result['code'], $result['msg']);
|
|
$this->assertSame(HttpStatus::OK, $result['code'], $result['msg']);
|
|
|
- $this->assertSame($manual, (int) DB::table('banner')->where('id', $id)->value('status'));
|
|
|
|
|
- $result = $this->save(['id' => $id, 'title' => '兼容完整编辑', 'status' => $legacy, 'manual_status' => $manual]);
|
|
|
|
|
|
|
+ $this->assertSame($canonical, (int) DB::table('banner')->where('id', $id)->value('status'));
|
|
|
|
|
+ $result = $this->save(['id' => $id, 'title' => '兼容完整编辑', 'status' => $canonical, 'manual_status' => $manual]);
|
|
|
$this->assertSame(HttpStatus::OK, $result['code'], $result['msg']);
|
|
$this->assertSame(HttpStatus::OK, $result['code'], $result['msg']);
|
|
|
- $this->assertSame($manual, (int) DB::table('banner')->where('id', $id)->value('status'));
|
|
|
|
|
|
|
+ $this->assertSame($canonical, (int) DB::table('banner')->where('id', $id)->value('status'));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public function test_unbound_list_row_edits_and_buttons_follow_changed_status_over_stale_manual_alias(): void
|
|
|
|
|
+ {
|
|
|
|
|
+ $ids = [];
|
|
|
|
|
+ foreach ([null, '', '0', 'https://example.test/promotion'] as $link) {
|
|
|
|
|
+ $ids[] = $this->banner(['link' => $link, 'status' => 1]);
|
|
|
|
|
+ }
|
|
|
|
|
+ $orderedIds = array_reverse($ids);
|
|
|
|
|
+ $assertPublication = function (int $id, int $expected) use ($orderedIds): array {
|
|
|
|
|
+ $rows = collect($this->listing()['data'])->keyBy('id')->all();
|
|
|
|
|
+ $this->assertState($rows[$id], $expected, $expected, $expected ? null : 'manual', null);
|
|
|
|
|
+ $this->assertSame($expected, (int) DB::table('banner')->where('id', $id)->value('status'));
|
|
|
|
|
+ $downIds = $expected ? [] : [$id];
|
|
|
|
|
+ $upIds = array_values(array_diff($orderedIds, $downIds));
|
|
|
|
|
+ foreach ([['0', $downIds], ['1', $upIds]] as [$status, $expectedIds]) {
|
|
|
|
|
+ $page = $this->listing(['status' => $status]);
|
|
|
|
|
+ $this->assertSame(count($expectedIds), $page['total']);
|
|
|
|
|
+ $this->assertSame($expectedIds, array_column($page['data'], 'id'));
|
|
|
|
|
+ }
|
|
|
|
|
+ return $rows[$id];
|
|
|
|
|
+ };
|
|
|
|
|
+ foreach ($ids as $id) {
|
|
|
|
|
+ $row = $assertPublication($id, 1);
|
|
|
|
|
+ $originalLink = $row['link'];
|
|
|
|
|
+ $row['status'] = 0;
|
|
|
|
|
+ $row['title'] = '列表编辑下架';
|
|
|
|
|
+ $this->assertSame(1, $row['manual_status']);
|
|
|
|
|
+ $result = $this->save($row);
|
|
|
|
|
+ $this->assertSame(HttpStatus::OK, $result['code'], $result['msg']);
|
|
|
|
|
+ $row = $assertPublication($id, 0);
|
|
|
|
|
+
|
|
|
|
|
+ $result = $this->status(['id' => $id, 'status' => 1, 'manual_status' => $row['manual_status']]);
|
|
|
|
|
+ $this->assertSame(HttpStatus::OK, $result['code'], $result['msg']);
|
|
|
|
|
+ $row = $assertPublication($id, 1);
|
|
|
|
|
+ $result = $this->status(['id' => $id, 'status' => 0, 'manual_status' => $row['manual_status']]);
|
|
|
|
|
+ $this->assertSame(HttpStatus::OK, $result['code'], $result['msg']);
|
|
|
|
|
+ $row = $assertPublication($id, 0);
|
|
|
|
|
+
|
|
|
|
|
+ $row['status'] = 1;
|
|
|
|
|
+ $row['title'] = '列表编辑上架';
|
|
|
|
|
+ $this->assertSame(0, $row['manual_status']);
|
|
|
|
|
+ $result = $this->save($row);
|
|
|
|
|
+ $this->assertSame(HttpStatus::OK, $result['code'], $result['msg']);
|
|
|
|
|
+ $row = $assertPublication($id, 1);
|
|
|
|
|
+ $this->assertSame('列表编辑上架', $row['title']);
|
|
|
|
|
+ $this->assertSame($originalLink, $row['link']);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -236,6 +284,14 @@ class BannerPublicationTest extends TestCase
|
|
|
$this->assertSame('轮播图', $row->title);
|
|
$this->assertSame('轮播图', $row->title);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+ foreach ([['status' => 1, 'manual_status' => 'invalid'], ['status' => 'invalid', 'manual_status' => 1]] as $fields) {
|
|
|
|
|
+ $result = $this->save($fields + ['id' => $id, 'title' => '不应保存']);
|
|
|
|
|
+ $this->assertSame(HttpStatus::VALIDATION_FAILED, $result['code']);
|
|
|
|
|
+ $result = $this->status($fields + ['id' => $id]);
|
|
|
|
|
+ $this->assertSame(HttpStatus::VALIDATION_FAILED, $result['code']);
|
|
|
|
|
+ $this->assertSame(0, (int) DB::table('banner')->where('id', $id)->value('status'));
|
|
|
|
|
+ $this->assertSame('轮播图', DB::table('banner')->where('id', $id)->value('title'));
|
|
|
|
|
+ }
|
|
|
$result = $this->save(['id' => $id, 'manual_status' => null, 'title' => '空值保持手动设置']);
|
|
$result = $this->save(['id' => $id, 'manual_status' => null, 'title' => '空值保持手动设置']);
|
|
|
$this->assertSame(HttpStatus::OK, $result['code'], $result['msg']);
|
|
$this->assertSame(HttpStatus::OK, $result['code'], $result['msg']);
|
|
|
$this->assertSame(0, (int) DB::table('banner')->where('id', $id)->value('status'));
|
|
$this->assertSame(0, (int) DB::table('banner')->where('id', $id)->value('status'));
|