~clinton-collins/familyproject/trunk

« back to all changes in this revision

Viewing changes to ZendFramework/tests/Zend/Measure/BinaryTest.php

  • Committer: Clinton Collins
  • Date: 2009-06-26 19:54:58 UTC
  • Revision ID: clinton.collins@gmail.com-20090626195458-5ebba0qcvo15xlpy
Initial Import

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
 
 
3
/**
 
4
 * Zend Framework
 
5
 *
 
6
 * LICENSE
 
7
 *
 
8
 * This source file is subject to the new BSD license that is bundled
 
9
 * with this package in the file LICENSE.txt.
 
10
 * It is also available through the world-wide-web at this URL:
 
11
 * http://framework.zend.com/license/new-bsd
 
12
 * If you did not receive a copy of the license and are unable to
 
13
 * obtain it through the world-wide-web, please send an email
 
14
 * to license@zend.com so we can send you a copy immediately.
 
15
 *
 
16
 * @category   Zend
 
17
 * @package    Zend_Measure
 
18
 * @subpackage UnitTests
 
19
 * @copyright  Copyright (c) 2006 Zend Technologies USA Inc. (http://www.zend.com)
 
20
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 
21
 * @version    $Id: BinaryTest.php 6799 2007-11-09 22:44:42Z thomas $
 
22
 */
 
23
 
 
24
 
 
25
/**
 
26
 * Zend_Measure_Binary
 
27
 */
 
28
require_once 'Zend/Measure/Binary.php';
 
29
 
 
30
/**
 
31
 * PHPUnit test case
 
32
 */
 
33
require_once 'PHPUnit/Framework/TestCase.php';
 
34
 
 
35
 
 
36
/**
 
37
 * @package    Zend_Measure
 
38
 * @subpackage UnitTests
 
39
 */
 
40
class Zend_Measure_BinaryTest extends PHPUnit_Framework_TestCase
 
