Alpha Framework alpha--tests
[ class tree: alpha--tests ] [ index: alpha--tests ] [ all elements ]

Source for file Image_Test.php

Documentation is available at Image_Test.php

  1. <?php
  2.  
  3. require_once $config->get('sysRoot').'alpha/view/widgets/Image.inc';
  4.  
  5. /**
  6.  *
  7.  * Test case for the Image generation widget
  8.  * 
  9.  * @package alpha::tests
  10.  * @since 1.0
  11.  * @author John Collins <dev@alphaframework.org>
  12.  * @version $Id: Image_Test.php 1341 2011-03-17 15:02:02Z johnc $
  13.  * @license http://www.opensource.org/licenses/bsd-license.php The BSD License
  14.  * @copyright Copyright (c) 2011, John Collins (founder of Alpha Framework).
  15.  *  All rights reserved.
  16.  * 
  17.  *  <pre>
  18.  *  Redistribution and use in source and binary forms, with or
  19.  *  without modification, are permitted provided that the
  20.  *  following conditions are met:
  21.  * 
  22.  *  * Redistributions of source code must retain the above
  23.  *    copyright notice, this list of conditions and the
  24.  *    following disclaimer.
  25.  *  * Redistributions in binary form must reproduce the above
  26.  *    copyright notice, this list of conditions and the
  27.  *    following disclaimer in the documentation and/or other
  28.  *    materials provided with the distribution.
  29.  *  * Neither the name of the Alpha Framework nor the names
  30.  *    of its contributors may be used to endorse or promote
  31.  *    products derived from this software without specific
  32.  *    prior written permission.
  33.  *   
  34.  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
  35.  *  CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
  36.  *  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  37.  *  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  38.  *  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
  39.  *  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  40.  *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  41.  *  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  42.  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  43.  *  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  44.  *  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
  45.  *  OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  46.  *  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  47.  *  </pre>
  48.  *  
  49.  */
  50. class Image_Test extends PHPUnit_Framework_TestCase {
  51.     /**
  52.      * An Image for testing
  53.      * 
  54.      * @var Image 
  55.      * @since 1.0
  56.      */
  57.     private $img;
  58.         
  59.     /**
  60.      * Called before the test functions will be executed
  61.      * this function is defined in PHPUnit_TestCase and overwritten
  62.      * here
  63.      * 
  64.      * @since 1.0
  65.      */
  66.     protected function setUp({
  67.         global $config;
  68.                 
  69.         $this->img new Image($config->get('sysRoot').'/alpha/images/icons/accept.png'1616'png');
  70.     }
  71.     
  72.     /** 
  73.      * Called after the test functions are executed
  74.      * this function is defined in PHPUnit_TestCase and overwritten
  75.      * here
  76.      * 
  77.      * @since 1.0
  78.      */    
  79.     protected function tearDown({        
  80.         unset($this->img);
  81.     }
  82.     
  83.     /**
  84.      * Testing for an expected exception when a bad source file path is provided
  85.      * 
  86.      * @since 1.0
  87.      */
  88.     public function testConstructorBadSource({
  89.         try {
  90.             $this->img new Image('/does/not/exist.png'1616'png');
  91.             $this->fail('testing for an expected exception when a bad source file path is provided');
  92.         catch (IllegalArguementException $e{
  93.             $this->assertEquals('The source file for the Image widget [/does/not/exist.png] cannot be found!'$e->getMessage()'testing for an expected exception when a bad source file path is provided');
  94.         }
  95.     }
  96.     
  97.     /**
  98.      * Testing for an expected exception when a bad source type is provided
  99.      * 
  100.      * @since 1.0
  101.      */
  102.     public function testConstructorBadSourceType({
  103.         global $config;
  104.         
  105.         try {
  106.             $this->img new Image($config->get('sysRoot').'/alpha/images/icons/accept.png'1616'tif');
  107.             $this->fail('testing for an expected exception when a bad source type is provided');
  108.         catch (IllegalArguementException $e{
  109.             $this->assertEquals('Not a valid enum option!'$e->getMessage()'testing for an expected exception when a bad source type is provided');
  110.         }
  111.     }
  112.     
  113.     /**
  114.      * Testing for an expected exception when a quality value is provided
  115.      * 
  116.      * @since 1.0
  117.      */
  118.     public function testConstructorQuality({
  119.         global $config;
  120.         
  121.         try {
  122.             $this->img new Image($config->get('sysRoot').'/alpha/images/icons/accept.png'1616'png'2.5);
  123.             $this->fail('testing for an expected exception when a quality value is provided');
  124.         catch (IllegalArguementException $e{
  125.             $this->assertEquals('The quality setting of [2.5] is outside of the allowable range of 0.0 to 1.0'$e->getMessage()'testing for an expected exception when a quality value is provided');
  126.         }
  127.     }
  128.     
  129.     /**
  130.      * Testing that the constructor will call setFilename internally to get up a filename  to store the generated image automatically
  131.      * 
  132.      * @since 1.0
  133.      */
  134.     public function testConstructorSetFilename({
  135.         global $config;
  136.         
  137.         $this->assertEquals($config->get('sysRoot').'cache/images/accept_16x16.png'$this->img->getFilename()'testing that the constructor will call setFilename internally to get up a filename  to store the generated image automatically');
  138.     }
  139.     
  140.     /**
  141.      * Testing the convertImageURLToPath method
  142.      * 
  143.      * @since 1.0
  144.      */
  145.     public function testConvertImageURLToPath({
  146.         global $config;
  147.         
  148.         $this->assertEquals('images/testimage.png'Image::convertImageURLToPath($config->get('sysURL').'images/testimage.png')'testing the convertImageURLToPath method');
  149.     }
  150. }
  151.  
  152. ?>

Documentation generated on Thu, 17 Mar 2011 16:44:22 +0000 by phpDocumentor 1.4.3