QpEncoderAcceptanceTest.php 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. require_once 'Swift/Tests/SwiftUnitTestCase.php';
  3. require_once 'Swift/Encoder/QpEncoder.php';
  4. require_once 'Swift/CharacterStream/ArrayCharacterStream.php';
  5. require_once 'Swift/CharacterReaderFactory/SimpleCharacterReaderFactory.php';
  6. class Swift_Encoder_QpEncoderAcceptanceTest
  7. extends Swift_Tests_SwiftUnitTestCase
  8. {
  9. private $_samplesDir;
  10. private $_factory;
  11. public function setUp()
  12. {
  13. $this->_samplesDir = realpath(dirname(__FILE__) . '/../../../_samples/charsets');
  14. $this->_factory = new Swift_CharacterReaderFactory_SimpleCharacterReaderFactory();
  15. }
  16. public function testEncodingAndDecodingSamples()
  17. {
  18. $sampleFp = opendir($this->_samplesDir);
  19. while (false !== $encodingDir = readdir($sampleFp))
  20. {
  21. if (substr($encodingDir, 0, 1) == '.')
  22. {
  23. continue;
  24. }
  25. $encoding = $encodingDir;
  26. $charStream = new Swift_CharacterStream_ArrayCharacterStream(
  27. $this->_factory, $encoding);
  28. $encoder = new Swift_Encoder_QpEncoder($charStream);
  29. $sampleDir = $this->_samplesDir . '/' . $encodingDir;
  30. if (is_dir($sampleDir))
  31. {
  32. $fileFp = opendir($sampleDir);
  33. while (false !== $sampleFile = readdir($fileFp))
  34. {
  35. if (substr($sampleFile, 0, 1) == '.')
  36. {
  37. continue;
  38. }
  39. $text = file_get_contents($sampleDir . '/' . $sampleFile);
  40. $encodedText = $encoder->encodeString($text);
  41. $this->assertEqual(
  42. quoted_printable_decode($encodedText), $text,
  43. '%s: Encoded string should decode back to original string for sample ' .
  44. $sampleDir . '/' . $sampleFile
  45. );
  46. }
  47. closedir($fileFp);
  48. }
  49. }
  50. closedir($sampleFp);
  51. }
  52. }