Open Journal Systems  3.3.0
FunZlibTest.php
1 <?php
2 
4 
5 class BuiltInZlibTest extends PHPUnit_Framework_TestCase
6 {
7  public function testFunZlibDeflateHelloWorld()
8  {
9  $deflate = StreamFilter\fun('zlib.deflate');
10 
11  $data = $deflate('hello') . $deflate(' ') . $deflate('world') . $deflate();
12 
13  $this->assertEquals(gzdeflate('hello world'), $data);
14  }
15 
16  public function testFunZlibDeflateEmpty()
17  {
18  if (PHP_VERSION >= 7) $this->markTestSkipped('Not supported on PHP7 (empty string does not invoke filter)');
19 
20  $deflate = StreamFilter\fun('zlib.deflate');
21 
22  //$data = gzdeflate('');
23  $data = $deflate();
24 
25  $this->assertEquals("\x03\x00", $data);
26  }
27 
28  public function testFunZlibDeflateBig()
29  {
30  $deflate = StreamFilter\fun('zlib.deflate');
31 
32  $n = 1000;
33  $expected = str_repeat('hello', $n);
34 
35  $bytes = '';
36  for ($i = 0; $i < $n; ++$i) {
37  $bytes .= $deflate('hello');
38  }
39  $bytes .= $deflate();
40 
41  $this->assertEquals($expected, gzinflate($bytes));
42  }
43 
44  public function testFunZlibInflateHelloWorld()
45  {
46  $inflate = StreamFilter\fun('zlib.inflate');
47 
48  $data = $inflate(gzdeflate('hello world')) . $inflate();
49 
50  $this->assertEquals('hello world', $data);
51  }
52 
53  public function testFunZlibInflateEmpty()
54  {
55  $inflate = StreamFilter\fun('zlib.inflate');
56 
57  $data = $inflate("\x03\x00") . $inflate();
58 
59  $this->assertEquals('', $data);
60  }
61 
62  public function testFunZlibInflateBig()
63  {
64  if (defined('HHVM_VERSION')) $this->markTestSkipped('Not supported on HHVM (final chunk will not be emitted)');
65 
66  $inflate = StreamFilter\fun('zlib.inflate');
67 
68  $expected = str_repeat('hello', 10);
69  $bytes = gzdeflate($expected);
70 
71  $ret = '';
72  foreach (str_split($bytes, 2) as $chunk) {
73  $ret .= $inflate($chunk);
74  }
75  $ret .= $inflate();
76 
77  $this->assertEquals($expected, $ret);
78  }
79 }
BuiltInZlibTest
Definition: FunZlibTest.php:5
BuiltInZlibTest\testFunZlibInflateBig
testFunZlibInflateBig()
Definition: FunZlibTest.php:62
BuiltInZlibTest\testFunZlibDeflateHelloWorld
testFunZlibDeflateHelloWorld()
Definition: FunZlibTest.php:7
Clue\StreamFilter
Definition: CallbackFilter.php:3
BuiltInZlibTest\testFunZlibInflateHelloWorld
testFunZlibInflateHelloWorld()
Definition: FunZlibTest.php:44
BuiltInZlibTest\testFunZlibDeflateEmpty
testFunZlibDeflateEmpty()
Definition: FunZlibTest.php:16
BuiltInZlibTest\testFunZlibInflateEmpty
testFunZlibInflateEmpty()
Definition: FunZlibTest.php:53
BuiltInZlibTest\testFunZlibDeflateBig
testFunZlibDeflateBig()
Definition: FunZlibTest.php:28