|
@@ -77,9 +77,9 @@ class PromotionActivitiesTest extends TestCase
|
|
|
}
|
|
}
|
|
|
private function texts(): array
|
|
private function texts(): array
|
|
|
{
|
|
{
|
|
|
- return ['zh' => ['title' => '测试活动', 'sub_title' => '规则', 'content' => '<p>中文活动正文</p>'],
|
|
|
|
|
- 'en' => ['title' => 'Test promotion', 'sub_title' => 'English subtitle', 'content' => '<p>English content</p>'],
|
|
|
|
|
- 'vi' => ['title' => 'Khuyến mãi', 'sub_title' => 'Phụ đề', 'content' => '<p>Nội dung</p>']];
|
|
|
|
|
|
|
+ return ['zh' => ['title' => '测试活动', 'content' => '<p>中文活动正文</p>'],
|
|
|
|
|
+ 'en' => ['title' => 'Test promotion', 'content' => '<p>English content</p>'],
|
|
|
|
|
+ 'vi' => ['title' => 'Khuyến mãi', 'content' => '<p>Nội dung</p>']];
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private function deposit(int $id, string $amount, ?string $time = null, string $type = '充值'): BalanceLog
|
|
private function deposit(int $id, string $amount, ?string $time = null, string $type = '充值'): BalanceLog
|
|
@@ -125,24 +125,46 @@ class PromotionActivitiesTest extends TestCase
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ public function test_subtitles_are_not_required_saved_or_returned_for_any_independent_activity(): void
|
|
|
|
|
+ {
|
|
|
|
|
+ $admin = new PromotionAdminService();
|
|
|
|
|
+ foreach ([7, 8, 9] as $type) {
|
|
|
|
|
+ $id = $this->activity($type); $legacy = $this->texts();
|
|
|
|
|
+ foreach ($legacy as &$text) $text['sub_title'] = 'Historical subtitle'; unset($text);
|
|
|
|
|
+ DB::table('promotion_activities')->where('id', $id)->update(['sub_title' => 'Historical subtitle', 'translations' => json_encode($legacy)]);
|
|
|
|
|
+ $detail = $admin->detail($id);
|
|
|
|
|
+ $this->assertArrayNotHasKey('sub_title', $detail);
|
|
|
|
|
+ foreach ($detail['translations'] as $text) $this->assertSame(['title', 'content'], array_keys($text));
|
|
|
|
|
+ $input = $detail; $input['sub_title'] = 'Ignored legacy input';
|
|
|
|
|
+ foreach ($input['translations'] as &$text) $text['sub_title'] = ['ignored legacy input']; unset($text);
|
|
|
|
|
+ $saved = $admin->save($input);
|
|
|
|
|
+ $this->assertSame($this->texts(), $saved['translations']);
|
|
|
|
|
+ $this->assertSame('Historical subtitle', DB::table('promotion_activities')->where('id', $id)->value('sub_title'));
|
|
|
|
|
+ foreach ([$saved, $admin->listing(['type' => $type])['data'][0], $admin->status($id, 1),
|
|
|
|
|
+ $this->service->listing(1, 'H5', 'zh', $type)['data'][0], $this->service->detail($id, 1, 'H5', 'zh')] as $row) {
|
|
|
|
|
+ $this->assertArrayNotHasKey('sub_title', $row);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
public function test_three_languages_edit_one_campaign_and_keep_rules_history_and_other_tabs(): void
|
|
public function test_three_languages_edit_one_campaign_and_keep_rules_history_and_other_tabs(): void
|
|
|
{
|
|
{
|
|
|
$admin = new PromotionAdminService();
|
|
$admin = new PromotionAdminService();
|
|
|
foreach ([7, 8, 9] as $type) {
|
|
foreach ([7, 8, 9] as $type) {
|
|
|
$id = $this->activity($type); $before = $admin->detail($id);
|
|
$id = $this->activity($type); $before = $admin->detail($id);
|
|
|
$count = DB::table('promotion_activities')->count();
|
|
$count = DB::table('promotion_activities')->count();
|
|
|
- $input = $before; $input['translations']['en']['sub_title'] = 'Updated English subtitle';
|
|
|
|
|
|
|
+ $input = $before; $input['translations']['en']['title'] = 'Updated English title';
|
|
|
$saved = $admin->save($input);
|
|
$saved = $admin->save($input);
|
|
|
$this->assertSame($id, $saved['id']);
|
|
$this->assertSame($id, $saved['id']);
|
|
|
$this->assertSame($count, DB::table('promotion_activities')->count());
|
|
$this->assertSame($count, DB::table('promotion_activities')->count());
|
|
|
$this->assertSame($before['translations']['zh'], $saved['translations']['zh']);
|
|
$this->assertSame($before['translations']['zh'], $saved['translations']['zh']);
|
|
|
$this->assertSame($before['translations']['vi'], $saved['translations']['vi']);
|
|
$this->assertSame($before['translations']['vi'], $saved['translations']['vi']);
|
|
|
- $this->assertSame('Updated English subtitle', $admin->detail($id)['translations']['en']['sub_title']);
|
|
|
|
|
|
|
+ $this->assertSame('Updated English title', $admin->detail($id)['translations']['en']['title']);
|
|
|
foreach (['params', 'rewarded_count', 'budget_used', 'first_published_at'] as $field) $this->assertSame($before[$field], $saved[$field]);
|
|
foreach (['params', 'rewarded_count', 'budget_used', 'first_published_at'] as $field) $this->assertSame($before[$field], $saved[$field]);
|
|
|
foreach (['zh', 'en', 'vi'] as $lang) {
|
|
foreach (['zh', 'en', 'vi'] as $lang) {
|
|
|
$rows = $this->service->listing(1, 'H5', $lang, $type)['data'];
|
|
$rows = $this->service->listing(1, 'H5', $lang, $type)['data'];
|
|
|
$this->assertCount(1, $rows); $this->assertSame($id, $rows[0]['activity_id']);
|
|
$this->assertCount(1, $rows); $this->assertSame($id, $rows[0]['activity_id']);
|
|
|
- $this->assertSame($saved['translations'][$lang]['sub_title'], $rows[0]['sub_title']);
|
|
|
|
|
|
|
+ $this->assertSame($saved['translations'][$lang]['title'], $rows[0]['title']);
|
|
|
$state = $this->service->detail($id, 1, 'H5', $lang);
|
|
$state = $this->service->detail($id, 1, 'H5', $lang);
|
|
|
$this->assertSame($lang, $state['lang']);
|
|
$this->assertSame($lang, $state['lang']);
|
|
|
$this->assertSame($saved['translations'][$lang]['title'], $state['title']);
|
|
$this->assertSame($saved['translations'][$lang]['title'], $state['title']);
|
|
@@ -152,12 +174,12 @@ class PromotionActivitiesTest extends TestCase
|
|
|
$this->assertSame(['zh', 'en', 'vi'], array_column($admin->options()['languages'], 'value'));
|
|
$this->assertSame(['zh', 'en', 'vi'], array_column($admin->options()['languages'], 'value'));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public function test_all_nine_text_fields_are_required_and_invalid_tabs_cannot_overwrite_saved_content(): void
|
|
|
|
|
|
|
+ public function test_all_six_text_fields_are_required_and_invalid_tabs_cannot_overwrite_saved_content(): void
|
|
|
{
|
|
{
|
|
|
$id = $this->activity(9); $admin = new PromotionAdminService(); $input = $admin->detail($id);
|
|
$id = $this->activity(9); $admin = new PromotionAdminService(); $input = $admin->detail($id);
|
|
|
$before = DB::table('promotion_activities')->where('id', $id)->first();
|
|
$before = DB::table('promotion_activities')->where('id', $id)->first();
|
|
|
foreach (['zh', 'en', 'vi'] as $lang) {
|
|
foreach (['zh', 'en', 'vi'] as $lang) {
|
|
|
- foreach (['title', 'sub_title', 'content'] as $field) {
|
|
|
|
|
|
|
+ foreach (['title', 'content'] as $field) {
|
|
|
$bad = $input; unset($bad['translations'][$lang][$field]);
|
|
$bad = $input; unset($bad['translations'][$lang][$field]);
|
|
|
try { $admin->save($bad); $this->fail('Missing language text was accepted'); }
|
|
try { $admin->save($bad); $this->fail('Missing language text was accepted'); }
|
|
|
catch (ValidationException $e) { $this->assertTrue($e->validator->errors()->has('translations.' . $lang . '.' . $field)); }
|
|
catch (ValidationException $e) { $this->assertTrue($e->validator->errors()->has('translations.' . $lang . '.' . $field)); }
|
|
@@ -172,9 +194,9 @@ class PromotionActivitiesTest extends TestCase
|
|
|
$bad = $input; $bad['translations']['fr'] = $input['translations']['en'];
|
|
$bad = $input; $bad['translations']['fr'] = $input['translations']['en'];
|
|
|
try { $admin->save($bad); $this->fail('Unknown language was accepted'); }
|
|
try { $admin->save($bad); $this->fail('Unknown language was accepted'); }
|
|
|
catch (ValidationException $e) { $this->assertTrue($e->validator->errors()->has('translations')); }
|
|
catch (ValidationException $e) { $this->assertTrue($e->validator->errors()->has('translations')); }
|
|
|
- $bad = $input; $bad['translations']['en']['sub_title'] = str_repeat('a', 201);
|
|
|
|
|
- try { $admin->save($bad); $this->fail('Oversized subtitle was accepted'); }
|
|
|
|
|
- catch (ValidationException $e) { $this->assertTrue($e->validator->errors()->has('translations.en.sub_title')); }
|
|
|
|
|
|
|
+ $bad = $input; $bad['translations']['en']['title'] = str_repeat('a', 141);
|
|
|
|
|
+ try { $admin->save($bad); $this->fail('Oversized title was accepted'); }
|
|
|
|
|
+ catch (ValidationException $e) { $this->assertTrue($e->validator->errors()->has('translations.en.title')); }
|
|
|
$this->assertEquals($before, DB::table('promotion_activities')->where('id', $id)->first());
|
|
$this->assertEquals($before, DB::table('promotion_activities')->where('id', $id)->first());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -229,7 +251,7 @@ class PromotionActivitiesTest extends TestCase
|
|
|
foreach ((array) $row as $field => $value) $this->assertSame($value, $saved->$field);
|
|
foreach ((array) $row as $field => $value) $this->assertSame($value, $saved->$field);
|
|
|
}
|
|
}
|
|
|
$texts = (new PromotionAdminService())->detail((int) $id)['translations'];
|
|
$texts = (new PromotionAdminService())->detail((int) $id)['translations'];
|
|
|
- $this->assertSame(['title' => 'Existing title', 'sub_title' => 'Existing subtitle', 'content' => '<p>Existing content</p>'], $texts['en']);
|
|
|
|
|
|
|
+ $this->assertSame(['title' => 'Existing title', 'content' => '<p>Existing content</p>'], $texts['en']);
|
|
|
$this->assertSame('', $texts['zh']['title']);
|
|
$this->assertSame('', $texts['zh']['title']);
|
|
|
$this->assertEquals($published, DB::table('promotion_campaigns')->orderBy('activity_id')->get());
|
|
$this->assertEquals($published, DB::table('promotion_campaigns')->orderBy('activity_id')->get());
|
|
|
$this->assertSame(0, DB::table('menus')->count());
|
|
$this->assertSame(0, DB::table('menus')->count());
|