source: branches/version-2_13_3/test/class/helper/SC_Helper_Address_Test.php @ 22567

Revision 22567, 5.0 KB checked in by shutta, 13 years ago (diff)

#2043 (typo修正・ソース整形・ソースコメントの改善 for 2.12.4)
Zend Framework PHP 標準コーディング規約のコーディングスタイルへ準拠。
classおよびfunctionの開始波括弧「{」のスタイルを修正。

Line 
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 */
13class 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        // ダミーの住所を登録
62        $sqlval = $this->dummy;
63        $sqlval['customer_id'] = $this->customer_id;
64        // 検証用の住所02
65        $sqlval['addr02'] = $create_test = 'create test ' . time();
66        $this->objAddress->registAddress($sqlval);
67
68        // 住所02が検証用のものと同じか確認
69        $this->objQuery->setOrder('other_deliv_id DESC');
70        $created_address = $this->objQuery->getRow('other_deliv_id, addr02', 'dtb_other_deliv', 'customer_id = ?', array($this->customer_id));
71        $this->assertEquals($create_test, $created_address['addr02']);
72
73        $sqlval['other_deliv_id'] = $created_address['other_deliv_id'];
74        // 更新の検証のために住所02を変更
75        $sqlval['addr02'] = $update_test = 'update test ' . time();
76        $this->objAddress->registAddress($sqlval);
77
78        // 住所02が検証用のものと同じか検証
79        $this->objQuery->setOrder('other_deliv_id DESC');
80        $updated_address = $this->objQuery->getRow('addr02', 'dtb_other_deliv', 'other_deliv_id = ?', array($created_address['other_deliv_id']));
81        $this->assertEquals($update_test, $updated_address['addr02']);
82    }
83
84    /**
85     * @depends testSave
86     */
87    function testGetAddress()
88    {
89        // testSave のテストが通っていること前提
90        $sqlval = $this->dummy;
91        $sqlval['customer_id'] = $this->customer_id;
92        $sqlval['addr02'] = 'get test';
93        $this->objAddress->registAddress($sqlval);
94        $this->objQuery->setOrder('other_deliv_id DESC');
95        $other_deliv_id = $this->objQuery->getOne('SELECT other_deliv_id FROM dtb_other_deliv WHERE customer_id = ?', array($this->customer_id));
96        // DBに正しく記録され、取得できているか確認
97        $address = $this->objAddress->getAddress($other_deliv_id);
98        $result = TRUE;
99        foreach ($sqlval as $key => $value) {
100            if ($value != $address[$key]) {
101                $result = FALSE;
102            }
103        }
104        $this->assertTrue($result);
105    }
106
107    /**
108     * @depends testSave
109     */
110    function testGetList()
111    {
112        // testSave のテストが通っていること前提
113        $sqlval = $this->dummy;
114        $sqlval['customer_id'] = $this->customer_id;
115        $sqlval['addr02'] = 'getList test';
116        $this->objAddress->registAddress($sqlval);
117        $list = $this->objAddress->getList($this->customer_id);
118        $found = FALSE;
119        foreach ($list as $address) {
120            $check = TRUE;
121            foreach ($sqlval as $key => $value) {
122                if ($value != $address[$key]) {
123                    $check = FALSE;
124                }
125            }
126            if ($check) {
127                $found = TRUE;
128                break;
129            }
130        }
131        $this->assertTrue($found);
132    }
133
134    /**
135     * @depends testSave
136     */
137    function testDeleteAddress()
138    {
139        // testSave のテストが通っていること前提
140        $sqlval = $this->dummy;
141        $sqlval['customer_id'] = $this->customer_id;
142        $sqlval['addr02'] = 'delete test';
143        $this->objAddress->registAddress($sqlval);
144        $this->objQuery->setOrder('other_deliv_id DESC');
145        $other_deliv_id = $this->objQuery->getOne('SELECT other_deliv_id FROM dtb_other_deliv WHERE customer_id = ?', array($this->customer_id));
146        $this->objAddress->deleteAddress($other_deliv_id);
147        $result = $this->objQuery->getRow('*', 'dtb_other_deliv', 'customer_id = ? and other_deliv_id = ?', array($this->customer_id, $other_deliv_id));
148        $this->assertNull($result);
149    }
150}
Note: See TracBrowser for help on using the repository browser.