Skip to content

Commit

Permalink
add ContentTransferEncoding Headers
Browse files Browse the repository at this point in the history
  • Loading branch information
prolic committed Dec 30, 2012
1 parent eecbe14 commit 52dd72b
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 0 deletions.
52 changes: 52 additions & 0 deletions library/Zend/Http/Header/ContentTransferEncoding.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_Http
*/

namespace Zend\Http\Header;

/**
* @throws Exception\InvalidArgumentException
* @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.11 @todo find section
*/
class ContentTransferEncoding implements HeaderInterface
{

public static function fromString($headerLine)
{
$header = new static();

list($name, $value) = explode(': ', $headerLine, 2);

// check to ensure proper header type for this factory
if (strtolower($name) !== 'content-transfer-encoding') {
throw new Exception\InvalidArgumentException('Invalid header line for Content-Transfer-Encoding string: "' . $name . '"');
}

// @todo implementation details
$header->value = $value;

return $header;
}

public function getFieldName()
{
return 'Content-Transfer-Encoding';
}

public function getFieldValue()
{
return $this->value;
}

public function toString()
{
return 'Content-Transfer-Encoding: ' . $this->getFieldValue();
}

}
51 changes: 51 additions & 0 deletions tests/ZendTest/Http/Header/ContentTransferEncodingTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_Http
*/

namespace ZendTest\Http\Header;

use Zend\Http\Header\ContentTransferEncoding;

class ContentTransferEncodingTest extends \PHPUnit_Framework_TestCase
{

public function testContentTransferEncodingFromStringCreatesValidContentTransferEncodingHeader()
{
$contentTransferEncodingHeader = ContentTransferEncoding::fromString('Content-Transfer-Encoding: xxx');
$this->assertInstanceOf('Zend\Http\Header\HeaderInterface', $contentTransferEncodingHeader);
$this->assertInstanceOf('Zend\Http\Header\ContentTransferEncoding', $contentTransferEncodingHeader);
}

public function testContentTransferEncodingGetFieldNameReturnsHeaderName()
{
$contentTransferEncodingHeader = new ContentTransferEncoding();
$this->assertEquals('Content-Transfer-Encoding', $contentTransferEncodingHeader->getFieldName());
}

public function testContentTransferEncodingGetFieldValueReturnsProperValue()
{
$this->markTestIncomplete('ContentTransferEncoding needs to be completed');

$contentTransferEncodingHeader = new ContentTransferEncoding();
$this->assertEquals('xxx', $contentTransferEncodingHeader->getFieldValue());
}

public function testContentTransferEncodingToStringReturnsHeaderFormattedString()
{
$this->markTestIncomplete('ContentTransferEncoding needs to be completed');

$contentTransferEncodingHeader = new ContentTransferEncoding();

// @todo set some values, then test output
$this->assertEmpty('Content-Transfer-Encoding: xxx', $contentTransferEncodingHeader->toString());
}

/** Implmentation specific tests here */

}

0 comments on commit 52dd72b

Please sign in to comment.