Rfc2231EncoderAcceptanceTest.php 1.7KB

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