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
|
<?php
namespace Base32;
use Base32\Base32;
/**
* Base32 test case.
*/
class Base32Test extends \PHPUnit_Framework_TestCase
{
/**
* Tests Base32->decode()
*
* Testing test vectors according to RFC 4648
* http://www.ietf.org/rfc/rfc4648.txt
*/
public function testDecode()
{
// RFC test vectors say that empty string returns empty string
$this->assertEquals('', Base32::decode(''));
// these strings are taken from the RFC
$this->assertEquals('f', Base32::decode('MY======'));
$this->assertEquals('fo', Base32::decode('MZXQ===='));
$this->assertEquals('foo', Base32::decode('MZXW6==='));
$this->assertEquals('foob', Base32::decode('MZXW6YQ='));
$this->assertEquals('fooba', Base32::decode('MZXW6YTB'));
$this->assertEquals('foobar', Base32::decode('MZXW6YTBOI======'));
// Decoding a string made up entirely of invalid characters
$this->assertEquals('', Base32::decode('8908908908908908'));
}
/**
* Encoder tests, reverse of the decodes
*/
public function testEncode()
{
// RFC test vectors say that empty string returns empty string
$this->assertEquals('', Base32::encode(''));
// these strings are taken from the RFC
$this->assertEquals('MY======', Base32::encode('f'));
$this->assertEquals('MZXQ====', Base32::encode('fo'));
$this->assertEquals('MZXW6===', Base32::encode('foo'));
$this->assertEquals('MZXW6YQ=', Base32::encode('foob'));
$this->assertEquals('MZXW6YTB', Base32::encode('fooba'));
$this->assertEquals('MZXW6YTBOI======', Base32::encode('foobar'));
}
}
|