Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
| 1 | <?php |
||
| 14 | class EA05CustomerCest |
||
| 15 | { |
||
| 16 | public function _before(\AcceptanceTester $I) |
||
| 17 | { |
||
| 18 | // すべてのテストケース実施前にログインしておく |
||
| 19 | // ログイン後は管理アプリのトップページに遷移している |
||
| 20 | $I->loginAsAdmin(); |
||
| 21 | } |
||
| 22 | |||
| 23 | public function _after(\AcceptanceTester $I) |
||
| 24 | { |
||
| 25 | } |
||
| 26 | |||
| 27 | public function customer_検索(\AcceptanceTester $I) |
||
| 28 | { |
||
| 29 | $I->wantTo('EA0501-UC01-T01 検索'); |
||
| 30 | |||
| 31 | |||
| 32 | $CustomerListPage = CustomerManagePage::go($I); |
||
| 33 | |||
| 34 | $createCustomer = Fixtures::get('createCustomer'); |
||
| 35 | $customer = $createCustomer(); |
||
| 36 | |||
| 37 | $CustomerListPage->検索($customer->getEmail()); |
||
| 38 | $I->see('検索結果:1件が該当しました', CustomerManagePage::$検索結果メッセージ); |
||
| 39 | } |
||
| 40 | |||
| 41 | public function customer_検索結果なし(\AcceptanceTester $I) |
||
| 42 | { |
||
| 43 | $I->wantTo('EA0501-UC01-T02 検索 結果なし'); |
||
| 44 | $faker = Fixtures::get('faker'); |
||
| 45 | $email = microtime(true).'.'.$faker->safeEmail; |
||
| 46 | |||
| 47 | CustomerManagePage::go($I) |
||
| 48 | ->検索($email); |
||
| 49 | |||
| 50 | $I->see('検索条件に合致するデータが見つかりませんでした', CustomerManagePage::$検索結果_結果なしメッセージ); |
||
| 51 | } |
||
| 52 | |||
| 53 | public function customer_検索エラー(\AcceptanceTester $I) |
||
| 54 | { |
||
| 55 | $I->wantTo('EA0501-UC01-T03 検索 エラー'); |
||
| 56 | |||
| 57 | CustomerManagePage::go($I) |
||
| 58 | ->詳細検索_電話番号('あああ'); |
||
| 59 | |||
| 60 | $I->see('検索条件に誤りがあります。', CustomerManagePage::$検索結果_エラーメッセージ); |
||
| 61 | } |
||
| 62 | |||
| 63 | public function customer_会員登録(\AcceptanceTester $I) |
||
| 64 | { |
||
| 65 | $I->wantTo('EA0502-UC01-T02(& UC01-T02) 会員登録'); |
||
| 66 | $faker = Fixtures::get('faker'); |
||
| 67 | $email = microtime(true).'.'.$faker->safeEmail; |
||
| 68 | |||
| 69 | $CustomerRegisterPage = CustomerEditPage::go($I) |
||
| 70 | ->入力_姓('testuser') |
||
| 71 | ->入力_名('testuser') |
||
| 72 | ->入力_セイ('テストユーザー') |
||
| 73 | ->入力_メイ('テストユーザー') |
||
| 74 | ->入力_都道府県(['27' => '大阪府']) |
||
| 75 | ->入力_郵便番号1('530') |
||
| 76 | ->入力_郵便番号2('0001') |
||
| 77 | ->入力_市区町村名('大阪市北区梅田2-4-9') |
||
| 78 | ->入力_番地_ビル名('ブリーゼタワー13F') |
||
| 79 | ->入力_Eメール($email) |
||
| 80 | ->入力_電話番号1('111') |
||
| 81 | ->入力_電話番号2('111') |
||
| 82 | ->入力_電話番号3('111') |
||
| 83 | ->入力_パスワード('password') |
||
| 84 | ->入力_パスワード確認('password'); |
||
| 85 | |||
| 86 | $findPluginByCode = Fixtures::get('findPluginByCode'); |
||
| 87 | $Plugin = $findPluginByCode('MailMagazine'); |
||
| 88 | if ($Plugin) { |
||
| 89 | $I->amGoingTo('メルマガプラグインを発見したため、メルマガを購読します'); |
||
| 90 | $I->click('#admin_customer_mailmaga_flg_0'); |
||
| 91 | } |
||
| 92 | |||
| 93 | $CustomerRegisterPage->登録(); |
||
| 94 | /* ブラウザによるhtml5のエラーなのでハンドリング不可 */ |
||
| 95 | $I->see('会員情報を保存しました。', CustomerEditPage::$登録完了メッセージ); } |
||
| 96 | |||
| 97 | public function customer_会員登録_必須項目未入力(\AcceptanceTester $I) |
||
| 98 | { |
||
| 99 | $I->wantTo('EA0502-UC01-T02 会員登録_必須項目未入力'); |
||
| 100 | |||
| 101 | CustomerEditPage::go($I)->登録(); |
||
| 102 | |||
| 103 | $I->seeElement(['css' => '#admin_customer_name_name01:invalid']); // 姓がエラー |
||
| 104 | $I->dontSeeElement(CustomerEditPage::$登録完了メッセージ); |
||
| 105 | } |
||
| 106 | |||
| 107 | public function customer_会員編集(\AcceptanceTester $I) |
||
| 108 | { |
||
| 109 | $I->wantTo('EA0502-UC02-T01 会員編集'); |
||
| 110 | |||
| 111 | $createCustomer = Fixtures::get('createCustomer'); |
||
| 112 | $customer = $createCustomer(); |
||
| 113 | |||
| 114 | $CustomerListPage = CustomerManagePage::go($I) |
||
| 115 | ->検索($customer->getEmail()); |
||
| 116 | |||
| 117 | $I->see('検索結果:1件が該当しました', CustomerManagePage::$検索結果メッセージ); |
||
| 118 | |||
| 119 | $CustomerListPage->一覧_編集(1); |
||
| 120 | |||
| 121 | $CustomerRegisterPage = CustomerEditPage::at($I) |
||
| 122 | ->入力_姓('testuser-1'); |
||
| 123 | |||
| 124 | $findPluginByCode = Fixtures::get('findPluginByCode'); |
||
| 125 | $Plugin = $findPluginByCode('MailMagazine'); |
||
| 126 | if ($Plugin) { |
||
| 127 | $I->amGoingTo('メルマガプラグインを発見したため、メルマガを購読します'); |
||
| 128 | $I->click('#admin_customer_mailmaga_flg_0'); |
||
| 129 | } |
||
| 130 | |||
| 131 | $CustomerRegisterPage->登録(); |
||
| 132 | $I->see('会員情報を保存しました。', CustomerEditPage::$登録完了メッセージ); |
||
| 133 | |||
| 134 | $CustomerRegisterPage |
||
| 135 | ->入力_姓('') |
||
| 136 | ->登録(); |
||
| 137 | } |
||
| 138 | |||
| 139 | public function customer_会員編集_必須項目未入力(\AcceptanceTester $I) |
||
| 140 | { |
||
| 141 | $I->wantTo('EA0502-UC02-T02 会員編集_必須項目未入力'); |
||
| 142 | |||
| 143 | $createCustomer = Fixtures::get('createCustomer'); |
||
| 144 | $customer = $createCustomer(); |
||
| 145 | |||
| 146 | $CustomerListPage = CustomerManagePage::go($I) |
||
| 147 | ->検索($customer->getEmail()); |
||
| 148 | |||
| 149 | $I->see('検索結果:1件が該当しました' ,CustomerManagePage::$検索結果メッセージ); |
||
| 150 | |||
| 151 | $CustomerListPage->一覧_編集(1); |
||
| 152 | |||
| 153 | CustomerEditPage::at($I) |
||
| 154 | ->入力_姓('') |
||
| 155 | ->登録(); |
||
| 156 | |||
| 157 | $I->seeElement(['css' => '#admin_customer_name_name01:invalid']); |
||
| 158 | $I->dontSeeElement(CustomerEditPage::$登録完了メッセージ); |
||
| 159 | } |
||
| 160 | |||
| 161 | public function customer_会員削除(\AcceptanceTester $I) |
||
| 162 | { |
||
| 163 | $I->wantTo('EA0501-UC03-T01 会員削除'); |
||
| 164 | |||
| 165 | $createCustomer = Fixtures::get('createCustomer'); |
||
| 166 | $customer = $createCustomer(); |
||
| 167 | |||
| 168 | $CustomerManagePage = CustomerManagePage::go($I) |
||
| 169 | ->検索($customer->getEmail()); |
||
| 170 | |||
| 171 | $CustomerManagePage->一覧_削除(1); |
||
| 172 | |||
| 173 | $I->see('検索条件に合致するデータが見つかりませんでした', CustomerManagePage::$検索結果_結果なしメッセージ); |
||
| 174 | } |
||
| 175 | |||
| 176 | public function customer_会員削除キャンセル(\AcceptanceTester $I) |
||
| 177 | { |
||
| 178 | $I->wantTo('EA0501-UC03-T02 会員削除キャンセル'); |
||
| 179 | |||
| 180 | $createCustomer = Fixtures::get('createCustomer'); |
||
| 181 | $customer = $createCustomer(); |
||
| 182 | |||
| 183 | $CustomerManagePage = CustomerManagePage::go($I) |
||
| 184 | ->検索($customer->getEmail()); |
||
| 185 | |||
| 186 | $CustomerIdForNotDel = $CustomerManagePage->一覧_会員ID(1); |
||
| 187 | $CustomerManagePage->一覧_削除(1, false); |
||
| 188 | |||
| 189 | $I->assertEquals($CustomerIdForNotDel, $CustomerManagePage->一覧_会員ID(1)); |
||
| 190 | } |
||
| 191 | |||
| 192 | /** |
||
| 193 | * @env firefox |
||
| 194 | * @env chrome |
||
| 195 | */ |
||
| 196 | public function customer_CSV出力(\AcceptanceTester $I) |
||
| 197 | { |
||
| 198 | $I->wantTo('EA0501-UC05-T01 CSV出力'); |
||
| 199 | |||
| 200 | $findCustomers = Fixtures::get('findCustomers'); |
||
| 201 | CustomerManagePage::go($I) |
||
| 202 | ->検索() |
||
| 203 | ->CSVダウンロード(); |
||
| 204 | |||
| 205 | $CustomerCSV = $I->getLastDownloadFile('/^customer_\d{14}\.csv$/'); |
||
| 206 | $I->assertEquals(count($findCustomers()) + 1, count(file($CustomerCSV))); |
||
| 207 | } |
||
| 208 | |||
| 209 | public function customer_CSV出力項目設定(\AcceptanceTester $I) |
||
| 210 | { |
||
| 211 | $I->wantTo('EA0501-UC04-T01 CSV出力項目設定'); |
||
| 212 | |||
| 213 | |||
| 214 | CustomerManagePage::go($I) |
||
| 215 | ->検索() |
||
| 216 | ->CSV出力項目設定(); |
||
| 217 | |||
| 218 | CsvSettingsPage::at($I); |
||
| 219 | $value = $I->grabValueFrom(CsvSettingsPage::$CSVタイプ); |
||
| 220 | $I->assertEquals('2', $value); |
||
| 221 | } |
||
| 222 | |||
| 223 | public function customer_仮会員メール再送(\AcceptanceTester $I) |
||
| 224 | { |
||
| 225 | $I->wantTo('EA0501-UC06-T01(& UC06-T02) 仮会員メール再送'); |
||
| 226 | |||
| 227 | $I->resetEmails(); |
||
| 228 | |||
| 229 | $createCustomer = Fixtures::get('createCustomer'); |
||
| 230 | $customer = $createCustomer(null, false); |
||
| 231 | $BaseInfo = Fixtures::get('baseinfo'); |
||
| 232 | |||
| 233 | CustomerManagePage::go($I) |
||
| 234 | ->検索($customer->getEmail()) |
||
| 235 | ->一覧_仮会員メール再送(1); |
||
| 236 | $I->wait(5); |
||
| 237 | |||
| 238 | $I->seeEmailCount(2); |
||
| 239 | foreach (array($customer->getEmail(), $BaseInfo->getEmail01()) as $email) { |
||
| 240 | $I->seeInLastEmailSubjectTo($email, '会員登録のご確認'); |
||
| 241 | $I->seeInLastEmailTo($email, $customer->getName01().' '.$customer->getName02().' 様'); |
||
| 242 | } |
||
| 243 | } |
||
| 244 | } |
||
| 245 |