source: branches/version-2_12-dev/tests/class/util/SC_Utils/SC_Utils_sfGetAddressTest.php @ 22199

Revision 22199, 5.1 KB checked in by shift_hiroko.tamagawa, 11 years ago (diff)

#1977 SC_Utilsの単体テストを追加・修正

  • Property svn:keywords set to Id Rev Date
Line 
1<?php
2
3$HOME = realpath(dirname(__FILE__)) . "/../../../..";
4require_once($HOME . "/tests/class/Common_TestCase.php");
5/*
6 * This file is part of EC-CUBE
7 *
8 * Copyright(c) 2000-2012 LOCKON CO.,LTD. All Rights Reserved.
9 *
10 * http://www.lockon.co.jp/
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25 */
26
27/**
28 * SC_Utils::sfGetAddress()のテストクラス.
29 *
30 *
31 * @author Hiroko Tamagawa
32 * @version $Id$
33 */
34class SC_Utils_sfGetAddressTest extends Common_TestCase {
35
36
37  protected function setUp() {
38    parent::setUp();
39    $this->setUpAddress();
40  }
41
42  protected function tearDown() {
43    parent::tearDown();
44  }
45
46  /////////////////////////////////////////
47  public function test_住所がヒットしない場合_空の配列が返る() {
48    $this->expected = array();
49    $this->actual = SC_Utils::sfGetAddress('9999999');
50
51    $this->verify('郵便番号検索結果');
52  }
53
54  public function test_住所が一件だけヒットする場合_住所データが取得できる() {
55    $this->expected = array(
56      array(
57        'state' => '1',    // 北海道
58        'city' => '札幌市中央区',
59        'town' => '大通東'
60      )
61    );
62    $this->actual = SC_Utils::sfGetAddress('0600041');
63
64    $this->verify('郵便番号検索結果');
65  }
66
67  // TODO 二件目に関しては件名のIDへの変換と町名の削除が行われない。
68  // 今の仕様ではこれでOKかもしれないが、そもそも一件目しか使わないのなら
69  // $data_list[0]を返した方が良いのでは?
70  public function test_住所が二件以上ヒットする場合_町名を消した住所データが取得できる() {
71    $this->expected = array(
72      array(
73        'state' => '5',    // 秋田県
74        'city' => '秋田市',
75        'town' => ''
76      ),
77      array(
78        'state' => '5',
79        'city' => '秋田市',
80        'town' => ''
81      )
82    );
83    $this->actual = SC_Utils::sfGetAddress('0110951');
84
85    $this->verify('郵便番号検索結果');
86  }
87
88  public function test_住所に但し書きが含まれる場合_但し書きが消去される() {
89    $this->expected = array(
90      array(
91        'state' => '1',    // 北海道
92        'city' => '札幌市中央区',
93        'town' => '大通西'
94      )
95    );
96    $this->actual = SC_Utils::sfGetAddress('0600042');
97
98    $this->verify('郵便番号検索結果');
99  }
100
101  public function test_住所に注意文言がある場合_町名が消去される() {
102    $this->expected = array(
103      array(
104        'state' => '1',    // 北海道
105        'city' => '札幌市中央区',
106        'town' => ''
107      )
108    );
109    $this->actual = SC_Utils::sfGetAddress('0600000');
110
111    $this->verify('郵便番号検索結果');
112  }
113
114  public function test_住所に番地の説明が含まれる場合_町名が消去される() {
115    $this->expected = array(
116      array(
117        'state' => '8',    // 茨城県
118        'city' => '猿島郡堺町',
119        'town' => ''
120      )
121    );
122    $this->actual = SC_Utils::sfGetAddress('3060433');
123
124    $this->verify('郵便番号検索結果');
125  }
126
127  //////////////////////////////////////////
128
129  protected function setUpAddress() {
130
131    $address = array(
132      array(
133        'zip_id' => '2',
134        'zipcode' => '0600041',
135        'state' => '北海道',
136        'city' => '札幌市中央区',
137        'town' => '大通東'
138      ),
139      array(
140        'zip_id' => '3',
141        'zipcode' => '0600042',
142        'state' => '北海道',
143        'city' => '札幌市中央区',
144        'town' => '大通西(1〜19丁目)'
145      ),
146      array(
147        'zip_id' => '0',
148        'zipcode' => '0600000',
149        'state' => '北海道',
150        'city' => '札幌市中央区',
151        'town' => '以下に掲載がない場合'
152      ),
153      array(
154        'zip_id' => '26867',
155        'zipcode' => '3060433',
156        'state' => '茨城県',
157        'city' => '猿島郡堺町',
158        'town' => '堺町の次に番地がくる場合'
159      ),
160      array(
161        'zip_id' => '16223',
162        'zipcode' => '0110951',
163        'state' => '秋田県',
164        'city' => '秋田市',
165        'town' => '土崎港相染町'
166      ),
167      array(
168        'zip_id' => '16226',
169        'zipcode' => '0110951',
170        'state' => '秋田県',
171        'city' => '秋田市',
172        'town' => '土崎港古川町'
173      )
174    );
175
176    $this->objQuery->delete('mtb_zip');
177    foreach ($address as $item) {
178      $this->objQuery->insert('mtb_zip', $item);
179    }
180  }
181}
182
Note: See TracBrowser for help on using the repository browser.