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-2010 Zend Technologies USA Inc. (http://www.zend.com)
19 * @license http://framework.zend.com/license/new-bsd New BSD License
23 // Call Zend_Validate_File_NotExistsTest::main() if this source file is executed directly.
24 if (!defined("PHPUnit_MAIN_METHOD")) {
25 define("PHPUnit_MAIN_METHOD", "Zend_Validate_File_NotExistsTest::main");
31 require_once dirname(__FILE__
) . '/../../../TestHelper.php';
34 * @see Zend_Validate_File_Size
36 require_once 'Zend/Validate/File/NotExists.php';
42 * @package Zend_Validate_File
43 * @subpackage UnitTests
44 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
45 * @license http://framework.zend.com/license/new-bsd New BSD License
46 * @group Zend_Validate
48 class Zend_Validate_File_NotExistsTest
extends PHPUnit_Framework_TestCase
51 * Runs the test methods of this class.
55 public static function main()
57 $suite = new PHPUnit_Framework_TestSuite("Zend_Validate_File_NotExistsTest");
58 $result = PHPUnit_TextUI_TestRunner
::run($suite);
62 * Ensures that the validator follows expected behavior
66 public function testBasic()
68 $baseDir = dirname(__FILE__
);
69 $valuesExpected = array(
70 array($baseDir, 'testsize.mo', true),
71 array($baseDir . '/_files', 'testsize.mo', false)
75 'name' => 'testsize.mo',
78 'tmp_name' => dirname(__FILE__
) . '/_files/testsize.mo',
82 foreach ($valuesExpected as $element) {
83 $validator = new Zend_Validate_File_NotExists($element[0]);
86 $validator->isValid($element[1]),
87 "Tested with " . var_export($element, 1)
91 $validator->isValid($element[1], $files),
92 "Tested with " . var_export($element, 1)
96 $valuesExpected = array(
97 array($baseDir, 'testsize.mo', true, false),
98 array($baseDir . '/_files', 'testsize.mo', false, false)
102 'name' => 'testsize.mo',
105 'tmp_name' => dirname(__FILE__
) . '/_files/testsize.mo',
107 'destination' => dirname(__FILE__
) . '/_files'
110 foreach ($valuesExpected as $element) {
111 $validator = new Zend_Validate_File_NotExists($element[0]);
114 $validator->isValid($element[1]),
115 "Tested with " . var_export($element, 1)
119 $validator->isValid($element[1], $files),
120 "Tested with " . var_export($element, 1)
124 $valuesExpected = array(
125 array($baseDir, 'testsize.mo', false, false),
126 array($baseDir . '/_files', 'testsize.mo', false, false)
129 foreach ($valuesExpected as $element) {
130 $validator = new Zend_Validate_File_NotExists();
133 $validator->isValid($element[1]),
134 "Tested with " . var_export($element, 1)
138 $validator->isValid($element[1], $files),
139 "Tested with " . var_export($element, 1)
145 * Ensures that getDirectory() returns expected value
149 public function testGetDirectory()
151 $validator = new Zend_Validate_File_NotExists('C:/temp');
152 $this->assertEquals('C:/temp', $validator->getDirectory());
154 $validator = new Zend_Validate_File_NotExists(array('temp', 'dir', 'jpg'));
155 $this->assertEquals('temp,dir,jpg', $validator->getDirectory());
157 $validator = new Zend_Validate_File_NotExists(array('temp', 'dir', 'jpg'));
158 $this->assertEquals(array('temp', 'dir', 'jpg'), $validator->getDirectory(true));
162 * Ensures that setDirectory() returns expected value
166 public function testSetDirectory()
168 $validator = new Zend_Validate_File_NotExists('temp');
169 $validator->setDirectory('gif');
170 $this->assertEquals('gif', $validator->getDirectory());
171 $this->assertEquals(array('gif'), $validator->getDirectory(true));
173 $validator->setDirectory('jpg, temp');
174 $this->assertEquals('jpg,temp', $validator->getDirectory());
175 $this->assertEquals(array('jpg', 'temp'), $validator->getDirectory(true));
177 $validator->setDirectory(array('zip', 'ti'));
178 $this->assertEquals('zip,ti', $validator->getDirectory());
179 $this->assertEquals(array('zip', 'ti'), $validator->getDirectory(true));
183 * Ensures that addDirectory() returns expected value
187 public function testAddDirectory()
189 $validator = new Zend_Validate_File_NotExists('temp');
190 $validator->addDirectory('gif');
191 $this->assertEquals('temp,gif', $validator->getDirectory());
192 $this->assertEquals(array('temp', 'gif'), $validator->getDirectory(true));
194 $validator->addDirectory('jpg, to');
195 $this->assertEquals('temp,gif,jpg,to', $validator->getDirectory());
196 $this->assertEquals(array('temp', 'gif', 'jpg', 'to'), $validator->getDirectory(true));
198 $validator->addDirectory(array('zip', 'ti'));
199 $this->assertEquals('temp,gif,jpg,to,zip,ti', $validator->getDirectory());
200 $this->assertEquals(array('temp', 'gif', 'jpg', 'to', 'zip', 'ti'), $validator->getDirectory(true));
202 $validator->addDirectory('');
203 $this->assertEquals('temp,gif,jpg,to,zip,ti', $validator->getDirectory());
204 $this->assertEquals(array('temp', 'gif', 'jpg', 'to', 'zip', 'ti'), $validator->getDirectory(true));
208 // Call Zend_Validate_File_NotExistsTest::main() if this source file is executed directly.
209 if (PHPUnit_MAIN_METHOD
== "Zend_Validate_File_NotExistsTest::main") {
210 Zend_Validate_File_NotExistsTest
::main();