PageRenderTime 26ms CodeModel.GetById 0ms RepoModel.GetById 1ms app.codeStats 0ms

/tests/acceptance/Swift/Encoder/Rfc2231EncoderAcceptanceTest.php

http://github.com/swiftmailer/swiftmailer
PHP | 50 lines | 42 code | 8 blank | 0 comment | 7 complexity | 3a007585aa77f1b6d9b31fb0fd3f870e MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.1
  1. <?php
  2. class Swift_Encoder_Rfc2231EncoderAcceptanceTest extends \PHPUnit\Framework\TestCase
  3. {
  4. private $samplesDir;
  5. private $factory;
  6. protected function setUp(): void
  7. {
  8. $this->samplesDir = realpath(__DIR__.'/../../../_samples/charsets');
  9. $this->factory = new Swift_CharacterReaderFactory_SimpleCharacterReaderFactory();
  10. }
  11. public function testEncodingAndDecodingSamples()
  12. {
  13. $sampleFp = opendir($this->samplesDir);
  14. while (false !== $encodingDir = readdir($sampleFp)) {
  15. if ('.' == substr($encodingDir, 0, 1)) {
  16. continue;
  17. }
  18. $encoding = $encodingDir;
  19. $charStream = new Swift_CharacterStream_ArrayCharacterStream(
  20. $this->factory, $encoding);
  21. $encoder = new Swift_Encoder_Rfc2231Encoder($charStream);
  22. $sampleDir = $this->samplesDir.'/'.$encodingDir;
  23. if (is_dir($sampleDir)) {
  24. $fileFp = opendir($sampleDir);
  25. while (false !== $sampleFile = readdir($fileFp)) {
  26. if ('.' == substr($sampleFile, 0, 1)) {
  27. continue;
  28. }
  29. $text = file_get_contents($sampleDir.'/'.$sampleFile);
  30. $encodedText = $encoder->encodeString($text);
  31. $this->assertEquals(
  32. urldecode(implode('', explode("\r\n", $encodedText))), $text,
  33. '%s: Encoded string should decode back to original string for sample '.
  34. $sampleDir.'/'.$sampleFile
  35. );
  36. }
  37. closedir($fileFp);
  38. }
  39. }
  40. closedir($sampleFp);
  41. }
  42. }