source: branches/version-2_13-dev/tests/class/SC_CheckError/SC_CheckError_FILE_NAME_CHECK_BY_NOUPLOADTest.php @ 23546

Revision 23546, 3.9 KB checked in by shutta, 10 years ago (diff)

#2580 Copyrightを更新
Copyrightを2014に更新

Line 
1<?php
2/*
3 * This file is part of EC-CUBE
4 *
5 * Copyright(c) 2000-2014 LOCKON CO.,LTD. All Rights Reserved.
6 *
7 * http://www.lockon.co.jp/
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22 */
23
24$HOME = realpath(dirname(__FILE__)) . "/../../..";
25require_once($HOME . "/tests/class/Common_TestCase.php");
26
27class SC_CheckError_FILE_NAME_CHECK_BY_NOUPLOADTest extends Common_TestCase
28{
29
30    public function setUp() {
31        set_error_handler(function($errno, $errstr, $errfile, $errline) {
32            throw new RuntimeException($errstr . " on line " . $errline . " in file " . $errfile);
33        });
34    }
35
36    public function tearDown() {
37        restore_error_handler();
38    }
39
40    public function validValueProvider()
41    {
42        return array(
43            array('a'),
44            array('012'),
45            array('abc012'),
46            array('a.txt'),
47            array('a-b.zip'),
48            array('a-b_c.tar.gz'),
49        );
50    }
51
52    public function invalidValueProvider()
53    {
54        return array(
55            array("line1\nline2"),
56            array("a\x00b"),
57            array('a/b'),
58            array('a b'),
59            array('日本語'),
60            array('日 本 語'),
61        );
62    }
63
64    public function testFILE_NAME_CHECK_BY_NOUPLOAD_空文字列の場合_エラーをセットしない()
65    {
66        $arrForm = array('file' => '');
67        $objErr = new SC_CheckError_Ex($arrForm);
68        $objErr->doFunc(array('label', 'file') ,array('FILE_NAME_CHECK_BY_NOUPLOAD'));
69
70        $this->expected = false;
71        $this->actual = isset($objErr->arrErr['file']);
72        $this->verify();
73    }
74
75    /**
76     * @dataProvider validValueProvider
77     */
78    public function testFILE_NAME_CHECK_BY_NOUPLOAD_使用できない文字が含まれていない場合_エラーをセットしない($value)
79    {
80        $arrForm = array('file' => $value);
81        $objErr = new SC_CheckError_Ex($arrForm);
82        $objErr->doFunc(array('label', 'file') ,array('FILE_NAME_CHECK_BY_NOUPLOAD'));
83
84        $this->expected = false;
85        $this->actual = isset($objErr->arrErr['file']);
86        $this->verify();
87    }
88
89    /**
90     * @dataProvider invalidValueProvider
91     */
92    public function testFILE_NAME_CHECK_BY_NOUPLOAD_使用できない文字が含まれている場合_エラーをセットする($value)
93    {
94        $arrForm = array('file' => $value);
95        $objErr = new SC_CheckError_Ex($arrForm);
96        $objErr->doFunc(array('label', 'file') ,array('FILE_NAME_CHECK_BY_NOUPLOAD'));
97
98        $this->expected = true;
99        $this->actual = isset($objErr->arrErr['file']);
100        $this->verify();
101    }
102
103    /**
104     * @depends testFILE_NAME_CHECK_BY_NOUPLOAD_使用できない文字が含まれている場合_エラーをセットする
105     */
106    public function testFILE_NAME_CHECK_BY_NOUPLOAD_他のエラーが既にセットされている場合_エラーを上書きしない()
107    {
108        $arrForm = array('file' => 'a/b');
109        $objErr = new SC_CheckError_Ex($arrForm);
110        $objErr->arrErr['file'] = $other_error = 'Unknown error.';
111        $objErr->doFunc(array('label', 'file') ,array('FILE_NAME_CHECK_BY_NOUPLOAD'));
112
113        $this->expected = $other_error;
114        $this->actual = $objErr->arrErr['file'];
115        $this->verify();
116    }
117}
Note: See TracBrowser for help on using the repository browser.