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 $姓_エラーメッセージ = '#shippingerInfo > div > div:nth-child(2) > div.col > span > ul > p'; |
||
| 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) |
||
| 18 | { |
||
| 19 | parent::__construct($I); |
||
| 20 | } |
||
| 21 | |||
| 22 | public static function go($I) |
||
| 23 | { |
||
| 24 | $page = new self($I); |
||
| 25 | $page->goPage('/shipping/new', '出荷登録出荷管理'); |
||
| 26 | return $page; |
||
| 27 | } |
||
| 28 | |||
| 29 | public static function at($I) |
||
| 30 | { |
||
| 31 | $page = new self($I); |
||
| 32 | $page->atPage('出荷登録出荷管理'); |
||
| 33 | return $page; |
||
| 34 | } |
||
| 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 お届け先編集() |
||
| 43 | { |
||
| 44 | $this->tester->click(['id' => 'edit-shipping-addr']); |
||
| 45 | $this->tester->waitForElementVisible(['id' => 'shipping_name_name01']); |
||
| 46 | return $this; |
||
| 47 | } |
||
| 48 | |||
| 49 | public function 入力_姓($value) |
||
| 50 | { |
||
| 51 | $this->tester->fillField(['id' => 'shipping_name_name01'], $value); |
||
| 52 | return $this; |
||
| 53 | } |
||
| 54 | |||
| 55 | public function 入力_名($value) |
||
| 56 | { |
||
| 57 | $this->tester->fillField(['id' => 'shipping_name_name02'], $value); |
||
| 58 | return $this; |
||
| 59 | } |
||
| 60 | |||
| 61 | public function 入力_セイ($value) |
||
| 62 | { |
||
| 63 | $this->tester->fillField(['id' => 'shipping_kana_kana01'], $value); |
||
| 64 | return $this; |
||
| 65 | } |
||
| 66 | |||
| 67 | public function 入力_メイ($value) |
||
| 68 | { |
||
| 69 | $this->tester->fillField(['id' => 'shipping_kana_kana02'], $value); |
||
| 70 | return $this; |
||
| 71 | } |
||
| 72 | |||
| 73 | public function 入力_郵便番号($value) |
||
| 74 | { |
||
| 75 | $this->tester->fillField(['id' => 'shipping_postal_code'], $value); |
||
| 76 | |||
| 77 | return $this; |
||
| 78 | } |
||
| 79 | |||
| 80 | public function 入力_都道府県($value) |
||
| 81 | { |
||
| 82 | $this->tester->selectOption(['id' => 'shipping_address_pref'], $value); |
||
| 83 | return $this; |
||
| 84 | } |
||
| 85 | |||
| 86 | public function 入力_市区町村名($value) |
||
| 87 | { |
||
| 88 | $this->tester->fillField(['id' => 'shipping_address_addr01'], $value); |
||
| 89 | return $this; |
||
| 90 | } |
||
| 91 | |||
| 92 | public function 入力_番地_ビル名($value) |
||
| 93 | { |
||
| 94 | $this->tester->fillField(['id' => 'shipping_address_addr02'], $value); |
||
| 95 | return $this; |
||
| 96 | } |
||
| 97 | |||
| 98 | public function 入力_電話番号($value) |
||
| 99 | { |
||
| 100 | $this->tester->fillField(['id' => 'shipping_phone_number'], $value); |
||
| 101 | |||
| 102 | return $this; |
||
| 103 | } |
||
| 104 | |||
| 105 | public function 入力_出荷伝票番号($value) |
||
| 106 | { |
||
| 107 | $this->tester->fillField(['id' => 'shipping_tracking_number'], $value); |
||
| 108 | return $this; |
||
| 109 | } |
||
| 110 | |||
| 111 | public function 入力_配送業者($value) |
||
| 112 | { |
||
| 113 | $this->tester->selectOption(['id' => 'shipping_Delivery'], $value); |
||
| 114 | return $this; |
||
| 115 | } |
||
| 116 | |||
| 117 | public function 入力_配達用メモ($value) |
||
| 118 | { |
||
| 119 | $this->tester->fillField(['id' => 'shipping_note'], $value); |
||
| 120 | return $this; |
||
| 121 | } |
||
| 122 | |||
| 123 | 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 | 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 出荷情報登録() |
||
| 140 | { |
||
| 141 | $this->tester->click(['id' => 'btn_save']); |
||
| 142 | return $this; |
||
| 143 | } |
||
| 144 | |||
| 145 | public function 変更を確定() |
||
| 146 | { |
||
| 147 | $this->tester->waitForElementVisible(['xpath' => '//*[@id="shippedNotifyModal"]/div/div/div[3]/button[2]']); |
||
| 148 | $this->tester->click(['xpath' => '//*[@id="shippedNotifyModal"]/div/div/div[3]/button[2]']); |
||
| 149 | return $this; |
||
| 150 | } |
||
| 151 | } |
||
| 152 |