cacert-testmgr/external/ZendFramework-1.9.5/tests/Zend/Mime/PartTest.php
Markus Warg 8398c9048d initially import ZendFramework-1.9.5 into repository
code was modified slightly, so the code differs from the original downloadable 1.9.5 version
2010-03-31 10:12:32 +02:00

122 lines
4.1 KiB
PHP
Raw Blame History

<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Mime
* @subpackage UnitTests
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: PartTest.php 17363 2009-08-03 07:40:18Z bkarwin $
*/
/**
* Zend_Mime_Part
*/
require_once 'Zend/Mime/Part.php';
/**
* PHPUnit test case
*/
require_once 'PHPUnit/Framework/TestCase.php';
/**
* @category Zend
* @package Zend_Mime
* @subpackage UnitTests
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @group Zend_Mime
*/
class Zend_Mime_PartTest extends PHPUnit_Framework_TestCase
{
/**
* MIME part test object
*
* @var Zend_Mime_Part
*/
protected $_part = null;
protected $_testText;
protected function setUp()
{
$this->_testText = 'safdsafsa<73>lg <20><>gd<67><64> sd<73>jg<6A>sdjg<6A>ld<6C>gksd<73>gj<67>sdfg<66>dsj<73>gjsd<73>gj<67>dfsjg<6A>dsfj<66>djs<6A>g kjhdkj '
. 'fgaskjfdh gksjhgjkdh gjhfsdghdhgksdjhg';
$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';
$this->part->disposition = 'attachment';
$this->part->charset = 'iso8859-1';
$this->part->id = '4711';
}
public function testHeaders()
{
$expectedHeaders = array('Content-Type: text/plain',
'Content-Transfer-Encoding: ' . Zend_Mime::ENCODING_BASE64,
'Content-Disposition: attachment',
'filename="test.txt"',
'charset=iso8859-1',
'Content-ID: <4711>');
$actual = $this->part->getHeaders();
foreach ($expectedHeaders as $expected) {
$this->assertContains($expected, $actual);
}
}
public function testContentEncoding()
{
// Test with base64 encoding
$content = $this->part->getContent();
$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));
// Test with 8Bit encoding
$this->part->encoding = Zend_Mime::ENCODING_8BIT;
$content = $this->part->getContent();
$this->assertEquals($this->_testText, $content);
}
public function testStreamEncoding()
{
$testfile = realpath(__FILE__);
$original = file_get_contents($testfile);
// Test Base64
$fp = fopen($testfile,'rb');
$this->assertTrue(is_resource($fp));
$part = new Zend_Mime_Part($fp);
$part->encoding = Zend_Mime::ENCODING_BASE64;
$fp2 = $part->getEncodedStream();
$this->assertTrue(is_resource($fp2));
$encoded = stream_get_contents($fp2);
fclose($fp);
$this->assertEquals(base64_decode($encoded),$original);
// test QuotedPrintable
$fp = fopen($testfile,'rb');
$this->assertTrue(is_resource($fp));
$part = new Zend_Mime_Part($fp);
$part->encoding = Zend_Mime::ENCODING_QUOTEDPRINTABLE;
$fp2 = $part->getEncodedStream();
$this->assertTrue(is_resource($fp2));
$encoded = stream_get_contents($fp2);
fclose($fp);
$this->assertEquals(quoted_printable_decode($encoded),$original);
}
}