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 |
||
| 11 | class EF06OtherCest |
||
| 12 | { |
||
| 13 | public function _before(\AcceptanceTester $I) |
||
| 14 | { |
||
| 15 | } |
||
| 16 | |||
| 17 | public function _after(\AcceptanceTester $I) |
||
| 18 | { |
||
| 19 | } |
||
| 20 | |||
| 21 | public function other_ログイン正常(\AcceptanceTester $I) |
||
| 22 | { |
||
| 23 | $I->wantTo('EF0601-UC01-T01 ログイン 正常パターン'); |
||
| 24 | $I->logoutAsMember(); |
||
| 25 | |||
| 26 | $createCustomer = Fixtures::get('createCustomer'); |
||
| 27 | $customer = $createCustomer(); |
||
| 28 | $I->loginAsMember($customer->getEmail(), 'password'); |
||
| 29 | } |
||
| 30 | |||
| 31 | public function other_ログイン異常1(\AcceptanceTester $I) |
||
| 32 | { |
||
| 33 | $I->wantTo('EF0601-UC01-T02 ログイン 異常パターン(仮会員)'); |
||
| 34 | $I->logoutAsMember(); |
||
| 35 | |||
| 36 | $createCustomer = Fixtures::get('createCustomer'); |
||
| 37 | $customer = $createCustomer(null, false); |
||
| 38 | |||
| 39 | $I->amOnPage('/mypage/login'); |
||
| 40 | $I->submitForm('#login_mypage', [ |
||
| 41 | 'login_email' => $customer->getEmail(), |
||
| 42 | 'login_pass' => 'password' |
||
| 43 | ]); |
||
| 44 | |||
| 45 | $I->see('ログインできませんでした。', 'div.ec-login p.ec-errorMessage'); |
||
| 46 | } |
||
| 47 | |||
| 48 | public function other_ログイン異常2(\AcceptanceTester $I) |
||
| 49 | { |
||
| 50 | $I->wantTo('EF0601-UC01-T03 ログイン 異常パターン(入力ミス)'); |
||
| 51 | $I->logoutAsMember(); |
||
| 52 | |||
| 53 | $createCustomer = Fixtures::get('createCustomer'); |
||
| 54 | $customer = $createCustomer(null, false); |
||
| 55 | |||
| 56 | $I->amOnPage('/mypage/login'); |
||
| 57 | $I->submitForm('#login_mypage', [ |
||
| 58 | 'login_email' => $customer->getEmail().'.bad', |
||
| 59 | 'login_pass' => 'password' |
||
| 60 | ]); |
||
| 61 | |||
| 62 | $I->see('ログインできませんでした。', 'div.ec-login p.ec-errorMessage'); |
||
| 63 | } |
||
| 64 | |||
| 65 | public function other_パスワード再発行(\AcceptanceTester $I) |
||
| 66 | { |
||
| 67 | $I->wantTo('EF0602-UC01-T01 パスワード再発行'); |
||
| 68 | $I->logoutAsMember(); |
||
| 69 | $BaseInfo = Fixtures::get('baseinfo'); |
||
| 70 | |||
| 71 | // TOPページ→ログイン(「ログイン情報をお忘れですか?」リンクを押下する)→パスワード再発行 |
||
| 72 | $I->amOnPage('/mypage/login'); |
||
| 73 | //$I->click('ログイン情報をお忘れですか', '#login_mypage #login_box .btn_area ul li a'); |
||
| 74 | $I->amOnPage('/forgot'); |
||
| 75 | |||
| 76 | // TOPページ>ログイン>パスワード再発行 |
||
| 77 | $I->see('パスワードの再発行', 'div.ec-pageHeader h1'); |
||
| 78 | |||
| 79 | // メールアドレスを入力する |
||
| 80 | // 「次のページへ」ボタンを押下する |
||
| 81 | $createCustomer = Fixtures::get('createCustomer'); |
||
| 82 | $customer = $createCustomer(); |
||
| 83 | $I->resetEmails(); |
||
| 84 | $I->submitForm('#form1',[ |
||
| 85 | 'login_email' => $customer->getEmail() |
||
| 86 | ]); |
||
| 87 | $I->see('パスワード発行メールの送信 完了', 'div.ec-pageHeader h1'); |
||
| 88 | |||
| 89 | $I->seeEmailCount(2); |
||
| 90 | foreach (array($customer->getEmail(), $BaseInfo->getEmail01()) as $email) { |
||
| 91 | $I->seeInLastEmailSubjectTo($email, 'パスワード変更のご確認'); |
||
| 92 | } |
||
| 93 | $url = $I->grabFromLastEmailTo($customer->getEmail(), '@/forgot/reset/(.*)@'); |
||
| 94 | |||
| 95 | $I->resetEmails(); |
||
| 96 | $I->amOnPage($url); |
||
| 97 | $I->see('パスワード変更(完了ページ)', 'div.ec-pageHeader h1'); |
||
| 98 | $I->seeEmailCount(2); |
||
| 99 | foreach (array($customer->getEmail(), $BaseInfo->getEmail01()) as $email) { |
||
| 100 | $I->seeInLastEmailSubjectTo($email, 'パスワード変更のお知らせ'); |
||
| 101 | } |
||
| 102 | $new_password = $I->grabFromLastEmailTo($customer->getEmail(), '@新しいパスワード:(.*)@'); |
||
| 103 | $I->loginAsMember($customer->getEmail(), trim(str_replace('新しいパスワード:', '', $new_password))); |
||
| 104 | } |
||
| 105 | |||
| 106 | public function other_ログアウト(\AcceptanceTester $I) |
||
| 107 | { |
||
| 108 | $I->wantTo('EF0603-UC01-T01 ログアウト'); |
||
| 109 | $I->logoutAsMember(); |
||
| 110 | |||
| 111 | $createCustomer = Fixtures::get('createCustomer'); |
||
| 112 | $customer = $createCustomer(); |
||
| 113 | $I->loginAsMember($customer->getEmail(), 'password'); |
||
| 114 | |||
| 115 | $I->logoutAsMember(); |
||
| 116 | } |
||
| 117 | |||
| 118 | public function other_当サイトについて(\AcceptanceTester $I) |
||
| 119 | { |
||
| 120 | $I->wantTo('EF0604-UC01-T01 当サイトについて'); |
||
| 121 | $I->amOnPage('/'); |
||
| 122 | |||
| 123 | $I->click('.ec-footerNavi .ec-footerNavi__link:nth-child(1) a'); |
||
| 124 | $I->see('当サイトについて', 'div.ec-pageHeader h1'); |
||
| 125 | $baseinfo = Fixtures::get('baseinfo'); |
||
| 126 | $I->see($baseinfo->getShopName(), '#help_about_box__shop_name'); |
||
| 127 | } |
||
| 128 | |||
| 129 | public function other_プライバシーポリシー(\AcceptanceTester $I) |
||
| 130 | { |
||
| 131 | $I->wantTo('EF0605-UC01-T01 プライバシーポリシー'); |
||
| 132 | $I->amOnPage('/'); |
||
| 133 | |||
| 134 | $I->click('.ec-footerNavi .ec-footerNavi__link:nth-child(2) a'); |
||
| 135 | $I->see('プライバシーポリシー', 'div.ec-pageHeader h1'); |
||
| 136 | $I->see('個人情報保護の重要性に鑑み、「個人情報の保護に関する法律」及び本プライバシーポリシーを遵守し、お客さまのプライバシー保護に努めます。', 'div.ec-layoutRole__main p:nth-child(1)'); |
||
| 137 | } |
||
| 138 | |||
| 139 | public function other_特定商取引法に基づく表記(\AcceptanceTester $I) |
||
| 140 | { |
||
| 141 | $I->wantTo('EF0606-UC01-T01 特定商取引法に基づく表記'); |
||
| 142 | $I->amOnPage('/'); |
||
| 143 | |||
| 144 | $I->click('.ec-footerNavi .ec-footerNavi__link:nth-child(3) a'); |
||
| 145 | $I->see('特定商取引法に基づく表記', 'div.ec-pageHeader h1'); |
||
| 146 | } |
||
| 147 | |||
| 148 | public function other_お問い合わせ1(\AcceptanceTester $I) |
||
| 149 | { |
||
| 150 | $I->wantTo('EF0607-UC01-T01 お問い合わせ'); |
||
| 151 | $I->amOnPage('/'); |
||
| 152 | $I->resetEmails(); |
||
| 153 | $faker = Fixtures::get('faker'); |
||
| 154 | $new_email = microtime(true).'.'.$faker->safeEmail; |
||
| 155 | $BaseInfo = Fixtures::get('baseinfo'); |
||
| 156 | |||
| 157 | $I->click('.ec-footerNavi .ec-footerNavi__link:nth-child(4) a'); |
||
| 158 | $I->see('お問い合わせ', 'div.ec-pageHeader h1'); |
||
| 159 | |||
| 160 | $I->fillField(['id' => 'contact_name_name01'], '姓'); |
||
| 161 | $I->fillField(['id' => 'contact_name_name02'], '名'); |
||
| 162 | $I->fillField(['id' => 'contact_kana_kana01'], 'セイ'); |
||
| 163 | $I->fillField(['id' => 'contact_kana_kana02'], 'メイ'); |
||
| 164 | $I->fillField(['id' => 'contact_postal_code'], '530-0001'); |
||
| 165 | $I->selectOption(['id' => 'contact_address_pref'], ['value' => '27']); |
||
| 166 | $I->fillField(['id' => 'contact_address_addr01'], '大阪市北区'); |
||
| 167 | $I->fillField(['id' => 'contact_address_addr02'], '梅田2-4-9 ブリーゼタワー13F'); |
||
| 168 | $I->fillField(['id' => 'contact_phone_number'], '111-111-111'); |
||
| 169 | $I->fillField(['id' => 'contact_email'], $new_email); |
||
| 170 | $I->fillField(['id' => 'contact_contents'], 'お問い合わせ内容の送信'); |
||
| 171 | $I->click('div.ec-RegisterRole__actions button.ec-blockBtn--action'); |
||
| 172 | |||
| 173 | $I->see('お問い合わせ', 'div.ec-pageHeader h1'); |
||
| 174 | $I->click('div.ec-contactConfirmRole div.ec-RegisterRole__actions button.ec-blockBtn--action'); |
||
| 175 | |||
| 176 | // 完了ページ |
||
| 177 | $I->see('お問い合わせ完了', 'div.ec-pageHeader h1'); |
||
| 178 | |||
| 179 | // メールチェック |
||
| 180 | $I->seeEmailCount(2); |
||
| 181 | foreach (array($new_email, $BaseInfo->getEmail01()) as $email) { |
||
| 182 | $I->seeInLastEmailSubjectTo($email, 'お問い合わせを受け付けました'); |
||
| 183 | $I->seeInLastEmailTo($email, '姓 名 様'); |
||
| 184 | $I->seeInLastEmailTo($email, 'お問い合わせ内容の送信'); |
||
| 185 | } |
||
| 186 | } |
||
| 187 | } |
||
| 188 |