Author: Chris Corbyn
Inheritance: implements Swift_Encoder
 public function testEncodingAndDecodingSamples()
 {
     $sampleFp = opendir($this->samplesDir);
     while (false !== ($encodingDir = readdir($sampleFp))) {
         if (substr($encodingDir, 0, 1) == '.') {
             continue;
         }
         $encoding = $encodingDir;
         $charStream = new Swift_CharacterStream_ArrayCharacterStream($this->factory, $encoding);
         $encoder = new Swift_Encoder_Rfc2231Encoder($charStream);
         $sampleDir = $this->samplesDir . '/' . $encodingDir;
         if (is_dir($sampleDir)) {
             $fileFp = opendir($sampleDir);
             while (false !== ($sampleFile = readdir($fileFp))) {
                 if (substr($sampleFile, 0, 1) == '.') {
                     continue;
                 }
                 $text = file_get_contents($sampleDir . '/' . $sampleFile);
                 $encodedText = $encoder->encodeString($text);
                 $this->assertEquals(urldecode(implode('', explode("\r\n", $encodedText))), $text, '%s: Encoded string should decode back to original string for sample ' . $sampleDir . '/' . $sampleFile);
             }
             closedir($fileFp);
         }
     }
     closedir($sampleFp);
 }
 public function testFirstLineCanHaveShorterLength()
 {
     $charStream = $this->_mock('Swift_CharacterStream');
     $seq = $this->_sequence('byte-sequence');
     $string = '';
     for ($x = 0; $x < 200; ++$x) {
         $char = 'a';
         $string .= $char;
         $this->_checking(Expectations::create()->one($charStream)->read(optional())->inSequence($seq)->returns($char));
     }
     $this->_checking(Expectations::create()->atLeast(1)->of($charStream)->read(optional())->inSequence($seq)->returns(false)->one($charStream)->importString($string)->ignoring($charStream)->flushContents());
     $encoder = new Swift_Encoder_Rfc2231Encoder($charStream);
     $encoded = $encoder->encodeString($string, 25, 75);
     $this->assertEqual(str_repeat('a', 50) . "\r\n" . str_repeat('a', 75) . "\r\n" . str_repeat('a', 75), $encoded, '%s: First line should be 25 bytes shorter than the others.');
 }
Esempio n. 3
0
 public function testFirstLineCanHaveShorterLength()
 {
     $charStream = $this->getMockery('Swift_CharacterStream');
     $string = '';
     for ($x = 0; $x < 200; ++$x) {
         $char = 'a';
         $string .= $char;
         $charStream->shouldReceive('read')->once()->andReturn($char);
     }
     $charStream->shouldReceive('flushContents')->once();
     $charStream->shouldReceive('importString')->once()->with($string);
     $charStream->shouldReceive('read')->atLeast()->times(1)->andReturn(false);
     $encoder = new Swift_Encoder_Rfc2231Encoder($charStream);
     $encoded = $encoder->encodeString($string, 25, 75);
     $this->assertEquals(str_repeat('a', 50) . "\r\n" . str_repeat('a', 75) . "\r\n" . str_repeat('a', 75), $encoded, '%s: First line should be 25 bytes shorter than the others.');
 }