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