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 |
||
| 10 | class EF04CustomerCest |
||
| 11 | { |
||
| 12 | public function customer_会員登録正常(\AcceptanceTester $I) |
||
| 13 | { |
||
| 14 | $I->wantTo('EF0401-UC01-T01 会員登録 正常パターン'); |
||
| 15 | $I->amOnPage('/entry'); |
||
| 16 | $faker = Fixtures::get('faker'); |
||
| 17 | $BaseInfo = Fixtures::get('baseinfo'); |
||
| 18 | $new_email = microtime(true).'.'.$faker->safeEmail; |
||
| 19 | // 会員情報入力フォームに、会員情報を入力する |
||
| 20 | // 「同意する」ボタンを押下する |
||
| 21 | $form = [ |
||
| 22 | 'entry[name][name01]' => '姓', |
||
| 23 | 'entry[name][name02]' => '名', |
||
| 24 | 'entry[kana][kana01]' => 'セイ', |
||
| 25 | 'entry[kana][kana02]' => 'メイ', |
||
| 26 | 'entry[zip][zip01]' => '530', |
||
| 27 | 'entry[zip][zip02]' => '0001', |
||
| 28 | 'entry[address][pref]' => ['value' => '27'], |
||
| 29 | 'entry[address][addr01]' => '大阪市北区', |
||
| 30 | 'entry[address][addr02]' => '梅田2-4-9 ブリーゼタワー13F', |
||
| 31 | 'entry[tel][tel01]' => '111', |
||
| 32 | 'entry[tel][tel02]' => '111', |
||
| 33 | 'entry[tel][tel03]' => '111', |
||
| 34 | 'entry[email][first]' => $new_email, |
||
| 35 | 'entry[email][second]' => $new_email, |
||
| 36 | 'entry[password][first]' => 'password', |
||
| 37 | 'entry[password][second]' => 'password', |
||
| 38 | 'entry[job]' => ['value' => '1'], |
||
| 39 | ]; |
||
| 40 | $findPluginByCode = Fixtures::get('findPluginByCode'); |
||
| 41 | $Plugin = $findPluginByCode('MailMagazine'); |
||
| 42 | if ($Plugin) { |
||
| 43 | $I->amGoingTo('メルマガプラグインを発見したため、メルマガを購読します'); |
||
| 44 | $form['entry[mailmaga_flg]'] = '1'; |
||
| 45 | } |
||
| 46 | $I->submitForm(['css' => '.ec-layoutRole__main form'], $form, ['css' => 'button.ec-blockBtn--action']); |
||
| 47 | |||
| 48 | // 入力した会員情報を確認する。 |
||
| 49 | $I->see('姓 名', '.ec-registerRole form .ec-borderedDefs dl:nth-child(1) dd'); |
||
| 50 | $I->see('111 - 111 - 111', '.ec-registerRole form .ec-borderedDefs dl:nth-child(5) dd'); |
||
| 51 | $I->see($new_email, '.ec-registerRole form .ec-borderedDefs dl:nth-child(7) dd'); |
||
| 52 | |||
| 53 | $I->resetEmails(); |
||
| 54 | // 「会員登録をする」ボタンを押下する |
||
| 55 | $I->click('.ec-registerRole form button.ec-blockBtn--action'); |
||
| 56 | |||
| 57 | $I->seeEmailCount(2); |
||
| 58 | foreach (array($new_email, $BaseInfo->getEmail01()) as $email) { |
||
| 59 | $I->seeInLastEmailSubjectTo($email, '会員登録のご確認'); |
||
| 60 | $I->seeInLastEmailTo($email, '姓 名 様'); |
||
| 61 | $I->seeInLastEmailTo($email, 'この度は会員登録依頼をいただきまして、有り難うございます。'); |
||
| 62 | } |
||
| 63 | |||
| 64 | // 「トップページへ」ボタンを押下する |
||
| 65 | $I->click('a.ec-blockBtn--cancel'); |
||
| 66 | $I->see('新着情報', '.ec-news__title'); |
||
| 67 | |||
| 68 | |||
| 69 | // アクティベートURL取得 |
||
| 70 | $activateUrl = $I->grabFromLastEmailTo($new_email, '@/entry/activate/(.*)@'); |
||
| 71 | $I->resetEmails(); |
||
| 72 | |||
| 73 | // アクティベートURLからトップページへ |
||
| 74 | $I->amOnPage($activateUrl); |
||
| 75 | $I->see('新規会員登録(完了)', 'div.ec-pageHeader h1'); |
||
| 76 | |||
| 77 | $I->seeEmailCount(2); |
||
| 78 | foreach (array($new_email, $BaseInfo->getEmail01()) as $email) { |
||
| 79 | $I->seeInLastEmailSubjectTo($email, '会員登録が完了しました。'); |
||
| 80 | $I->seeInLastEmailTo($email, '姓 名 様'); |
||
| 81 | $I->seeInLastEmailTo($email, '本会員登録が完了いたしました。'); |
||
| 82 | } |
||
| 83 | |||
| 84 | $I->click('div.ec-registerCompleteRole a.ec-blockBtn--cancel'); |
||
| 85 | $I->see('新着情報', '.ec-news__title'); |
||
| 86 | } |
||
| 87 | |||
| 88 | public function customer_会員登録異常1(\AcceptanceTester $I) |
||
| 89 | { |
||
| 90 | $I->wantTo('EF0401-UC01-T02 会員登録 異常パターン 重複'); |
||
| 91 | $I->amOnPage('/entry'); |
||
| 92 | |||
| 93 | $createCustomer = Fixtures::get('createCustomer'); |
||
| 94 | $customer = $createCustomer(); |
||
| 95 | |||
| 96 | // 会員情報入力フォームに、会員情報を入力する |
||
| 97 | // 「同意する」ボタンを押下する |
||
| 98 | $I->submitForm(['css' => '.ec-layoutRole__main form'],[ |
||
| 99 | 'entry[name][name01]' => '姓', |
||
| 100 | 'entry[name][name02]' => '名', |
||
| 101 | 'entry[kana][kana01]' => 'セイ', |
||
| 102 | 'entry[kana][kana02]' => 'メイ', |
||
| 103 | 'entry[zip][zip01]' => '530', |
||
| 104 | 'entry[zip][zip02]' => '0001', |
||
| 105 | 'entry[address][pref]' => ['value' => '27'], |
||
| 106 | 'entry[address][addr01]' => '大阪市北区', |
||
| 107 | 'entry[address][addr02]' => '梅田2-4-9 ブリーゼタワー13F', |
||
| 108 | 'entry[tel][tel01]' => '111', |
||
| 109 | 'entry[tel][tel02]' => '111', |
||
| 110 | 'entry[tel][tel03]' => '111', |
||
| 111 | 'entry[email][first]' => $customer->getEmail(), // 会員登録済みのメールアドレスを入力する |
||
| 112 | 'entry[email][second]' => $customer->getEmail(), |
||
| 113 | 'entry[password][first]' => 'password', |
||
| 114 | 'entry[password][second]' => 'password', |
||
| 115 | ], ['css' => 'button.ec-blockBtn--action']); |
||
| 116 | |||
| 117 | // 入力した会員情報を確認する。 |
||
| 118 | $I->see('既に利用されているメールアドレスです', '.ec-registerRole form .ec-borderedDefs dl:nth-child(7) dd'); |
||
| 119 | } |
||
| 120 | |||
| 121 | public function customer_会員登録異常2(\AcceptanceTester $I) |
||
| 122 | { |
||
| 123 | $I->wantTo('EF0401-UC01-T03 会員登録 異常パターン 入力ミス'); |
||
| 124 | $I->amOnPage('/entry'); |
||
| 125 | |||
| 126 | $faker = Fixtures::get('faker'); |
||
| 127 | $new_email = microtime(true).'.'.$faker->safeEmail; |
||
| 128 | |||
| 129 | // 会員情報入力フォームに、会員情報を入力する |
||
| 130 | // 「同意する」ボタンを押下する |
||
| 131 | $I->submitForm(['css' => '.ec-layoutRole__main form'],[ |
||
| 132 | 'entry[name][name01]' => '', |
||
| 133 | 'entry[name][name02]' => '名', |
||
| 134 | 'entry[kana][kana01]' => 'セイ', |
||
| 135 | 'entry[kana][kana02]' => 'メイ', |
||
| 136 | 'entry[zip][zip01]' => '530', |
||
| 137 | 'entry[zip][zip02]' => '0001', |
||
| 138 | 'entry[address][pref]' => ['value' => '27'], |
||
| 139 | 'entry[address][addr01]' => '大阪市北区', |
||
| 140 | 'entry[address][addr02]' => '梅田2-4-9 ブリーゼタワー13F', |
||
| 141 | 'entry[tel][tel01]' => '111', |
||
| 142 | 'entry[tel][tel02]' => '111', |
||
| 143 | 'entry[tel][tel03]' => '111', |
||
| 144 | 'entry[email][first]' => $new_email, |
||
| 145 | 'entry[email][second]' => $new_email, |
||
| 146 | 'entry[password][first]' => 'password', |
||
| 147 | 'entry[password][second]' => 'password', |
||
| 148 | ], ['css' => 'button.ec-blockBtn--action']); |
||
| 149 | |||
| 150 | // 入力した会員情報を確認する。 |
||
| 151 | $I->see('新規会員登録', '.ec-pageHeader h1'); |
||
| 152 | |||
| 153 | // TODO [fixture] 確認画面のあとでのメールアドレス重複エラー |
||
| 154 | } |
||
| 155 | |||
| 156 | public function customer_会員登録同意しない(\AcceptanceTester $I) |
||
| 157 | { |
||
| 158 | $I->wantTo('EF0401-UC01-T04 会員登録 同意しないボタン'); |
||
| 159 | $I->amOnPage('/entry'); |
||
| 160 | |||
| 161 | $I->click('.ec-layoutRole__main form a.ec-blockBtn--cancel'); |
||
| 162 | $I->see('新着情報', '.ec-news__title'); |
||
| 163 | } |
||
| 164 | |||
| 165 | public function customer_会員登録戻る(\AcceptanceTester $I) |
||
| 166 | { |
||
| 167 | $I->wantTo('EF0401-UC01-T05 会員登録 戻るボタン'); |
||
| 168 | $I->amOnPage('/entry'); |
||
| 169 | |||
| 170 | $faker = Fixtures::get('faker'); |
||
| 171 | $new_email = microtime(true).'.'.$faker->safeEmail; |
||
| 172 | |||
| 173 | // 会員情報入力フォームに、会員情報を入力する |
||
| 174 | // 「同意する」ボタンを押下する |
||
| 175 | $form = [ |
||
| 176 | 'entry[name][name01]' => '姓', |
||
| 177 | 'entry[name][name02]' => '名', |
||
| 178 | 'entry[kana][kana01]' => 'セイ', |
||
| 179 | 'entry[kana][kana02]' => 'メイ', |
||
| 180 | 'entry[zip][zip01]' => '530', |
||
| 181 | 'entry[zip][zip02]' => '0001', |
||
| 182 | 'entry[address][pref]' => ['value' => '27'], |
||
| 183 | 'entry[address][addr01]' => '大阪市北区', |
||
| 184 | 'entry[address][addr02]' => '梅田2-4-9 ブリーゼタワー13F', |
||
| 185 | 'entry[tel][tel01]' => '111', |
||
| 186 | 'entry[tel][tel02]' => '111', |
||
| 187 | 'entry[tel][tel03]' => '111', |
||
| 188 | 'entry[email][first]' => $new_email, |
||
| 189 | 'entry[email][second]' => $new_email, |
||
| 190 | 'entry[password][first]' => 'password', |
||
| 191 | 'entry[password][second]' => 'password', |
||
| 192 | 'entry[job]' => ['value' => '1'], |
||
| 193 | ]; |
||
| 194 | |||
| 195 | $findPluginByCode = Fixtures::get('findPluginByCode'); |
||
| 196 | $Plugin = $findPluginByCode('MailMagazine'); |
||
| 197 | if ($Plugin) { |
||
| 198 | $I->amGoingTo('メルマガプラグインを発見したため、メルマガを購読します'); |
||
| 199 | $form['entry[mailmaga_flg]'] = '1'; |
||
| 200 | } |
||
| 201 | $I->submitForm(['css' => '.ec-layoutRole__main form'], $form, ['css' => 'button.ec-blockBtn--action']); |
||
| 202 | |||
| 203 | $I->click('.ec-registerRole form button.ec-blockBtn--cancel'); |
||
| 204 | $I->see('新規会員登録', '.ec-pageHeader h1'); |
||
| 205 | } |
||
| 206 | |||
| 207 | public function customer_会員登録利用規約(\AcceptanceTester $I) |
||
| 208 | { |
||
| 209 | $I->wantTo('EF0404-UC01-T01 会員登録 利用規約'); |
||
| 210 | $I->amOnPage('/entry'); |
||
| 211 | |||
| 212 | $I->click('.ec-registerRole form a.ec-link'); |
||
| 213 | |||
| 214 | $I->switchToNewWindow(); |
||
| 215 | $I->seeInCurrentUrl('/help/agreement'); |
||
| 216 | } |
||
| 217 | } |
||
| 218 |