PageRenderTime 94ms CodeModel.GetById 18ms app.highlight 18ms RepoModel.GetById 1ms app.codeStats 1ms

/tests/Zend/Validate/File/Md5Test.php

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