PageRenderTime 395ms CodeModel.GetById 201ms app.highlight 9ms RepoModel.GetById 182ms app.codeStats 0ms

/DevApp/library/ServerLibraries/ZendFramework/1.7/tests/Zend/Validate/File/Md5Test.php

http://firephp.googlecode.com/
PHP | 212 lines | 112 code | 23 blank | 77 comment | 3 complexity | b86ad884f4b2673132847cde849e6ae6 MD5 | raw file
  1<?php
  2/**
  3 * Zend Framework
  4 *
  5 * LICENSE
  6 *
  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.
 14 *
 15 * @category   Zend
 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: $
 21 */
 22
 23// Call Zend_Validate_File_Md5Test::main() if this source file is executed directly.
 24if (!defined("PHPUnit_MAIN_METHOD")) {
 25    define("PHPUnit_MAIN_METHOD", "Zend_Validate_File_Md5Test::main");
 26}
 27
 28/**
 29 * Test helper
 30 */
 31require_once dirname(__FILE__) . '/../../../TestHelper.php';
 32
 33/**
 34 * @see Zend_Validate_File_Md5
 35 */
 36require_once 'Zend/Validate/File/Md5.php';
 37
 38/**
 39 * Md5 testbed
 40 *
 41 * @category   Zend
 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
 46 */
 47class Zend_Validate_File_Md5Test extends PHPUnit_Framework_TestCase
 48{
 49    /**
 50     * Runs the test methods of this class.
 51     *
 52     * @return void
 53     */
 54    public static function main()
 55    {
 56        $suite  = new PHPUnit_Framework_TestSuite("Zend_Validate_File_Md5Test");
 57        $result = PHPUnit_TextUI_TestRunner::run($suite);
 58    }
 59
 60    /**
 61     * Ensures that the validator follows expected behavior
 62     *
 63     * @return void
 64     */
 65    public function testBasic()
 66    {
 67        $valuesExpected = array(
 68            array('ed74c22109fe9f110579f77b053b8bc3', true),
 69            array('4d74c22109fe9f110579f77b053b8bc3', false),
 70            array(array('4d74c22109fe9f110579f77b053b8bc3', 'ed74c22109fe9f110579f77b053b8bc3'), true),
 71            array(array('4d74c22109fe9f110579f77b053b8bc3', '7d74c22109fe9f110579f77b053b8bc3'), false),
 72        );
 73
 74        foreach ($valuesExpected as $element) {
 75            $validator = new Zend_Validate_File_Md5($element[0]);
 76            $this->assertEquals(
 77                $element[1],
 78                $validator->isValid(dirname(__FILE__) . '/_files/picture.jpg'),
 79                "Tested with " . var_export($element, 1)
 80            );
 81        }
 82
 83        $validator = new Zend_Validate_File_Md5('ed74c22109fe9f110579f77b053b8bc3');
 84        $this->assertFalse($validator->isValid(dirname(__FILE__) . '/_files/nofile.mo'));
 85        $this->assertTrue(array_key_exists('fileMd5NotFound', $validator->getMessages()));
 86
 87        $files = array(
 88            'name'     => 'test1',
 89            'type'     => 'text',
 90            'size'     => 200,
 91            'tmp_name' => 'tmp_test1',
 92            'error'    => 0
 93        );
 94        $validator = new Zend_Validate_File_Md5('ed74c22109fe9f110579f77b053b8bc3');
 95        $this->assertFalse($validator->isValid(dirname(__FILE__) . '/_files/nofile.mo', $files));
 96        $this->assertTrue(array_key_exists('fileMd5NotFound', $validator->getMessages()));
 97
 98        $files = array(
 99            'name'     => 'testsize.mo',
100            'type'     => 'text',
101            'size'     => 200,
102            'tmp_name' => dirname(__FILE__) . '/_files/testsize.mo',
103            'error'    => 0
104        );
105        $validator = new Zend_Validate_File_Md5('ed74c22109fe9f110579f77b053b8bc3');
106        $this->assertTrue($validator->isValid(dirname(__FILE__) . '/_files/picture.jpg', $files));
107
108        $files = array(
109            'name'     => 'testsize.mo',
110            'type'     => 'text',
111            'size'     => 200,
112            'tmp_name' => dirname(__FILE__) . '/_files/testsize.mo',
113            'error'    => 0
114        );
115        $validator = new Zend_Validate_File_Md5('7d74c22109fe9f110579f77b053b8bc3');
116        $this->assertFalse($validator->isValid(dirname(__FILE__) . '/_files/picture.jpg', $files));
117        $this->assertTrue(array_key_exists('fileMd5DoesNotMatch', $validator->getMessages()));
118    }
119
120    /**
121     * Ensures that getMd5() returns expected value
122     *
123     * @return void
124     */
125    public function testgetMd5()
126    {
127        $validator = new Zend_Validate_File_Md5('12345');
128        $this->assertEquals(array('12345' => 'md5'), $validator->getMd5());
129
130        $validator = new Zend_Validate_File_Md5(array('12345', '12333', '12344'));
131        $this->assertEquals(array('12345' => 'md5', '12333' => 'md5', '12344' => 'md5'), $validator->getMd5());
132    }
133
134    /**
135     * Ensures that getHash() returns expected value
136     *
137     * @return void
138     */
139    public function testgetHash()
140    {
141        $validator = new Zend_Validate_File_Md5('12345');
142        $this->assertEquals(array('12345' => 'md5'), $validator->getHash());
143
144        $validator = new Zend_Validate_File_Md5(array('12345', '12333', '12344'));
145        $this->assertEquals(array('12345' => 'md5', '12333' => 'md5', '12344' => 'md5'), $validator->getHash());
146    }
147
148    /**
149     * Ensures that setMd5() returns expected value
150     *
151     * @return void
152     */
153    public function testSetMd5()
154    {
155        $validator = new Zend_Validate_File_Md5('12345');
156        $validator->setMd5('12333');
157        $this->assertEquals(array('12333' => 'md5'), $validator->getMd5());
158        
159        $validator->setMd5(array('12321', '12121'));
160        $this->assertEquals(array('12321' => 'md5', '12121' => 'md5'), $validator->getMd5());
161    }
162
163    /**
164     * Ensures that setHash() returns expected value
165     *
166     * @return void
167     */
168    public function testSetHash()
169    {
170        $validator = new Zend_Validate_File_Md5('12345');
171        $validator->setHash('12333');
172        $this->assertEquals(array('12333' => 'md5'), $validator->getMd5());
173        
174        $validator->setHash(array('12321', '12121'));
175        $this->assertEquals(array('12321' => 'md5', '12121' => 'md5'), $validator->getMd5());
176    }
177
178    /**
179     * Ensures that addMd5() returns expected value
180     *
181     * @return void
182     */
183    public function testAddMd5()
184    {
185        $validator = new Zend_Validate_File_Md5('12345');
186        $validator->addMd5('12344');
187        $this->assertEquals(array('12345' => 'md5', '12344' => 'md5'), $validator->getMd5());
188
189        $validator->addMd5(array('12321', '12121'));
190        $this->assertEquals(array('12345' => 'md5', '12344' => 'md5', '12321' => 'md5', '12121' => 'md5'), $validator->getMd5());
191    }
192
193    /**
194     * Ensures that addHash() returns expected value
195     *
196     * @return void
197     */
198    public function testAddHash()
199    {
200        $validator = new Zend_Validate_File_Md5('12345');
201        $validator->addHash('12344');
202        $this->assertEquals(array('12345' => 'md5', '12344' => 'md5'), $validator->getMd5());
203
204        $validator->addHash(array('12321', '12121'));
205        $this->assertEquals(array('12345' => 'md5', '12344' => 'md5', '12321' => 'md5', '12121' => 'md5'), $validator->getMd5());
206    }
207}
208
209// Call Zend_Validate_File_Md5Test::main() if this source file is executed directly.
210if (PHPUnit_MAIN_METHOD == "Zend_Validate_File_Md5Test::main") {
211    Zend_Validate_File_Md5Test::main();
212}