Skip to content

Commit 1a86b30

Browse files
authored
Merge pull request #1143 from opensource-workshop/Test&Manual
マニュアルのテンプレートの対応
2 parents 894bfab + 6cde56a commit 1a86b30

File tree

7 files changed

+268
-7
lines changed

7 files changed

+268
-7
lines changed

resources/views/manual/method.blade.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
<img src="./images/{{basename($img_arg["path"])}}.png" class="img-fluid img-manual"
2525
--}}
2626
@php
27-
$image_info = getimagesize(\Storage::disk("manual")->path("html/" . $img_arg["path"] . ".png"));
27+
// ここでは、まだ、manual 側に画像ができていないので、screenshot を参照。
28+
$image_info = getimagesize(\Storage::disk("screenshot")->path($img_arg["path"] . ".png"));
2829
$width = $image_info[0];
2930
if ($width > 980) {
3031
$width = 980;

resources/views/manual/pdf/method.blade.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
<table nobr="true">
1111
<tr>
1212
@php
13-
$image_info = getimagesize(\Storage::disk("manual")->path("html/" . $img_arg["path"] . ".png"));
13+
// ここでは、まだ、manual 側に画像ができていないので、screenshot を参照。
14+
$image_info = getimagesize(\Storage::disk("screenshot")->path($img_arg["path"] . ".png"));
1415
$width = $image_info[0];
1516
if ($width > 800) {
1617
$td_width = [10, 80];

tests/Browser/User/CalendarsPluginTest.php

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use App\Enums\PluginName;
1010
use App\Models\Common\Frame;
1111
use App\Models\Common\Uploads;
12+
use App\Models\Core\Dusks;
1213
use App\Models\User\Calendars\Calendar;
1314
use App\Models\User\Calendars\CalendarPost;
1415

@@ -28,7 +29,7 @@ class CalendarsPluginTest extends DuskTestCase
2829
public function testBlog()
2930
{
3031
// 最初にマニュアルの順番確定用にメソッドを指定する。
31-
$this->reserveManual('index', 'show', 'edit', 'createBuckets', 'listBuckets');
32+
$this->reserveManual('index', 'show', 'edit', 'template', 'createBuckets', 'listBuckets');
3233

3334
$this->login(1);
3435

@@ -41,8 +42,9 @@ public function testBlog()
4142
$this->edit();
4243

4344
$this->logout();
44-
$this->index(); // 記事一覧
45-
$this->show(); // 記事詳細
45+
$this->index(); // 記事一覧
46+
$this->show(); // 記事詳細
47+
$this->template(); // テンプレート
4648
}
4749

4850
/**
@@ -188,4 +190,13 @@ private function listBuckets()
188190
}
189191
]');
190192
}
193+
194+
/**
195+
* テンプレート
196+
*/
197+
private function template()
198+
{
199+
Dusks::where('plugin_name', 'calendars')->where('method_name', 'template')->delete();
200+
$this->putManualTemplateData($this->test_frame, 'user', '/test/calendar', ['calendars', 'カレンダー'], ['day' => '日表示', 'small_month' => '月表示(小)']);
201+
}
191202
}
Lines changed: 191 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
1+
<?php
2+
3+
namespace Tests\Browser\User;
4+
5+
use Illuminate\Foundation\Testing\DatabaseMigrations;
6+
use Laravel\Dusk\Browser;
7+
use Tests\DuskTestCase;
8+
9+
use App\Enums\PluginName;
10+
use App\Models\Common\Frame;
11+
use App\Models\Common\Uploads;
12+
use App\Models\User\Calendars\Slideshow;
13+
use App\Models\User\Calendars\SlideshowsItems;
14+
15+
/**
16+
* スライドショーテスト
17+
*
18+
* @see https://github.com/opensource-workshop/connect-cms/wiki/Dusk#テスト実行 [How to test]
19+
*/
20+
class SlideshowsPluginTest extends DuskTestCase
21+
{
22+
/**
23+
* スライドショーテスト
24+
*
25+
* @group user
26+
* @see https://readouble.com/laravel/6.x/ja/dusk.html#running-tests
27+
*/
28+
public function testSlideshow()
29+
{
30+
// 最初にマニュアルの順番確定用にメソッドを指定する。
31+
$this->reserveManual('index', 'createBuckets', 'editItem', 'listBuckets');
32+
33+
$this->login(1);
34+
35+
// プラグインが配置されていなければ追加(テストするFrameとページのインスタンス変数への保持も)
36+
$this->addPluginFirst('calendars', '/test/slideshow', 2);
37+
38+
$this->createBuckets();
39+
$this->listBuckets();
40+
41+
$this->edit();
42+
43+
$this->logout();
44+
$this->index(); // 記事一覧
45+
$this->show(); // 記事詳細
46+
}
47+
48+
/**
49+
* インデックス
50+
*/
51+
private function index()
52+
{
53+
// 実行
54+
$this->browse(function (Browser $browser) {
55+
$browser->visit('/test/calendar')
56+
->assertPathBeginsWith('/')
57+
->screenshot('user/calendars/index/images/index1');
58+
59+
$browser->resize(400, 800);
60+
61+
$browser->visit('/test/calendar')
62+
->assertPathBeginsWith('/')
63+
->screenshot('user/calendars/index/images/index2');
64+
65+
$browser->resize(1280, 800);
66+
});
67+
68+
// マニュアル用データ出力
69+
$this->putManualData('[
70+
{"path": "user/calendars/index/images/index1",
71+
"name": "月表示",
72+
"comment": "<ul class=\"mb-0\"><li>月表示のカレンダー上に予定が表示されます。</li></ul>"
73+
},
74+
{"path": "user/calendars/index/images/index2",
75+
"name": "月表示(スマホ表示)",
76+
"comment": "<ul class=\"mb-0\"><li>スマートフォンの場合は縦長のカレンダーに予定が表示されます。</li></ul>"
77+
}
78+
]');
79+
}
80+
81+
/**
82+
* 予定登録
83+
*/
84+
private function edit($title = null)
85+
{
86+
// ブログ(バケツ)があって且つ、その月に記事が3件未満の場合に記事作成
87+
$ym = date("Y-m");
88+
if (Frame::where('plugin_name', 'blogs')->first() && CalendarPost::where('start_date', 'like', $ym . '%')->count() < 3) {
89+
// 実行
90+
$this->browse(function (Browser $browser) use ($ym) {
91+
$browser->visit('plugin/calendars/edit/' . $this->test_frame->page_id . '/' . $this->test_frame->id . '?date=' . $ym . '-01#frame-' . $this->test_frame->id)
92+
->assertPathBeginsWith('/')
93+
->type('title', 'テストの予定')
94+
->type('start_time', '10:00')
95+
->type('end_date', $ym . '-01')
96+
->type('end_time', '12:00')
97+
->screenshot('user/calendars/edit/images/edit1')
98+
->press('登録確定');
99+
100+
$browser->visit('plugin/calendars/edit/' . $this->test_frame->page_id . '/' . $this->test_frame->id . '?date=' . $ym . '-08#frame-' . $this->test_frame->id)
101+
->assertPathBeginsWith('/')
102+
->type('title', 'テストの予定2')
103+
->click('#label_allday_flag')
104+
->pause(500)
105+
->driver->executeScript('tinyMCE.get(0).setContent(\'この予定は全日予定です。\')');
106+
107+
$browser->screenshot('user/calendars/edit/images/edit2')
108+
->press('登録確定');
109+
110+
$browser->visit('plugin/calendars/edit/' . $this->test_frame->page_id . '/' . $this->test_frame->id . '?date=' . $ym . '-20#frame-' . $this->test_frame->id)
111+
->assertPathBeginsWith('/')
112+
->type('title', 'テストの予定3')
113+
->type('start_time', '12:00')
114+
->type('end_date', $ym . '-21')
115+
->type('end_time', '18:00')
116+
->screenshot('user/calendars/edit/images/edit3')
117+
->press('登録確定');
118+
});
119+
}
120+
121+
// マニュアル用データ出力(記事の登録はしていなくても、画像データはできているはず。reserveManual() で一旦、内容がクリアされているので、画像の登録は行う)
122+
$this->putManualData('[
123+
{"path": "user/calendars/edit/images/edit1",
124+
"comment": "<ul class=\"mb-0\"><li>カレンダーに予定を登録できます。</li><li>タイトル、開始日時、終了日時、本文が登録できます。</li><li>全日予定にすると、時間のない予定として登録できます。</li></ul>"
125+
}
126+
]');
127+
}
128+
129+
/**
130+
* 予定詳細
131+
*/
132+
private function show()
133+
{
134+
// 実行
135+
$this->browse(function (Browser $browser) {
136+
// データ取得
137+
$post = CalendarPost::where('start_date', date("Y-m-01"))->first();
138+
$browser->visit('plugin/calendars/show/' . $this->test_frame->page_id . '/' . $this->test_frame->id . '/' . $post->id . '#frame-' . $this->test_frame->id)
139+
->assertPathBeginsWith('/')
140+
->screenshot('user/calendars/show/images/show');
141+
});
142+
143+
// マニュアル用データ出力
144+
$this->putManualData('user/calendars/show/images/show');
145+
}
146+
147+
/**
148+
* バケツ作成
149+
*/
150+
private function createBuckets()
151+
{
152+
// バケツがなければ作成する。(プラグイン&フレームの配置まではできているはず)
153+
if (Calendar::count() == 0) {
154+
// 実行
155+
$this->browse(function (Browser $browser) {
156+
$browser->visit('/plugin/calendars/createBuckets/' . $this->test_frame->page_id . '/' . $this->test_frame->id . '#frame-' . $this->test_frame->id)
157+
->assertPathBeginsWith('/')
158+
->type('name', 'テストのカレンダー')
159+
->screenshot('user/calendars/createBuckets/images/createBuckets')
160+
->press('登録確定');
161+
});
162+
}
163+
164+
// マニュアル用データ出力
165+
$this->putManualData('[
166+
{"path": "user/calendars/createBuckets/images/createBuckets",
167+
"comment": "<ul class=\"mb-0\"><li>カレンダー枠を作成して、その枠に予定を登録できます。</li><li>カレンダー枠は複数作成できるため、別の用途のカレンダーを作成することができます。</li></ul>"
168+
}
169+
]');
170+
}
171+
172+
/**
173+
* ブログ選択
174+
*/
175+
private function listBuckets()
176+
{
177+
// 実行
178+
$this->browse(function (Browser $browser) {
179+
$browser->visit('/plugin/calendars/listBuckets/' . $this->test_frame->page_id . '/' . $this->test_frame->id . '#frame-' . $this->test_frame->id)
180+
->assertPathBeginsWith('/')
181+
->screenshot('user/calendars/listBuckets/images/listBuckets');
182+
});
183+
184+
// マニュアル用データ出力
185+
$this->putManualData('[
186+
{"path": "user/calendars/listBuckets/images/listBuckets",
187+
"comment": "<ul class=\"mb-0\"><li>表示するカレンダーを変更できます。</li></ul>"
188+
}
189+
]');
190+
}
191+
}

tests/DuskTestCase.php

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,8 +340,10 @@ private function getDocument($annotation_name, $class_name, $method_name = null)
340340
{
341341
if ($method_name == null) {
342342
$class = new \ReflectionClass($class_name);
343-
} else {
343+
} elseif (method_exists($class_name, $method_name)) {
344344
$class = new \ReflectionMethod($class_name, $method_name);
345+
} else {
346+
return "";
345347
}
346348
$class_document = $class->getDocComment();
347349
return trim($this->getAnnotation($class_document, $annotation_name));
@@ -414,4 +416,57 @@ public function putManualData($img_args = null, $method = null)
414416
$dusk->save();
415417
}
416418
}
419+
420+
/**
421+
* マニュアルデータ(テンプレート変更)出力
422+
*/
423+
public function putManualTemplateData($frame, $category, $test_path, $plugin, $templates)
424+
{
425+
// 画像関係パス
426+
$img_args = "";
427+
428+
// テンプレートの数だけループしながら、スクリーンショット取得
429+
foreach ($templates as $template_name => $template_desc) {
430+
// フレームのテンプレート名を修正する。
431+
$frame->template = $template_name;
432+
$frame->save();
433+
434+
// 指定のURLを表示し、スクリーンショットを取る。
435+
$this->browse(function (Browser $browser) use ($category, $test_path, $plugin, $template_name) {
436+
$browser->visit($test_path)
437+
->assertPathBeginsWith('/')
438+
->screenshot($category . '/' . $plugin[0] . '/template/images/' . $template_name);
439+
});
440+
441+
$img_args .=<<< EOF
442+
{"path": "{$category}/{$plugin[0]}/template/images/{$template_name}",
443+
"name": "{$template_desc}"
444+
}
445+
EOF;
446+
if (array_key_last($templates) != $template_name) {
447+
$img_args .= ",";
448+
}
449+
}
450+
451+
// テンプレートを標準に戻す。
452+
$frame->template = "default";
453+
$frame->save();
454+
455+
// マニュアル用データ出力
456+
$dusk = Dusks::putManualData(
457+
['html_path' => $category . '/' . $plugin[0] . '/template/index.html'],
458+
['category' => $category,
459+
'sort' => 2,
460+
'plugin_name' => $plugin[0],
461+
'plugin_title' => $plugin[1],
462+
'plugin_desc' => '',
463+
'method_name' => 'template',
464+
'method_title' => 'テンプレート',
465+
'method_desc' => 'テンプレート変更時の表示結果を紹介します。',
466+
'method_detail' => '',
467+
'html_path' => $category . '/' . $plugin[0] . '/template/index.html',
468+
'img_args' => '[' . $img_args . ']',
469+
'test_result' => 'OK']
470+
);
471+
}
417472
}

tests/Manual/src/ManualOutput.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,6 @@ private function outputImage($method)
218218
} else {
219219
// 画像をコピー
220220
foreach (explode(',', $method->img_args) as $img_path) {
221-
222221
if (!\Storage::disk('manual')->exists('html/' . dirname($img_path))) {
223222
\Storage::disk('manual')->makeDirectory('html/' . dirname($img_path));
224223
}

tests/bin/connect-cms-test.bat

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,9 @@ php artisan dusk tests\Browser\User\BlogsPluginTest.php
173173
echo --- カレンダー
174174
php artisan dusk tests\Browser\User\CalendarsPluginTest.php
175175

176+
echo --- スライドショー
177+
rem php artisan dusk tests\Browser\User\SlideshowsPluginTest.php
178+
176179
echo --- フォトアルバム
177180
rem php artisan dusk tests\Browser\User\PhotoalbumsPluginTest.php
178181

0 commit comments

Comments
 (0)