41
{
 
42
    /**
 
43
     * test for Binary initialisation
 
44
     * expected instance
 
45
     */
 
46
    public function testBinaryInit()
 
47
    {
 
48
        $value = new Zend_Measure_Binary('100',Zend_Measure_Binary::STANDARD,'de');
 
49
        $this->assertTrue($value instanceof Zend_Measure_Binary,'Zend_Measure_Binary Object not returned');
 
50
    }
 
51
 
 
52
 
 
53
    /**
 
54
     * test for exception unknown type
 
55
     * expected exception
 
56
     */
 
57
    public function testBinaryUnknownType()
 
58
    {
 
59
        try {
 
60
            $value = new Zend_Measure_Binary('100','Binary::UNKNOWN','de');
 
61
            $this->fail('Exception expected because of unknown type');
 
62
        } catch (Zend_Measure_Exception $e) {
 
63
            // success
 
64
        }
 
65
    }
 
66
 
 
67
 
 
68
    /**
 
69
     * test for exception unknown value
 
70
     * expected exception
 
71
     */
 
72
    public function testBinaryUnknownValue()
 
73
    {
 
74
        try {
 
75
            $value = new Zend_Measure_Binary('novalue',Zend_Measure_Binary::STANDARD,'de');
 
76
            $this->fail('Exception expected because of empty value');
 
77
        } catch (Zend_Measure_Exception $e) {
 
78
            // success
 
79
        }
 
80
    }
 
81
 
 
82
 
 
83
    /**
 
84
     * test for exception unknown locale
 
85
     * expected root value
 
86
     */
 
87
    public function testBinaryUnknownLocale()
 
88
    {
 
89
        try {
 
90
            $value = new Zend_Measure_Binary('100',Zend_Measure_Binary::STANDARD,'nolocale');
 
91
            $this->fail('Exception expected because of unknown locale');
 
92
        } catch (Zend_Measure_Exception $e) {
 
93
            // success
 
94
        }
 
95
    }
 
96
 
 
97
 
 
98
    /**
 
99
     * test for exception no locale
 
100
     * expected root value
 
101
     */
 
102
    public function testBinaryNoLocale()
 
103
    {
 
104
        $value = new Zend_Measure_Binary('100',Zend_Measure_Binary::STANDARD);
 
105
        $this->assertTrue(is_object($value),'Object expected because of standard locale');
 
106
    }
 
107
 
 
108
 
 
109
    /**
 
110
     * test for positive value
 
111
     * expected integer
 
112
     */
 
113
    public function testBinaryValuePositive()
 
114
    {
 
115
        $value = new Zend_Measure_Binary('100',Zend_Measure_Binary::STANDARD,'de');
 
116
        $this->assertEquals(100, $value->getValue(), 'Zend_Measure_Binary value expected to be a positive integer');
 
117
    }
 
118
 
 
119
 
 
120
    /**
 
121
     * test for negative value
 
122
     * expected integer
 
123
     */
 
124
    public function testBinaryValueNegative()
 
125
    {
 
126
        $value = new Zend_Measure_Binary('-100',Zend_Measure_Binary::STANDARD,'de');
 
127
        $this->assertEquals(-100, $value->getValue(), 'Zend_Measure_Binary value expected to be a negative integer');
 
128
    }
 
129
 
 
130
 
 
131
    /**
 
132
     * test for decimal value
 
133
     * expected float
 
134
     */
 
135
    public function testBinaryValueDecimal()
 
136
    {
 
137
        $value = new Zend_Measure_Binary('-100,200',Zend_Measure_Binary::STANDARD,'de');
 
138
        $this->assertEquals(-100.200, $value->getValue(), 'Zend_Measure_Binary value expected to be a decimal value');
 
139
    }
 
140
 
 
141
 
 
142
    /**
 
143
     * test for decimal seperated value
 
144
     * expected float
 
145
     */
 
146
    public function testBinaryValueDecimalSeperated()
 
147
    {
 
148
        $value = new Zend_Measure_Binary('-100.100,200',Zend_Measure_Binary::STANDARD,'de');
 
149
        $this->assertEquals(-100100.200, $value->getValue(),'Zend_Measure_Binary Object not returned');
 
150
    }
 
151
 
 
152
 
 
153
    /**
 
154
     * test for string with integrated value
 
155
     * expected float
 
156
     */
 
157
    public function testBinaryValueString()
 
158
    {
 
159
        $value = new Zend_Measure_Binary('string -100.100,200',Zend_Measure_Binary::STANDARD,'de');
 
160
        $this->assertEquals(-100100.200, $value->getValue(),'Zend_Measure_Binary Object not returned');
 
161
    }
 
162
 
 
163
 
 
164
    /**
 
165
     * test for equality
 
166
     * expected true
 
167
     */
 
168
    public function testBinaryEquality()
 
169
    {
 
170
        $value = new Zend_Measure_Binary('string -100.100,200',Zend_Measure_Binary::STANDARD,'de');
 
171
        $newvalue = new Zend_Measure_Binary('otherstring -100.100,200',Zend_Measure_Binary::STANDARD,'de');
 
172
        $this->assertTrue($value->equals($newvalue),'Zend_Measure_Binary Object should be equal');
 
173
    }
 
174
 
 
175
 
 
176
    /**
 
177
     * test for no equality
 
178
     * expected false
 
179
     */
 
180
    public function testBinaryNoEquality()
 
181
    {
 
182
        $value = new Zend_Measure_Binary('string -100.100,200',Zend_Measure_Binary::STANDARD,'de');
 
183
        $newvalue = new Zend_Measure_Binary('otherstring -100,200',Zend_Measure_Binary::STANDARD,'de');
 
184
        $this->assertFalse($value->equals($newvalue),'Zend_Measure_Binary Object should be not equal');
 
185
    }
 
186
 
 
187
 
 
188
    /**
 
189
     * test for set positive value
 
190
     * expected integer
 
191
     */
 
192
    public function testBinarySetPositive()
 
193
    {
 
194
        $value = new Zend_Measure_Binary('100',Zend_Measure_Binary::STANDARD,'de');
 
195
        $value->setValue('200',Zend_Measure_Binary::STANDARD,'de');
 
196
        $this->assertEquals(200, $value->getValue(), 'Zend_Measure_Binary value expected to be a positive integer');
 
197
    }
 
198
 
 
199
 
 
200
    /**
 
201
     * test for set negative value
 
202
     * expected integer
 
203
     */
 
204
    public function testBinarySetNegative()
 
205
    {
 
206
        $value = new Zend_Measure_Binary('-100',Zend_Measure_Binary::STANDARD,'de');
 
207
        $value->setValue('-200',Zend_Measure_Binary::STANDARD,'de');
 
208
        $this->assertEquals(-200, $value->getValue(), 'Zend_Measure_Binary value expected to be a negative integer');
 
209
    }
 
210
 
 
211
 
 
212
    /**
 
213
     * test for set decimal value
 
214
     * expected float
 
215
     */
 
216
    public function testBinarySetDecimal()
 
217
    {
 
218
        $value = new Zend_Measure_Binary('-100,200',Zend_Measure_Binary::STANDARD,'de');
 
219
        $value->setValue('-200,200',Zend_Measure_Binary::STANDARD,'de');
 
220
        $this->assertEquals(-200.200, $value->getValue(), 'Zend_Measure_Binary value expected to be a decimal value');
 
221
    }
 
222
 
 
223
 
 
224
    /**
 
225
     * test for set decimal seperated value
 
226
     * expected float
 
227
     */
 
228
    public function testBinarySetDecimalSeperated()
 
229
    {
 
230
        $value = new Zend_Measure_Binary('-100.100,200',Zend_Measure_Binary::STANDARD,'de');
 
231
        $value->setValue('-200.200,200',Zend_Measure_Binary::STANDARD,'de');
 
232
        $this->assertEquals(-200200.200, $value->getValue(),'Zend_Measure_Binary Object not returned');
 
233
    }
 
234
 
 
235
 
 
236
    /**
 
237
     * test for set string with integrated value
 
238
     * expected float
 
239
     */
 
240
    public function testBinarySetString()
 
241
    {
 
242
        $value = new Zend_Measure_Binary('string -100.100,200',Zend_Measure_Binary::STANDARD,'de');
 
243
        $value->setValue('otherstring -200.200,200',Zend_Measure_Binary::STANDARD,'de');
 
244
        $this->assertEquals(-200200.200, $value->getValue(),'Zend_Measure_Binary Object not returned');
 
245
    }
 
246
 
 
247
 
 
248
    /**
 
249
     * test for exception unknown type
 
250
     * expected exception
 
251
     */
 
252
    public function testBinarySetUnknownType()
 
253
    {
 
254
        try {
 
255
            $value = new Zend_Measure_Binary('100',Zend_Measure_Binary::STANDARD,'de');
 
256
            $value->setValue('otherstring -200.200,200','Binary::UNKNOWN','de');
 
257
            $this->fail('Exception expected because of unknown type');
 
258
        } catch (Zend_Measure_Exception $e) {
 
259
            // success
 
260
        }
 
261
    }
 
262
 
 
263
 
 
264
    /**
 
265
     * test for exception unknown value
 
266
     * expected exception
 
267
     */
 
268
    public function testBinarySetUnknownValue()
 
269
    {
 
270
        try {
 
271
            $value = new Zend_Measure_Binary('100',Zend_Measure_Binary::STANDARD,'de');
 
272
            $value->setValue('novalue',Zend_Measure_Binary::STANDARD,'de');
 
273
            $this->fail('Exception expected because of empty value');
 
274
        } catch (Zend_Measure_Exception $e) {
 
275
            // success
 
276
        }
 
277
    }
 
278
 
 
279
 
 
280
    /**
 
281
     * test for exception unknown locale
 
282
     * expected exception
 
283
     */
 
284
    public function testBinarySetUnknownLocale()
 
285
    {
 
286
        try {
 
287
            $value = new Zend_Measure_Binary('100',Zend_Measure_Binary::STANDARD,'de');
 
288
            $value->setValue('200',Zend_Measure_Binary::STANDARD,'nolocale');
 
289
            $this->fail('Exception expected because of unknown locale');
 
290
        } catch (Zend_Measure_Exception $e) {
 
291
            // success
 
292
        }
 
293
    }
 
294
 
 
295
 
 
296
    /**
 
297
     * test for exception unknown locale
 
298
     * expected exception
 
299
     */
 
300
    public function testBinarySetWithNoLocale()
 
301
    {
 
302
        $value = new Zend_Measure_Binary('100', Zend_Measure_Binary::STANDARD, 'de');
 
303
        $value->setValue('200', Zend_Measure_Binary::STANDARD);
 
304
        $this->assertEquals(200, $value->getValue(), 'Zend_Measure_Binary value expected to be a positive integer');
 
305
    }
 
306
 
 
307
 
 
308
    /**
 
309
     * test setting type
 
310
     * expected new type
 
311
     */
 
312
    public function testBinarySetType()
 
313
    {
 
314
        $value = new Zend_Measure_Binary('-100',Zend_Measure_Binary::STANDARD,'de');
 
315
        $value->setType(Zend_Measure_Binary::GIGABYTE);
 
316
        $this->assertEquals(Zend_Measure_Binary::GIGABYTE, $value->getType(), 'Zend_Measure_Binary type expected');
 
317
    }
 
318
 
 
319
 
 
320
    /**
 
321
     * test setting computed type
 
322
     * expected new type
 
323
     */
 
324
    public function testBinarySetComputedType1()
 
325
    {
 
326
        $value = new Zend_Measure_Binary('-100',Zend_Measure_Binary::MEGABYTE,'de');
 
327
        $value->setType(Zend_Measure_Binary::TERABYTE);
 
328
        $this->assertEquals(Zend_Measure_Binary::TERABYTE, $value->getType(), 'Zend_Measure_Binary type expected');
 
329
    }
 
330
 
 
331
 
 
332
    /**
 
333
     * test setting computed type
 
334
     * expected new type
 
335
     */
 
336
    public function testBinarySetComputedType2()
 
337
    {
 
338
        $value = new Zend_Measure_Binary('-100',Zend_Measure_Binary::TERABYTE,'de');
 
339
        $value->setType(Zend_Measure_Binary::KILOBYTE);
 
340
        $this->assertEquals(Zend_Measure_Binary::KILOBYTE, $value->getType(), 'Zend_Measure_Binary type expected');
 
341
    }
 
342
 
 
343
 
 
344
    /**
 
345
     * test setting unknown type
 
346
     * expected new type
 
347
     */
 
348
    public function testBinarySetTypeFailed()
 
349
    {
 
350
        try {
 
351
            $value = new Zend_Measure_Binary('-100',Zend_Measure_Binary::STANDARD,'de');
 
352
            $value->setType('Binary::UNKNOWN');
 
353
            $this->fail('Exception expected because of unknown type');
 
354
        } catch (Zend_Measure_Exception $e) {
 
355
            // success
 
356
        }
 
357
    }
 
358
 
 
359
 
 
360
    /**
 
361
     * test toString
 
362
     * expected string
 
363
     */
 
364
    public function testBinaryToString()
 
365
    {
 
366
        $value = new Zend_Measure_Binary('-100',Zend_Measure_Binary::STANDARD,'de');
 
367
        $this->assertEquals('-100 B', $value->toString(), 'Value -100 B expected');
 
368
    }
 
369
 
 
370
 
 
371
    /**
 
372
     * test __toString
 
373
     * expected string
 
374
     */
 
375
    public function testBinary_ToString()
 
376
    {
 
377
        $value = new Zend_Measure_Binary('-100',Zend_Measure_Binary::STANDARD,'de');
 
378
        $this->assertEquals('-100 B', $value->__toString(), 'Value -100 B expected');
 
379
    }
 
380
 
 
381
 
 
382
    /**
 
383
     * test getConversionList
 
384
     * expected array
 
385
     */
 
386
    public function testBinaryConversionList()
 
387
    {
 
388
        $value = new Zend_Measure_Binary('-100',Zend_Measure_Binary::STANDARD,'de');
 
389
        $unit  = $value->getConversionList();
 
390
        $this->assertTrue(is_array($unit), 'Array expected');
 
391
    }
 
392
}