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