|
| 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 | +} |
0 commit comments