PageRenderTime 406ms CodeModel.GetById 221ms app.highlight 9ms RepoModel.GetById 172ms app.codeStats 0ms

/ZendFramework-1.10.0/tests/Zend/Validate/File/Md5Test.php

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