7
* This source file is subject to the new BSD license that is bundled
8
* with this package in the file LICENSE.txt.
9
* It is also available through the world-wide-web at this URL:
10
* http://framework.zend.com/license/new-bsd
11
* If you did not receive a copy of the license and are unable to
12
* obtain it through the world-wide-web, please send an email
13
* to license@zend.com so we can send you a copy immediately.
16
* @package Zend_Validate_File
17
* @subpackage UnitTests
18
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
19
* @license http://framework.zend.com/license/new-bsd New BSD License
20
* @version $Id: ExtensionTest.php 12541 2008-11-11 05:44:35Z matthew $
23
// Call Zend_Validate_File_ExtensionTest::main() if this source file is executed directly.
24
if (!defined("PHPUnit_MAIN_METHOD")) {
25
define("PHPUnit_MAIN_METHOD", "Zend_Validate_File_ExtensionTest::main");
31
require_once dirname(__FILE__) . '/../../../TestHelper.php';
34
* @see Zend_Validate_File_Extension
36
require_once 'Zend/Validate/File/Extension.php';
42
* @package Zend_Validate_File
43
* @subpackage UnitTests
44
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
45
* @license http://framework.zend.com/license/new-bsd New BSD License
47
class Zend_Validate_File_ExtensionTest extends PHPUnit_Framework_TestCase
50
* Runs the test methods of this class.
54
public static function main()
56
$suite = new PHPUnit_Framework_TestSuite("Zend_Validate_File_ExtensionTest");
57
$result = PHPUnit_TextUI_TestRunner::run($suite);
61
* Ensures that the validator follows expected behavior
65
public function testBasic()
67
$valuesExpected = array(
70
array(array('mo'), true),
71
array(array('gif'), false),
72
array(array('gif', 'pdf', 'mo', 'pict'), true),
73
array(array('gif', 'gz', 'hint'), false),
76
foreach ($valuesExpected as $element) {
77
$validator = new Zend_Validate_File_Extension($element[0]);
80
$validator->isValid(dirname(__FILE__) . '/_files/testsize.mo'),
81
"Tested with " . var_export($element, 1)
85
$validator = new Zend_Validate_File_Extension('mo');
86
$this->assertEquals(false, $validator->isValid(dirname(__FILE__) . '/_files/nofile.mo'));
87
$this->assertTrue(array_key_exists('fileExtensionNotFound', $validator->getMessages()));
93
'tmp_name' => 'tmp_test1',
96
$validator = new Zend_Validate_File_Extension('mo');
97
$this->assertEquals(false, $validator->isValid(dirname(__FILE__) . '/_files/nofile.mo', $files));
98
$this->assertTrue(array_key_exists('fileExtensionNotFound', $validator->getMessages()));
101
'name' => 'testsize.mo',
104
'tmp_name' => dirname(__FILE__) . '/_files/testsize.mo',
107
$validator = new Zend_Validate_File_Extension('mo');
108
$this->assertEquals(true, $validator->isValid(dirname(__FILE__) . '/_files/testsize.mo', $files));
111
'name' => 'testsize.mo',
114
'tmp_name' => dirname(__FILE__) . '/_files/testsize.mo',
117
$validator = new Zend_Validate_File_Extension('gif');
118
$this->assertEquals(false, $validator->isValid(dirname(__FILE__) . '/_files/testsize.mo', $files));
119
$this->assertTrue(array_key_exists('fileExtensionFalse', $validator->getMessages()));
122
public function testZF3891()
125
'name' => 'testsize.mo',
128
'tmp_name' => dirname(__FILE__) . '/_files/testsize.mo',
131
$validator = new Zend_Validate_File_Extension(array('MO', 'case' => true));
132
$this->assertEquals(false, $validator->isValid(dirname(__FILE__) . '/_files/testsize.mo', $files));
134
$validator = new Zend_Validate_File_Extension(array('MO', 'case' => false));
135
$this->assertEquals(true, $validator->isValid(dirname(__FILE__) . '/_files/testsize.mo', $files));
139
* Ensures that getExtension() returns expected value
143
public function testGetExtension()
145
$validator = new Zend_Validate_File_Extension('mo');
146
$this->assertEquals(array('mo'), $validator->getExtension());
148
$validator = new Zend_Validate_File_Extension(array('mo', 'gif', 'jpg'));
149
$this->assertEquals(array('mo', 'gif', 'jpg'), $validator->getExtension());
153
* Ensures that setExtension() returns expected value
157
public function testSetExtension()
159
$validator = new Zend_Validate_File_Extension('mo');
160
$validator->setExtension('gif');
161
$this->assertEquals(array('gif'), $validator->getExtension());
163
$validator->setExtension('jpg, mo');
164
$this->assertEquals(array('jpg', 'mo'), $validator->getExtension());
166
$validator->setExtension(array('zip', 'ti'));
167
$this->assertEquals(array('zip', 'ti'), $validator->getExtension());
171
* Ensures that addExtension() returns expected value
175
public function testAddExtension()
177
$validator = new Zend_Validate_File_Extension('mo');
178
$validator->addExtension('gif');
179
$this->assertEquals(array('mo', 'gif'), $validator->getExtension());
181
$validator->addExtension('jpg, to');
182
$this->assertEquals(array('mo', 'gif', 'jpg', 'to'), $validator->getExtension());
184
$validator->addExtension(array('zip', 'ti'));
185
$this->assertEquals(array('mo', 'gif', 'jpg', 'to', 'zip', 'ti'), $validator->getExtension());
187
$validator->addExtension('');
188
$this->assertEquals(array('mo', 'gif', 'jpg', 'to', 'zip', 'ti'), $validator->getExtension());
192
// Call Zend_Validate_File_ExtensionTest::main() if this source file is executed directly.
193
if (PHPUnit_MAIN_METHOD == "Zend_Validate_File_ExtensionTest::main") {
194
Zend_Validate_File_ExtensionTest::main();