1 | <?php
|
---|
2 |
|
---|
3 | /*
|
---|
4 | * To change this template, choose Tools | Templates
|
---|
5 | * and open the template in the editor.
|
---|
6 | */
|
---|
7 |
|
---|
8 | /**
|
---|
9 | * Description of SC_Helper_Address_Test
|
---|
10 | *
|
---|
11 | * @author cyberwill
|
---|
12 | */
|
---|
13 | class SC_Helper_Address_Test extends PHPUnit_Framework_TestCase
|
---|
14 | {
|
---|
15 | public $objQuery = "";
|
---|
16 | public $objAddress = "";
|
---|
17 | public $customer_id = "";
|
---|
18 |
|
---|
19 | public $dummy = array(
|
---|
20 | 'name01' => '追加',
|
---|
21 | 'name02' => '住所',
|
---|
22 | 'kana01' => 'ツイカ',
|
---|
23 | 'kana02' => 'ジュウショ',
|
---|
24 | 'zip01' => '123',
|
---|
25 | 'zip02' => '4567',
|
---|
26 | 'pref' => '23',
|
---|
27 | 'addr01' => 'その他のお届け先',
|
---|
28 | 'addr02' => '',
|
---|
29 | 'tel01' => '0123',
|
---|
30 | 'tel02' => '4567',
|
---|
31 | 'tel03' => '8901',
|
---|
32 | 'fax01' => '',
|
---|
33 | 'fax02' => '',
|
---|
34 | 'fax03' => '',
|
---|
35 | );
|
---|
36 |
|
---|
37 | /**
|
---|
38 | * Sets up the fixture, for example, opens a network connection.
|
---|
39 | * This method is called before a test is executed.
|
---|
40 | */
|
---|
41 | protected function setUp()
|
---|
42 | {
|
---|
43 | $this->objQuery =& SC_Query::getSingletonInstance();
|
---|
44 | $this->objQuery->begin();
|
---|
45 | $arrRet = $this->objQuery->getOne('SELECT MAX(customer_id) FROM dtb_customer');
|
---|
46 | $this->customer_id = $arrRet;
|
---|
47 | $this->objAddress = new SC_Helper_Address_Ex();
|
---|
48 | }
|
---|
49 |
|
---|
50 | /**
|
---|
51 | * Tears down the fixture, for example, closes a network connection.
|
---|
52 | * This method is called after a test is executed.
|
---|
53 | */
|
---|
54 | protected function tearDown()
|
---|
55 | {
|
---|
56 | $this->objQuery->rollback();
|
---|
57 | }
|
---|
58 |
|
---|
59 | function testRegistAddress() {
|
---|
60 | // ダミーの住所を登録
|
---|
61 | $sqlval = $this->dummy;
|
---|
62 | $sqlval['customer_id'] = $this->customer_id;
|
---|
63 | // 検証用の住所02
|
---|
64 | $sqlval['addr02'] = $create_test = 'create test ' . time();
|
---|
65 | $this->objAddress->registAddress($sqlval);
|
---|
66 |
|
---|
67 | // 住所02が検証用のものと同じか確認
|
---|
68 | $this->objQuery->setOrder('other_deliv_id DESC');
|
---|
69 | $created_address = $this->objQuery->getRow('other_deliv_id, addr02', 'dtb_other_deliv', 'customer_id = ?', array($this->customer_id));
|
---|
70 | $this->assertEquals($create_test, $created_address['addr02']);
|
---|
71 |
|
---|
72 | $sqlval['other_deliv_id'] = $created_address['other_deliv_id'];
|
---|
73 | // 更新の検証のために住所02を変更
|
---|
74 | $sqlval['addr02'] = $update_test = 'update test ' . time();
|
---|
75 | $this->objAddress->registAddress($sqlval);
|
---|
76 |
|
---|
77 | // 住所02が検証用のものと同じか検証
|
---|
78 | $this->objQuery->setOrder('other_deliv_id DESC');
|
---|
79 | $updated_address = $this->objQuery->getRow('addr02', 'dtb_other_deliv', 'other_deliv_id = ?', array($created_address['other_deliv_id']));
|
---|
80 | $this->assertEquals($update_test, $updated_address['addr02']);
|
---|
81 | }
|
---|
82 |
|
---|
83 | /**
|
---|
84 | * @depends testSave
|
---|
85 | */
|
---|
86 | function testGetAddress() {
|
---|
87 | // testSave のテストが通っていること前提
|
---|
88 | $sqlval = $this->dummy;
|
---|
89 | $sqlval['customer_id'] = $this->customer_id;
|
---|
90 | $sqlval['addr02'] = 'get test';
|
---|
91 | $this->objAddress->registAddress($sqlval);
|
---|
92 | $this->objQuery->setOrder('other_deliv_id DESC');
|
---|
93 | $other_deliv_id = $this->objQuery->getOne('SELECT other_deliv_id FROM dtb_other_deliv WHERE customer_id = ?', array($this->customer_id));
|
---|
94 | // DBに正しく記録され、取得できているか確認
|
---|
95 | $address = $this->objAddress->getAddress($other_deliv_id);
|
---|
96 | $result = TRUE;
|
---|
97 | foreach ($sqlval as $key => $value) {
|
---|
98 | if ($value != $address[$key]) {
|
---|
99 | $result = FALSE;
|
---|
100 | }
|
---|
101 | }
|
---|
102 | $this->assertTrue($result);
|
---|
103 | }
|
---|
104 |
|
---|
105 | /**
|
---|
106 | * @depends testSave
|
---|
107 | */
|
---|
108 | function testGetList() {
|
---|
109 | // testSave のテストが通っていること前提
|
---|
110 | $sqlval = $this->dummy;
|
---|
111 | $sqlval['customer_id'] = $this->customer_id;
|
---|
112 | $sqlval['addr02'] = 'getList test';
|
---|
113 | $this->objAddress->registAddress($sqlval);
|
---|
114 | $list = $this->objAddress->getList($this->customer_id);
|
---|
115 | $found = FALSE;
|
---|
116 | foreach ($list as $address) {
|
---|
117 | $check = TRUE;
|
---|
118 | foreach ($sqlval as $key => $value) {
|
---|
119 | if ($value != $address[$key]) {
|
---|
120 | $check = FALSE;
|
---|
121 | }
|
---|
122 | }
|
---|
123 | if ($check) {
|
---|
124 | $found = TRUE;
|
---|
125 | break;
|
---|
126 | }
|
---|
127 | }
|
---|
128 | $this->assertTrue($found);
|
---|
129 | }
|
---|
130 |
|
---|
131 | /**
|
---|
132 | * @depends testSave
|
---|
133 | */
|
---|
134 | function testDeleteAddress() {
|
---|
135 | // testSave のテストが通っていること前提
|
---|
136 | $sqlval = $this->dummy;
|
---|
137 | $sqlval['customer_id'] = $this->customer_id;
|
---|
138 | $sqlval['addr02'] = 'delete test';
|
---|
139 | $this->objAddress->registAddress($sqlval);
|
---|
140 | $this->objQuery->setOrder('other_deliv_id DESC');
|
---|
141 | $other_deliv_id = $this->objQuery->getOne('SELECT other_deliv_id FROM dtb_other_deliv WHERE customer_id = ?', array($this->customer_id));
|
---|
142 | $this->objAddress->deleteAddress($other_deliv_id);
|
---|
143 | $result = $this->objQuery->getRow('*', 'dtb_other_deliv', 'customer_id = ? and other_deliv_id = ?', array($this->customer_id, $other_deliv_id));
|
---|
144 | $this->assertNull($result);
|
---|
145 | }
|
---|
146 | }
|
---|