2
0
Просмотр исходного кода

ZF-1491
- Added a getRawContent() method to Zend_Mime_Part to get unencoded content


git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@23713 44c647ce-9c0f-0410-b52a-842ac1e357ba

ralph 15 лет назад
Родитель
Сommit
47a9664e41
2 измененных файлов с 29 добавлено и 7 удалено
  1. 13 0
      library/Zend/Mime/Part.php
  2. 16 7
      tests/Zend/Mime/PartTest.php

+ 13 - 0
library/Zend/Mime/Part.php

@@ -146,6 +146,19 @@ class Zend_Mime_Part {
             return Zend_Mime::encode($this->_content, $this->encoding, $EOL);
         }
     }
+    
+    /**
+     * Get the RAW unencoded content from this part
+     * @return string
+     */
+    public function getRawContent()
+    {
+        if ($this->_isStream) {
+            return stream_get_contents($this->_content);
+        } else {
+            return $this->_content;
+        }
+    }
 
     /**
      * Create and return the array of headers for this MIME part

+ 16 - 7
tests/Zend/Mime/PartTest.php

@@ -40,14 +40,14 @@ class Zend_Mime_PartTest extends PHPUnit_Framework_TestCase
      *
      * @var Zend_Mime_Part
      */
-    protected $_part = null;
-    protected $_testText;
+    protected $part = null;
+    protected $testText;
 
     protected function setUp()
     {
-        $this->_testText = 'safdsafsa�lg ��gd�� sd�jg�sdjg�ld�gksd�gj�sdfg�dsj�gjsd�gj�dfsjg�dsfj�djs�g kjhdkj '
+        $this->testText = 'safdsafsa�lg ��gd�� sd�jg�sdjg�ld�gksd�gj�sdfg�dsj�gjsd�gj�dfsjg�dsfj�djs�g kjhdkj '
                        . 'fgaskjfdh gksjhgjkdh gjhfsdghdhgksdjhg';
-        $this->part = new Zend_Mime_Part($this->_testText);
+        $this->part = new Zend_Mime_Part($this->testText);
         $this->part->encoding = Zend_Mime::ENCODING_BASE64;
         $this->part->type = "text/plain";
         $this->part->filename = 'test.txt';
@@ -76,15 +76,15 @@ class Zend_Mime_PartTest extends PHPUnit_Framework_TestCase
     {
         // Test with base64 encoding
         $content = $this->part->getContent();
-        $this->assertEquals($this->_testText, base64_decode($content));
+        $this->assertEquals($this->testText, base64_decode($content));
         // Test with quotedPrintable Encoding:
         $this->part->encoding = Zend_Mime::ENCODING_QUOTEDPRINTABLE;
         $content = $this->part->getContent();
-        $this->assertEquals($this->_testText, quoted_printable_decode($content));
+        $this->assertEquals($this->testText, quoted_printable_decode($content));
         // Test with 8Bit encoding
         $this->part->encoding = Zend_Mime::ENCODING_8BIT;
         $content = $this->part->getContent();
-        $this->assertEquals($this->_testText, $content);
+        $this->assertEquals($this->testText, $content);
     }
 
     public function testStreamEncoding()
@@ -114,4 +114,13 @@ class Zend_Mime_PartTest extends PHPUnit_Framework_TestCase
         fclose($fp);
         $this->assertEquals(quoted_printable_decode($encoded),$original);
     }
+    
+    /**
+     * @group ZF-1491
+     */
+    public function testGetRawContentFromPart()
+    {
+        $this->assertEquals($this->testText, $this->part->getRawContent());
+    }
+    
 }