File: TextTest.php

package info (click to toggle)
php-image-text 0.7.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, stretch
  • size: 332 kB
  • ctags: 211
  • sloc: php: 808; xml: 181; makefile: 2
file content (303 lines) | stat: -rw-r--r-- 7,656 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
<?php
/**
 * Tests for Image_Text
 *
 * PHP version 5
 *
 * @category Image
 * @package  Image_Text
 * @author   Michael Cramer <michael@bigmichi1.de>
 * @license  BSD License
 * @link     http://pear.php.net/package/Text_CAPTCHA
 */
require_once 'Image/Text.php';
require_once dirname(__FILE__) . '/imageisthesame.php';
/**
 * Class Image_Text_Test
 *
 * @category Text
 * @package  Text_CAPTCHA
 * @author   Michael Cramer <michael@bigmichi1.de>
 * @license  BSD License
 * @link     http://pear.php.net/package/Text_CAPTCHA
 */
class Image_Text_Test extends PHPUnit_Framework_TestCase
{
    /**
     * directory with images for comparison
     *
     * @var
     */
    private $_dir;

    /**
     * Sets up the fixture, for example, open a network connection.
     * This method is called before a test is executed.
     *
     * @return void
     */
    protected function setUp()
    {
        if (!extension_loaded('gd')) {
            $this->markTestSkipped("Requires the gd extension");
        }
        $this->_dir = dirname(__FILE__) . '/testimages/';
    }

    /**
     * initialize the testee
     *
     * @param string $text Text for Image
     *
     * @return Image_Text testee
     */
    protected function initInstance($text)
    {
        $i = new Image_Text($text);
        $i->set(
            array(
                'font_path' => dirname(__FILE__) . '/data/',
                'font_file' => 'Vera.ttf',
                'font_size' => 12,
                'canvas' => array('width' => 200, 'height' => 100),
                'width' => 200,
                'height' => 200,
                'color' => array('#FFFFFF')
            )
        );
        return $i;
    }

    /**
     * test construction
     *
     * @return void
     */
    public function testConstruct()
    {
        $i = $this->initInstance('test');
        $this->assertSame('Image_Text', get_class($i));
        $i->init();
        $i->render();
        $this->assertTrue(
            imageisthesame(
                $this->_dir . 'test-construct.png',
                $i->getImg()
            )
        );

        $i = $this->initInstance('text');
        $this->assertSame('Image_Text', get_class($i));
        $i->init();
        $i->render();
        $this->assertFalse(
            imageisthesame(
                $this->_dir . 'test-construct.png',
                $i->getImg()
            )
        );
    }

    /**
     * test background color
     *
     * @return void
     */
    public function testBackgroundColor()
    {
        //default background is black
        $i = $this->initInstance('test');
        $this->assertSame('Image_Text', get_class($i));
        $i->init();
        $i->render();
        $this->assertTrue(
            imageisthesame(
                $this->_dir . 'test-construct.png',
                $i->getImg()
            )
        );

        //red background
        $i = $this->initInstance('text');
        $this->assertSame('Image_Text', get_class($i));
        $i->set(array('background_color' => '#FF0000'));
        $i->init();
        $i->render();
        $this->assertTrue(
            imageisthesame(
                $this->_dir . 'test-background-red.png',
                $i->getImg()
            )
        );

        //transparent background
        $i = $this->initInstance('text');
        $this->assertSame('Image_Text', get_class($i));
        $i->set(array('background_color' => null));
        $i->init();
        $i->render();
        $this->assertTrue(
            imageisthesame(
                $this->_dir . 'test-background-transparent.png',
                $i->getImg()
            )
        );
    }

    /**
     * @todo Implement testSet().
     */
    public function testSet()
    {
        // Remove the following line when you implement this test.
        $this->markTestIncomplete(
            "This test has not been implemented yet."
        );
    }

    /**
     * @todo Implement testSetColors().
     */
    public function testSetColors()
    {
        // Remove the following line when you implement this test.
        $this->markTestIncomplete(
            "This test has not been implemented yet."
        );
    }

    /**
     * @todo Implement testSetColor().
     */
    public function testSetColor()
    {
        // Remove the following line when you implement this test.
        $this->markTestIncomplete(
            "This test has not been implemented yet."
        );
    }

    /**
     * @todo Implement testInit().
     */
    public function testInit()
    {
        // Remove the following line when you implement this test.
        $this->markTestIncomplete(
            "This test has not been implemented yet."
        );
    }

    /**
     * @todo Implement testAutoMeasurize().
     */
    public function testAutoMeasurize()
    {
        // Remove the following line when you implement this test.
        $this->markTestIncomplete(
            "This test has not been implemented yet."
        );
    }

    /**
     * @todo Implement testMeasurize().
     */
    public function testMeasurize()
    {
        // Remove the following line when you implement this test.
        $this->markTestIncomplete(
            "This test has not been implemented yet."
        );
    }

    /**
     * @todo Implement testRender().
     */
    public function testRender()
    {
        // Remove the following line when you implement this test.
        $this->markTestIncomplete(
            "This test has not been implemented yet."
        );
    }

    /**
     * @todo Implement testGetImg().
     */
    public function testGetImg()
    {
        // Remove the following line when you implement this test.
        $this->markTestIncomplete(
            "This test has not been implemented yet."
        );
    }

    /**
     * @todo Implement testDisplay().
     */
    public function testDisplay()
    {
        // Remove the following line when you implement this test.
        $this->markTestIncomplete(
            "This test has not been implemented yet."
        );
    }

    /**
     * @todo Implement testSave().
     */
    public function testSave()
    {
        // Remove the following line when you implement this test.
        $this->markTestIncomplete(
            "This test has not been implemented yet."
        );
    }

    /**
     * @todo Implement test_getOffset().
     */
    public function test_getOffset()
    {
        // Remove the following line when you implement this test.
        $this->markTestIncomplete(
            "This test has not been implemented yet."
        );
    }

    /**
     * test convert routine
     *
     * @return void
     */
    public function test_convertString2RGB()
    {
        $this->assertEquals(
            array('r' => 255, 'g' => 255, 'b' => 255, 'a' => 0),
            Image_Text::convertString2RGB('#FFFFFF')
        );
        $this->assertEquals(
            array('r' => 255, 'g' => 255, 'b' => 255, 'a' => 0),
            Image_Text::convertString2RGB('#00FFFFFF')
        );
        $this->assertEquals(
            array('r' => 0, 'g' => 0, 'b' => 0, 'a' => 0),
            Image_Text::convertString2RGB('#000000')
        );
        $this->assertEquals(
            array('r' => 0, 'g' => 0, 'b' => 0, 'a' => 255),
            Image_Text::convertString2RGB('#FF000000')
        );
    }

    /**
     * @todo Implement test_processText().
     */
    public function test_processText()
    {
        // Remove the following line when you implement this test.
        $this->markTestIncomplete(
            "This test has not been implemented yet."
        );
    }
}