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 |
||
| 6 | class ShippingManagePage extends AbstractAdminPageStyleGuide |
||
| 7 | { |
||
| 8 | public static $検索結果_メッセージ = '#search_form > div.c-outsideBlock__contents.mb-3 > span'; |
||
| 9 | public static $検索結果_エラーメッセージ = '//*[@id="page_admin_shipping"]/div[1]/div[3]/div[3]/div/div[1]/div/div/div[1]'; |
||
| 10 | public static $詳細検索ボタン = '//*[@id="search_form"]/div[1]/div/div/div[2]/a/span'; |
||
| 11 | |||
| 12 | /** |
||
| 13 | * ShippingListPage constructor. |
||
| 14 | */ |
||
| 15 | public function __construct(\AcceptanceTester $I) |
||
| 16 | { |
||
| 17 | parent::__construct($I); |
||
| 18 | } |
||
| 19 | |||
| 20 | public static function go(\AcceptanceTester $I) |
||
| 21 | { |
||
| 22 | $page = new self($I); |
||
| 23 | return $page->goPage('/shipping', '出荷一覧出荷管理'); |
||
| 24 | } |
||
| 25 | |||
| 26 | public static function at(\AcceptanceTester $I) |
||
| 27 | { |
||
| 28 | $page = new self($I); |
||
| 29 | return $page->atPage('出荷管理出荷一覧'); |
||
| 30 | } |
||
| 31 | |||
| 32 | public function 検索($value = '') |
||
| 33 | { |
||
| 34 | $this->tester->fillField(['id' => 'admin_search_shipping_multi'], $value); |
||
| 35 | $this->tester->click('#search_form > div.c-outsideBlock__contents.mb-3 > button'); |
||
| 36 | return $this; |
||
| 37 | } |
||
| 38 | |||
| 39 | public function 詳細検索設定() |
||
| 40 | { |
||
| 41 | $this->tester->click(self::$詳細検索ボタン); |
||
| 42 | $this->tester->waitForElementVisible(['id' => 'searchDetail']); |
||
| 43 | $this->tester->wait(0.5); |
||
| 44 | return $this; |
||
| 45 | } |
||
| 46 | |||
| 47 | public function 入力_ご注文者お名前($value) |
||
| 48 | { |
||
| 49 | $this->tester->fillField(['id' => 'admin_search_shipping_order_name'], $value); |
||
| 50 | return $this; |
||
| 51 | } |
||
| 52 | |||
| 53 | public function 入力_ご注文者お名前フリガナ($value) |
||
| 54 | { |
||
| 55 | $this->tester->fillField(['id' => 'admin_search_shipping_order_kana'], $value); |
||
| 56 | return $this; |
||
| 57 | } |
||
| 58 | |||
| 59 | public function 詳細検索_電話番号($value = '') |
||
| 60 | { |
||
| 61 | $this->tester->click(self::$詳細検索ボタン); |
||
| 62 | $this->tester->wait(1); |
||
| 63 | $this->tester->fillField(['id' => 'admin_search_shipping_phone_number'], $value); |
||
| 64 | $this->tester->click('#search_form > div.c-outsideBlock__contents.mb-3 > button'); |
||
| 65 | return $this; |
||
| 66 | } |
||
| 67 | |||
| 68 | public function 出荷CSVダウンロード実行() |
||
| 69 | { |
||
| 70 | $this->tester->click(['xpath' => '//*[@id="form_bulk"]/div[1]/div[2]/div[2]/div/a[1]']); |
||
| 71 | return $this; |
||
| 72 | } |
||
| 73 | |||
| 74 | public function 出荷CSV出力項目設定() |
||
| 75 | { |
||
| 76 | $this->tester->click(['xpath' => '//*[@id="form_bulk"]/div[1]/div[2]/div[2]/div/a[2]']); |
||
| 77 | return $this; |
||
| 78 | } |
||
| 79 | |||
| 80 | public function 一覧_編集($rowNum) |
||
| 81 | { |
||
| 82 | $this->tester->click(['xpath' => "//*[@id='form_bulk']/div[2]/div/table/tbody/tr[${rowNum}]/td[2]/a"]); |
||
| 83 | } |
||
| 84 | |||
| 85 | public function 一覧_削除() |
||
| 86 | { |
||
| 87 | $this->tester->waitForElementVisible(['xpath' => '//*[@id="btn_bulk"]/button[3]']); |
||
| 88 | $this->tester->click(['xpath' => '//*[@id="btn_bulk"]/button[3]']); |
||
| 89 | $this->tester->waitForElementVisible(['xpath' => '//*[@id="btn_bulk_delete"]']); |
||
| 90 | $this->tester->click(['xpath' => '//*[@id="btn_bulk_delete"]']); |
||
| 91 | return $this; |
||
| 92 | } |
||
| 93 | |||
| 94 | public function 一覧_削除キャンセル() |
||
| 95 | { |
||
| 96 | $this->tester->waitForElementVisible(['xpath' => '//*[@id="btn_bulk"]/button[1]']); |
||
| 97 | $this->tester->click(['xpath' => '//*[@id="btn_bulk"]/button[1]']); |
||
| 98 | return $this; |
||
| 99 | } |
||
| 100 | |||
| 101 | public function 一括発送済み更新() |
||
| 102 | { |
||
| 103 | $this->tester->waitForElementVisible(['xpath' => '//*[@id="btn_bulk"]/button[2]']); |
||
| 104 | $this->tester->click(['xpath' => '//*[@id="btn_bulk"]/button[2]']); |
||
| 105 | $this->tester->wait(3); |
||
| 106 | $this->tester->click(['id' => 'notificationMail']); |
||
| 107 | $this->tester->click(['id' => 'bulkChange']); |
||
| 108 | return $this; |
||
| 109 | } |
||
| 110 | |||
| 111 | public function 一括発送済みメール送信() |
||
| 112 | { |
||
| 113 | $this->tester->waitForElementVisible(['xpath' => '//*[@id="btn_bulk"]/button[1]']); |
||
| 114 | $this->tester->click(['xpath' => '//*[@id="btn_bulk"]/button[1]']); |
||
| 115 | $this->tester->wait(3); |
||
| 116 | $this->tester->click(['id' => 'bulkChange']); |
||
| 117 | return $this; |
||
| 118 | } |
||
| 119 | |||
| 120 | public function 一覧_全選択() |
||
| 121 | { |
||
| 122 | $this->tester->checkOption(['id' => 'check-all']); |
||
| 123 | return $this; |
||
| 124 | } |
||
| 125 | |||
| 126 | /** |
||
| 127 | * TODO: Should remove this function due to new design does not have other dropdown menu |
||
| 128 | */ |
||
| 129 | private function その他メニュー() |
||
| 130 | { |
||
| 131 | $this->tester->click('#dropmenu > a'); |
||
| 132 | } |
||
| 133 | |||
| 134 | public function メール一括通知() |
||
| 135 | { |
||
| 136 | $this->tester->click('#form_bulk #btn_bulk_mail'); |
||
| 137 | } |
||
| 138 | |||
| 139 | public function 一覧_チェックボックス($rowNum) |
||
| 140 | { |
||
| 141 | $this->tester->click(['xpath' => "//*[@id='form_bulk']/div[2]/div/table/tbody/tr[${rowNum}]/td[1]/input"]); |
||
| 142 | } |
||
| 143 | |||
| 144 | public function 取得_出荷伝票番号($rowNum) |
||
| 145 | { |
||
| 146 | return $this->tester->grabTextFrom("#form_bulk table > tbody > tr:nth-child(${rowNum}) > td:nth-child(3)"); |
||
| 147 | } |
||
| 148 | |||
| 149 | public function 取得_出荷日($rowNum) |
||
| 150 | { |
||
| 151 | return $this->tester->grabTextFrom("#form_bulk table > tbody > tr:nth-child(${rowNum}) > td:nth-child(7)"); |
||
| 152 | } |
||
| 153 | } |
||
| 154 |