FunTest.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. use Clue\StreamFilter as Filter;
  3. class FunTest extends PHPUnit_Framework_TestCase
  4. {
  5. public function testFunInRot13()
  6. {
  7. $rot = Filter\fun('string.rot13');
  8. $this->assertEquals('grfg', $rot('test'));
  9. $this->assertEquals('test', $rot($rot('test')));
  10. $this->assertEquals(null, $rot());
  11. }
  12. public function testFunInQuotedPrintable()
  13. {
  14. $encode = Filter\fun('convert.quoted-printable-encode');
  15. $decode = Filter\fun('convert.quoted-printable-decode');
  16. $this->assertEquals('t=C3=A4st', $encode('täst'));
  17. $this->assertEquals('täst', $decode($encode('täst')));
  18. $this->assertEquals(null, $encode());
  19. }
  20. /**
  21. * @expectedException RuntimeException
  22. */
  23. public function testFunWriteAfterCloseRot13()
  24. {
  25. $rot = Filter\fun('string.rot13');
  26. $this->assertEquals(null, $rot());
  27. $rot('test');
  28. }
  29. /**
  30. * @expectedException RuntimeException
  31. */
  32. public function testFunInvalid()
  33. {
  34. Filter\fun('unknown');
  35. }
  36. public function testFunInBase64()
  37. {
  38. $encode = Filter\fun('convert.base64-encode');
  39. $decode = Filter\fun('convert.base64-decode');
  40. $string = 'test';
  41. $this->assertEquals(base64_encode($string), $encode($string) . $encode());
  42. $this->assertEquals($string, $decode(base64_encode($string)));
  43. $encode = Filter\fun('convert.base64-encode');
  44. $decode = Filter\fun('convert.base64-decode');
  45. $this->assertEquals($string, $decode($encode($string) . $encode()));
  46. $encode = Filter\fun('convert.base64-encode');
  47. $this->assertEquals(null, $encode());
  48. }
  49. }