Base64EncoderAcceptanceTest.php 1.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. require_once 'Swift/Encoder/Base64Encoder.php';
  3. class Swift_Encoder_Base64EncoderAcceptanceTest extends UnitTestCase
  4. {
  5. private $_samplesDir;
  6. private $_encoder;
  7. public function setUp()
  8. {
  9. $this->_samplesDir = realpath(dirname(__FILE__) . '/../../../_samples/charsets');
  10. $this->_encoder = new Swift_Encoder_Base64Encoder();
  11. }
  12. public function testEncodingAndDecodingSamples()
  13. {
  14. $sampleFp = opendir($this->_samplesDir);
  15. while (false !== $encodingDir = readdir($sampleFp))
  16. {
  17. if (substr($encodingDir, 0, 1) == '.')
  18. {
  19. continue;
  20. }
  21. $sampleDir = $this->_samplesDir . '/' . $encodingDir;
  22. if (is_dir($sampleDir))
  23. {
  24. $fileFp = opendir($sampleDir);
  25. while (false !== $sampleFile = readdir($fileFp))
  26. {
  27. if (substr($sampleFile, 0, 1) == '.')
  28. {
  29. continue;
  30. }
  31. $text = file_get_contents($sampleDir . '/' . $sampleFile);
  32. $encodedText = $this->_encoder->encodeString($text);
  33. $this->assertEqual(
  34. base64_decode($encodedText), $text,
  35. '%s: Encoded string should decode back to original string for sample ' .
  36. $sampleDir . '/' . $sampleFile
  37. );
  38. }
  39. closedir($fileFp);
  40. }
  41. }
  42. closedir($sampleFp);
  43. }
  44. }