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 |
||
| 7 | class ShippingEditPage extends AbstractAdminPageStyleGuide |
||
|
|
|||
| 8 | { |
||
| 9 | |||
| 10 | public static $姓_エラーメッセージ = '#shipmentOverview_0 > div > div:nth-child(2) > div:nth-child(1) > div:nth-child(1) > div > div > div:nth-child(1) > span > span > span.form-error-message'; |
||
| 11 | |||
| 12 | public static $登録完了メッセージ = '#page_admin_shipping_edit > div > div.c-contentsArea > div.alert.alert-success.alert-dismissible.fade.show.m-3 > span'; |
||
| 13 | |||
| 14 | /** |
||
| 15 | * ShippingRegisterPage constructor. |
||
| 16 | */ |
||
| 17 | public function __construct(\AcceptanceTester $I) |
||
| 21 | |||
| 22 | public static function go($I) |
||
| 28 | |||
| 29 | public static function at($I) |
||
| 35 | |||
| 36 | public function 入力_出荷日($value) |
||
| 37 | { |
||
| 38 | $this->tester->executeJS("document.getElementById('shipping_shipping_date').value = '{$value}'"); |
||
| 39 | return $this; |
||
| 40 | } |
||
| 41 | |||
| 42 | public function お届け先編集() |
||
| 48 | |||
| 49 | public function 入力_姓($value, $num = 0) |
||
| 50 | { |
||
| 51 | $this->tester->fillField(['id' => 'form_shippings_'.$num.'_name_name01'], $value); |
||
| 52 | return $this; |
||
| 53 | } |
||
| 54 | |||
| 55 | public function 入力_名($value, $num = 0) |
||
| 56 | { |
||
| 57 | $this->tester->fillField(['id' => 'form_shippings_'.$num.'_name_name02'], $value); |
||
| 58 | return $this; |
||
| 59 | } |
||
| 60 | |||
| 61 | public function 入力_セイ($value, $num = 0) |
||
| 62 | { |
||
| 63 | $this->tester->fillField(['id' => 'form_shippings_'.$num.'_kana_kana01'], $value); |
||
| 64 | return $this; |
||
| 65 | } |
||
| 66 | |||
| 67 | public function 入力_メイ($value, $num = 0) |
||
| 68 | { |
||
| 69 | $this->tester->fillField(['id' => 'form_shippings_'.$num.'_kana_kana02'], $value); |
||
| 70 | return $this; |
||
| 71 | } |
||
| 72 | |||
| 73 | public function 入力_郵便番号($value, $num = 0) |
||
| 74 | { |
||
| 75 | $this->tester->fillField(['id' => 'form_shippings_'.$num.'_postal_code'], $value); |
||
| 76 | |||
| 77 | return $this; |
||
| 78 | } |
||
| 79 | |||
| 80 | public function 入力_都道府県($value, $num = 0) |
||
| 81 | { |
||
| 82 | $this->tester->selectOption(['id' => 'form_shippings_'.$num.'_address_pref'], $value); |
||
| 83 | return $this; |
||
| 84 | } |
||
| 85 | |||
| 86 | public function 入力_市区町村名($value, $num = 0) |
||
| 87 | { |
||
| 88 | $this->tester->fillField(['id' => 'form_shippings_'.$num.'_address_addr01'], $value); |
||
| 89 | return $this; |
||
| 90 | } |
||
| 91 | |||
| 92 | public function 入力_番地_ビル名($value, $num = 0) |
||
| 93 | { |
||
| 94 | $this->tester->fillField(['id' => 'form_shippings_'.$num.'_address_addr02'], $value); |
||
| 95 | return $this; |
||
| 96 | } |
||
| 97 | |||
| 98 | public function 入力_電話番号($value, $num = 0) |
||
| 99 | { |
||
| 100 | $this->tester->fillField(['id' => 'form_shippings_'.$num.'_phone_number'], $value); |
||
| 101 | |||
| 102 | return $this; |
||
| 103 | } |
||
| 104 | |||
| 105 | public function 入力_出荷伝票番号($value, $num = 0) |
||
| 106 | { |
||
| 107 | $this->tester->fillField(['id' => 'form_shippings_'.$num.'_tracking_number'], $value); |
||
| 108 | return $this; |
||
| 109 | } |
||
| 110 | |||
| 111 | public function 入力_配送業者($value, $num = 0) |
||
| 112 | { |
||
| 113 | $this->tester->selectOption(['id' => 'form_shippings_'.$num.'_Delivery'], $value); |
||
| 114 | return $this; |
||
| 115 | } |
||
| 116 | |||
| 117 | public function 入力_配達用メモ($value, $num = 0) |
||
| 118 | { |
||
| 119 | $this->tester->fillField(['id' => 'form_shippings_'.$num.'_note'], $value); |
||
| 120 | return $this; |
||
| 121 | } |
||
| 122 | |||
| 123 | View Code Duplication | public function 商品検索($value = '') |
|
| 124 | { |
||
| 125 | $this->tester->click(['xpath' => '//*[@id="shipmentItem"]/div/div/div/button']); |
||
| 126 | $this->tester->waitForElementVisible(['id' => 'addProduct']); |
||
| 127 | $this->tester->click(['id' => 'searchItemsButton']); |
||
| 128 | return $this; |
||
| 129 | } |
||
| 130 | |||
| 131 | View Code Duplication | public function 商品検索結果_選択($rowNum) |
|
| 132 | { |
||
| 133 | $this->tester->click(['xpath' => "//*[@id='searchItemsResult']/table/tbody/tr[${rowNum}]/td[5]/i"]); |
||
| 134 | $this->tester->click(['xpath' => '//*[@id="addProduct"]/div/div/div[1]/button']); |
||
| 135 | $this->tester->wait(1); |
||
| 136 | return $this; |
||
| 137 | } |
||
| 138 | |||
| 139 | public function 出荷情報登録() |
||
| 144 | |||
| 145 | public function 出荷完了にする($num = 0) |
||
| 146 | { |
||
| 147 | $this->tester->scrollTo(['id' => 'shipmentOverview_'.$num], 0, 50); |
||
| 148 | $this->tester->click('#shipmentOverview_'.$num.' > div > div:nth-child(4) > div:nth-child(2) > div:nth-child(3) > div > button'); |
||
| 149 | return $this; |
||
| 150 | } |
||
| 151 | |||
| 152 | View Code Duplication | public function 変更を確定() |
|
| 153 | { |
||
| 154 | $this->tester->waitForElementVisible(['id' => 'bulkChange']); |
||
| 155 | $this->tester->click(['id' => 'bulkChange']); |
||
| 156 | $this->tester->waitForElementVisible(['id' => 'bulkChangeComplete']); |
||
| 157 | $this->tester->click(['id' => 'bulkChangeComplete']); |
||
| 158 | return $this; |
||
| 159 | } |
||
| 160 | |||
| 161 | public function 出荷先を追加() |
||
| 167 | |||
| 168 | public function 出荷日を確認($num = 0) |
||
| 174 | } |
||
| 175 |