Large diffs are not rendered by default.

@@ -16,31 +16,12 @@
*/
class ContentTypeTest extends \PHPUnit_Framework_TestCase
{
public function testContentTypeFromStringCreatesValidContentTypeHeader()
public function testImplementsHeaderInterface()
{
$contentTypeHeader = ContentType::fromString('Content-Type: xxx/yyy');
$this->assertInstanceOf('Zend\Mail\Header\HeaderInterface', $contentTypeHeader);
$this->assertInstanceOf('Zend\Mail\Header\ContentType', $contentTypeHeader);
}

public function testContentTypeGetFieldNameReturnsHeaderName()
{
$contentTypeHeader = new ContentType();
$this->assertEquals('Content-Type', $contentTypeHeader->getFieldName());
}
$header = new ContentType();

public function testContentTypeGetFieldValueReturnsProperValue()
{
$contentTypeHeader = new ContentType();
$contentTypeHeader->setType('foo/bar');
$this->assertEquals('foo/bar', $contentTypeHeader->getFieldValue());
}

public function testContentTypeToStringReturnsHeaderFormattedString()
{
$contentTypeHeader = new ContentType();
$contentTypeHeader->setType('foo/bar');
$this->assertEquals("Content-Type: foo/bar", $contentTypeHeader->toString());
$this->assertInstanceOf('Zend\Mail\Header\UnstructuredInterface', $header);
$this->assertInstanceOf('Zend\Mail\Header\HeaderInterface', $header);
}

/**
@@ -55,80 +36,53 @@ public function testTrailingSemiColonFromString()
$this->assertEquals(array('boundary' => 'Apple-Mail=_1B852F10-F9C6-463D-AADD-CD503A5428DD'), $params);
}

public function testProvidingParametersIntroducesHeaderFolding()
{
$header = new ContentType();
$header->setType('application/x-unit-test');
$header->addParameter('charset', 'us-ascii');
$string = $header->toString();

$this->assertContains("Content-Type: application/x-unit-test;", $string);
$this->assertContains(";\r\n charset=\"us-ascii\"", $string);
}

public function testExtractsExtraInformationFromContentType()
{
$contentTypeHeader = ContentType::fromString(
'Content-Type: multipart/alternative; boundary="Apple-Mail=_1B852F10-F9C6-463D-AADD-CD503A5428DD"'
);
$params = $contentTypeHeader->getParameters();
$this->assertEquals($params, array('boundary' => 'Apple-Mail=_1B852F10-F9C6-463D-AADD-CD503A5428DD'));
}

public function testExtractsExtraInformationWithoutBeingConfusedByTrailingSemicolon()
{
$header = ContentType::fromString('Content-Type: application/pdf;name="foo.pdf";');
$this->assertEquals($header->getParameters(), array('name' => 'foo.pdf'));
}

/**
* @group #2728
*
* Tests setting different MIME types
* @dataProvider setTypeProvider
*/
public function testSetContentType()
public function testFromString($type, $parameters, $fieldValue, $expectedToString)
{
$header = new ContentType();

$header->setType('application/vnd.ms-excel');
$this->assertEquals('Content-Type: application/vnd.ms-excel', $header->toString());

$header->setType('application/rss+xml');
$this->assertEquals('Content-Type: application/rss+xml', $header->toString());

$header->setType('video/mp4');
$this->assertEquals('Content-Type: video/mp4', $header->toString());

$header->setType('message/rfc822');
$this->assertEquals('Content-Type: message/rfc822', $header->toString());
$header = ContentType::fromString($expectedToString);

$this->assertInstanceOf('Zend\Mail\Header\ContentType', $header);
$this->assertEquals('Content-Type', $header->getFieldName(), 'getFieldName() value not match');
$this->assertEquals($type, $header->getType(), 'getType() value not match');
$this->assertEquals($fieldValue, $header->getFieldValue(), 'getFieldValue() value not match');
$this->assertEquals($parameters, $header->getParameters(), 'getParameters() value not match');
$this->assertEquals($expectedToString, $header->toString(), 'toString() value not match');
}

/**
* @group ZF2015-04
* @dataProvider setTypeProvider
*/
public function testFromStringRaisesExceptionForInvalidName()
public function testSetType($type, $parameters, $fieldValue, $expectedToString)
{
$this->setExpectedException('Zend\Mail\Header\Exception\InvalidArgumentException', 'header name');
$header = ContentType::fromString('Content-Type' . chr(32) . ': text/html');
}
$header = new ContentType();

public function headerLines()
{
return array(
'newline' => array("Content-Type: text/html;\nlevel=1"),
'cr-lf' => array("Content-Type: text/html\r\n;level=1",),
'multiline' => array("Content-Type: text/html;\r\nlevel=1\r\nq=0.1"),
);
$header->setType($type);
foreach ($parameters as $name => $value) {
$header->addParameter($name, $value);
}

$this->assertEquals('Content-Type', $header->getFieldName(), 'getFieldName() value not match');
$this->assertEquals($type, $header->getType(), 'getType() value not match');
$this->assertEquals($fieldValue, $header->getFieldValue(), 'getFieldValue() value not match');
$this->assertEquals($parameters, $header->getParameters(), 'getParameters() value not match');
$this->assertEquals($expectedToString, $header->toString(), 'toString() value not match');
}

/**
* @dataProvider headerLines
* @group ZF2015-04
* @dataProvider invalidHeaderLinesProvider
*/
public function testFromStringRaisesExceptionForNonFoldingMultilineValues($headerLine)
public function testFromStringThrowException($headerLine, $expectedException, $exceptionMessage)
{
$this->setExpectedException('Zend\Mail\Header\Exception\InvalidArgumentException', 'header value');
$header = ContentType::fromString($headerLine);
$this->setExpectedException($expectedException, $exceptionMessage);
ContentType::fromString($headerLine);
}

/**
@@ -142,24 +96,66 @@ public function testFromStringHandlesContinuations()
}

/**
* @group ZF2015-04
* @dataProvider invalidParametersProvider
*/
public function testAddParameterRaisesInvalidArgumentExceptionForInvalidParameterName()
public function testAddParameterThrowException($paramName, $paramValue, $expectedException, $exceptionMessage)
{
$header = new ContentType();
$header->setType('text/html');
$this->setExpectedException('Zend\Mail\Header\Exception\InvalidArgumentException', 'parameter name');
$header->addParameter("b\r\na\rr\n", "baz");

$this->setExpectedException($expectedException, $exceptionMessage);
$header->addParameter($paramName, $paramValue);
}

/**
* @group ZF2015-04
*/
public function testAddParameterRaisesInvalidArgumentExceptionForInvalidParameterValue()
public function setTypeProvider()
{
$header = new ContentType();
$header->setType('text/html');
$this->setExpectedException('Zend\Mail\Header\Exception\InvalidArgumentException', 'parameter value');
$header->addParameter('foo', "\nbar\r\nbaz\r");
$foldingHeaderLine = "Content-Type: foo/baz;\r\n charset=\"us-ascii\"";
$foldingFieldValue = "foo/baz;\r\n charset=\"us-ascii\"";

$encodedHeaderLine = "Content-Type: foo/baz;\r\n name=\"=?UTF-8?Q?=C3=93?=\"";
$encodedFieldValue = "foo/baz;\r\n name=\"Ă“\"";

// @codingStandardsIgnoreStart
return array(
// Description => [$type, $parameters, $fieldValue, toString()]
// @group #2728
'foo/a.b-c' => array('foo/a.b-c', array(), 'foo/a.b-c', 'Content-Type: foo/a.b-c'),
'foo/a+b' => array('foo/a+b' , array(), 'foo/a+b' , 'Content-Type: foo/a+b'),
'foo/baz' => array('foo/baz' , array(), 'foo/baz' , 'Content-Type: foo/baz'),
'parameter use header folding' => array('foo/baz' , array('charset' => 'us-ascii'), $foldingFieldValue, $foldingHeaderLine),
'encoded characters' => array('foo/baz' , array('name' => 'Ă“'), $encodedFieldValue, $encodedHeaderLine),
);
// @codingStandardsIgnoreEnd
}

public function invalidParametersProvider()
{
$invalidArgumentException = 'Zend\Mail\Header\Exception\InvalidArgumentException';

// @codingStandardsIgnoreStart
return array(
// Description => [param name, param value, expected exception, exception message contain]

// @group ZF2015-04
'invalid name' => array("b\r\na\rr\n", 'baz', $invalidArgumentException, 'parameter name'),
);
// @codingStandardsIgnoreEnd
}

public function invalidHeaderLinesProvider()
{
$invalidArgumentException = 'Zend\Mail\Header\Exception\InvalidArgumentException';

// @codingStandardsIgnoreStart
return array(
// Description => [header line, expected exception, exception message contain]

// @group ZF2015-04
'invalid name' => array('Content-Type' . chr(32) . ': text/html', $invalidArgumentException, 'header name'),
'newline' => array("Content-Type: text/html;\nlevel=1", $invalidArgumentException, 'header value'),
'cr-lf' => array("Content-Type: text/html\r\n;level=1", $invalidArgumentException, 'header value'),
'multiline' => array("Content-Type: text/html;\r\nlevel=1\r\nq=0.1", $invalidArgumentException, 'header value'),
);
// @codingStandardsIgnoreEnd
}
}
@@ -30,7 +30,8 @@ public function getFilterValues()
array("This is a\r\r test", "This is a test"),
array("This is a \r\r\n test", "This is a \r\n test"),
array("This is a \r\n\r\ntest", "This is a test"),
array("This is a \r\n\n\r\n test", "This is a \r\n test")
array("This is a \r\n\n\r\n test", "This is a \r\n test"),
array("This is a test\r\n", "This is a test"),
);
}

@@ -50,13 +51,18 @@ public function validateValues()
array("This is a\r test", 'assertFalse'),
array("This is a\n\r test", 'assertFalse'),
array("This is a\r\n test", 'assertTrue'),
array("This is a\r\n\ttest", 'assertTrue'),
array("This is a \r\ntest", 'assertFalse'),
array("This is a \r\n\n test", 'assertFalse'),
array("This is a\n\n test", 'assertFalse'),
array("This is a\r\r test", 'assertFalse'),
array("This is a \r\r\n test", 'assertFalse'),
array("This is a \r\n\r\ntest", 'assertFalse'),
array("This is a \r\n\n\r\n test", 'assertFalse')
array("This is a \r\n\n\r\n test", 'assertFalse'),
array("This\tis\ta test", 'assertTrue'),
array("This is\ta \r\n test", 'assertTrue'),
array("This\tis\ta\ntest", 'assertFalse'),
array("This is a \r\t\n \r\n test", 'assertFalse'),
);
}

@@ -81,7 +87,7 @@ public function assertValues()
array("This is a\r\r test"),
array("This is a \r\r\n test"),
array("This is a \r\n\r\ntest"),
array("This is a \r\n\n\r\n test")
array("This is a \r\n\n\r\n test"),
);
}

@@ -31,15 +31,15 @@ public function testGetFieldNameReturnsHeaderName()
}

/**
* @dataProvider validSenderDataProvider
* @dataProvider validSenderHeaderDataProvider
* @group ZF2015-04
* @param string $email
* @param null|string $name
* @param string $expectedFieldValue,
* @param string $encodedValue
* @param string $encoding
*/
public function testParseValidSenderHeader($email, $name, $expectedFieldValue, $encodedValue, $encoding)
public function testParseValidSenderHeader($expectedFieldValue, $encodedValue, $encoding)
{
$header = Header\Sender::fromString('Sender:' . $encodedValue);

@@ -145,6 +145,20 @@ public function validSenderDataProvider()
);
}

public function validSenderHeaderDataProvider()
{
return array_merge(array_map(function ($parameters) {
return array_slice($parameters, 2);
}, $this->validSenderDataProvider()), array(
// Per RFC 2822, 3.4 and 3.6.2, "Sender: foo@bar" is valid.
'Unbracketed email' => array(
'<foo@bar>',
'foo@bar',
'ASCII'
)
));
}

public function invalidSenderDataProvider()
{
$mailInvalidArgumentException = 'Zend\Mail\Exception\InvalidArgumentException';
@@ -199,6 +199,16 @@ public function testCanAddFromAddressUsingName()
$this->assertEquals('ZF DevTeam', $address->getName());
}

public function testCanAddFromAddressUsingEmailAndNameAsString()
{
$this->message->addFrom('ZF DevTeam <zf-devteam@example.com>');
$addresses = $this->message->getFrom();
$this->assertEquals(1, count($addresses));
$address = $addresses->current();
$this->assertEquals('zf-devteam@example.com', $address->getEmail());
$this->assertEquals('ZF DevTeam', $address->getName());
}

public function testCanAddFromAddressUsingAddressObject()
{
$address = new Address('zf-devteam@example.com', 'ZF DevTeam');
@@ -753,7 +763,7 @@ public function testHeaderUnfoldingWorksAsExpectedForMultipartMessages()
$text->encoding = Mime::ENCODING_QUOTEDPRINTABLE;
$text->disposition = Mime::DISPOSITION_INLINE;
$text->charset = 'UTF-8';

$html = new MimePart('<b>Test content</b>');
$html->type = Mime::TYPE_HTML;
$html->encoding = Mime::ENCODING_QUOTEDPRINTABLE;
@@ -39,40 +39,40 @@ public function testInvalidFile()
$this->fail('no exception raised while loading unknown file');
}

public function testIsMultipart()
/**
* @dataProvider filesProvider
*/
public function testIsMultipart($params)
{
$message = new Message(array('file' => $this->_file));

$message = new Message($params);
$this->assertTrue($message->isMultipart());
}

public function testGetHeader()
/**
* @dataProvider filesProvider
*/
public function testGetHeader($params)
{
$message = new Message(array('file' => $this->_file));

$message = new Message($params);
$this->assertEquals($message->subject, 'multipart');
}

public function testGetDecodedHeader()
/**
* @dataProvider filesProvider
*/
public function testGetDecodedHeader($params)
{
$message = new Message(array('file' => $this->_file));

$message = new Message($params);
$this->assertEquals('Peter MĂĽller <peter-mueller@example.com>', $message->from);
}

public function testGetHeaderAsArray()
{
$message = new Message(array('file' => $this->_file));

$this->assertEquals($message->getHeader('subject', 'array'), array('multipart'));
}

public function testGetHeaderFromOpenFile()
/**
* @dataProvider filesProvider
*/
public function testGetHeaderAsArray($params)
{
$fh = fopen($this->_file, 'r');
$message = new Message(array('file' => $fh));

$this->assertEquals($message->subject, 'multipart');
$message = new Message($params);
$this->assertEquals(array('multipart'), $message->getHeader('subject', 'array'), 'getHeader() value not match');
}

public function testGetFirstPart()
@@ -428,4 +428,18 @@ public function testStrictParseMessage()
$raw = "From foo@example.com Sun Jan 01 00:00:00 2000\n" . $raw;
$message = new Message(array('raw' => $raw, 'strict' => true));
}

public function filesProvider()
{
$filePath = __DIR__ . '/../_files/mail.txt';
$fileBlankLineOnTop = __DIR__ . '/../_files/mail_blank_top_line.txt';

return array(
// Description => [params]
'resource' => array(array('file' => fopen($filePath, 'r'))),
'file path' => array(array('file' => $filePath)),
'raw' => array(array('raw' => file_get_contents($filePath))),
'file with blank line on top' => array(array('file' => $fileBlankLineOnTop)),
);
}
}
@@ -10,6 +10,7 @@
namespace ZendTest\Mail\Transport;

use Zend\Mail\Message;
use Zend\Mail\Transport\Exception\RuntimeException;
use Zend\Mail\Transport\Sendmail;

/**
@@ -128,4 +129,28 @@ public function testAssertSubjectEncoded()
$this->transport->send($message);
$this->assertEquals('=?UTF-8?Q?Testing=20Zend\Mail\Transport\Sendmail?=', $this->subject);
}

public function testCodeInjectionInFromHeader()
{
$message = $this->getMessage();
$message->setBody('This is the text of the email.');
$message->setFrom('"AAA\" code injection"@domain', 'Sender\'s name');
$message->addTo('hacker@localhost', 'Name of recipient');
$message->setSubject('TestSubject');

$this->setExpectedException(RuntimeException::class);
$this->transport->send($message);
}

public function testValidEmailLocaDomainInFromHeader()
{
$message = $this->getMessage();
$message->setBody('This is the text of the email.');
$message->setFrom('"foo-bar"@domain', 'Foo Bar');
$message->addTo('hacker@localhost', 'Name of recipient');
$message->setSubject('TestSubject');

$this->transport->send($message);
$this->assertContains('From: Foo Bar <"foo-bar"@domain>', $this->additional_headers);
}
}
@@ -0,0 +1,28 @@

To: foo@example.com
Subject: multipart
Date: Sun, 01 Jan 2000 00:00:00 +0000
From: =?UTF-8?Q?"Peter M=C3=BCller"?= <peter-mueller@example.com>
ContENT-type: multipart/alternative; boUNDary="crazy-multipart"
Message-ID: <CALTvGe4_oYgf9WsYgauv7qXh2-6=KbPLExmJNG7fCs9B=1nOYg@mail.example.com>
MIME-version: 1.0

multipart message
--crazy-multipart
Content-type: text/plain

The first part
is horizontal

--crazy-multipart
Content-type: text/x-vertical

T s p i v
h e a s e
e c r r
o t t
n i
d c
a
l
--crazy-multipart--
@@ -25,7 +25,7 @@
use Zend\Stdlib\Parameters;
use Zend\Validator\NotEmpty;
use ZendTest\Mvc\Controller\TestAsset\SampleController;
use ZendTest\Session\TestAsset\TestManager as SessionManager;
use ZendTest\Mvc\TestAsset\SessionManager;

class FilePostRedirectGetTest extends TestCase
{
@@ -407,6 +407,6 @@ public function testCorrectInputDataMerging()

$messages = $form->getMessages();
$this->assertTrue(isset($messages['collection'][1]['text'][NotEmpty::IS_EMPTY]));
$this->assertTrue(isset($messages['collection'][1]['file'][NotEmpty::IS_EMPTY]));
$this->assertTrue(isset($messages['collection'][1]['file'][NotEmpty::IS_EMPTY]), var_export($messages['collection'][1], 1));
}
}
@@ -10,7 +10,7 @@
namespace ZendTest\Mvc\Controller\Plugin;

use Zend\Mvc\Controller\Plugin\FlashMessenger;
use ZendTest\Session\TestAsset\TestManager as SessionManager;
use ZendTest\Mvc\TestAsset\SessionManager;

class FlashMessengerTest extends \PHPUnit_Framework_TestCase
{
@@ -22,7 +22,7 @@
use Zend\Mvc\ModuleRouteListener;
use Zend\Stdlib\Parameters;
use ZendTest\Mvc\Controller\TestAsset\SampleController;
use ZendTest\Session\TestAsset\TestManager as SessionManager;
use ZendTest\Mvc\TestAsset\SessionManager;

class PostRedirectGetTest extends TestCase
{
@@ -15,7 +15,7 @@
use Zend\I18n\Translator\Translator;
use Zend\Stdlib\Request as BaseRequest;
use Zend\Mvc\Router\Http\Segment;
use ZendTest\I18n\Translator\TestAsset\Loader as TestLoader;
use ZendTest\Mvc\TestAsset\TranslatorLoader as TestLoader;
use ZendTest\Mvc\Router\FactoryTester;

class SegmentTest extends TestCase
@@ -30,8 +30,8 @@ public static function routeProvider()
$enLoader->textDomain = new TextDomain(array('fw' => 'framework'));
$deLoader->textDomain = new TextDomain(array('fw' => 'baukasten'));
$domainLoader->textDomain = new TextDomain(array('fw' => 'fw-alternative'));
$translator->getPluginManager()->setService('test-en', $enLoader);
$translator->getPluginManager()->setService('test-de', $deLoader);
$translator->getPluginManager()->setService('test-en', $enLoader);
$translator->getPluginManager()->setService('test-de', $deLoader);
$translator->getPluginManager()->setService('test-domain', $domainLoader);
$translator->addTranslationFile('test-en', null, 'default', 'en-US');
$translator->addTranslationFile('test-de', null, 'default', 'de-DE');
@@ -0,0 +1,113 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

namespace ZendTest\Mvc\TestAsset;

use Zend\Console\Adapter\AbstractAdapter;

/**
* @group Zend_Console
*/
class ConsoleAdapter extends AbstractAdapter
{
public $stream;

public $autoRewind = true;

public $testWidth = 80;

public $testIsUtf8 = true;

public $writtenData = array();

/**
* Construct.
*
* @param bool $autoRewind If rewinds the stream before read the next char/line
*/
public function __construct($autoRewind = true)
{
$this->autoRewind = (bool) $autoRewind;
}

/**
* Read a single line from the console input
*
* @param int $maxLength Maximum response length
* @return string
*/
public function readLine($maxLength = 2048)
{
if ($this->autoRewind) {
rewind($this->stream);
}
$line = stream_get_line($this->stream, $maxLength, PHP_EOL) ?: '';
return rtrim($line, PHP_EOL);
}

/**
* Read a single character from the console input
*
* @param string|null $mask A list of allowed chars
* @return string
*/
public function readChar($mask = null)
{
if ($this->autoRewind) {
rewind($this->stream);
}
do {
$char = fread($this->stream, 1);
} while ("" === $char || ($mask !== null && false === strstr($mask, $char)));
return $char;
}

/**
* Force reported width for testing purposes.
*
* @param int $width
* @return int
*/
public function setTestWidth($width)
{
$this->testWidth = $width;
}

/**
* Force reported utf8 capability.
*
* @param bool $isUtf8
*/
public function setTestUtf8($isUtf8)
{
$this->testIsUtf8 = $isUtf8;
}

public function isUtf8()
{
return $this->testIsUtf8;
}

public function getWidth()
{
return $this->testWidth;
}

/**
* Tracks exactly what data has been written
* @param string $text
* @param null $color
* @param null $bgColor
*/
public function write($text, $color = null, $bgColor = null)
{
$this->writtenData[] = $text;
parent::write($text, $color, $bgColor);
}
}
@@ -0,0 +1,88 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

namespace ZendTest\Mvc\TestAsset;

use Zend\EventManager\EventManagerInterface;
use Zend\Session\AbstractManager;

class SessionManager extends AbstractManager
{
public $started = false;

protected $configDefaultClass = 'Zend\\Session\\Configuration\\StandardConfig';
protected $storageDefaultClass = 'Zend\\Session\\Storage\\ArrayStorage';

public function start()
{
$this->started = true;
}

public function destroy()
{
$this->started = false;
}

public function stop()
{
}

public function writeClose()
{
$this->started = false;
}

public function getName()
{
}

public function setName($name)
{
}

public function getId()
{
}

public function setId($id)
{
}

public function regenerateId()
{
}

public function rememberMe($ttl = null)
{
}

public function forgetMe()
{
}

public function setValidatorChain(EventManagerInterface $chain)
{
}

public function getValidatorChain()
{
}

public function isValid()
{
}

public function sessionExists()
{
}

public function expireSessionCookie()
{
}
}
@@ -0,0 +1,33 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

namespace ZendTest\Mvc\TestAsset;

use Zend\I18n\Translator\Loader\FileLoaderInterface;

/**
* Test loader.
*/
class TranslatorLoader implements FileLoaderInterface
{
public $textDomain;

/**
* load(): defined by LoaderInterface.
*
* @see LoaderInterface::load()
* @param string $filename
* @param string $locale
* @return TextDomain|null
*/
public function load($filename, $locale)
{
return $this->textDomain;
}
}
@@ -11,13 +11,13 @@

use PHPUnit_Framework_TestCase as TestCase;
use Zend\EventManager\EventManager;
use Zend\Mvc\ApplicationInterface;
use Zend\Mvc\MvcEvent;
use Zend\Mvc\View\Console\DefaultRenderingStrategy;
use Zend\ServiceManager\ServiceManager;
use Zend\Stdlib\Response;
use Zend\View\Model;
use ZendTest\Console\TestAssets\ConsoleAdapter;
use ZendTest\ModuleManager\TestAsset\MockApplication;
use ZendTest\Mvc\TestAsset\ConsoleAdapter;

class DefaultRenderingStrategyTest extends TestCase
{
@@ -37,6 +37,8 @@ public function testAttachesRendererAtExpectedPriority()
$expectedCallback = array($this->strategy, 'render');
$expectedPriority = -10000;
$found = false;

/* @var \Zend\Stdlib\CallbackHandler $listener */
foreach ($listeners as $listener) {
$callback = $listener->getCallback();
if ($callback === $expectedCallback) {
@@ -61,12 +63,22 @@ public function testCanDetachListenersFromEventManager()

public function testIgnoresNonConsoleModelNotContainingResultKeyWhenObtainingResult()
{
$console = $this->getMock('Zend\Console\Adapter\AbstractAdapter');
$console
->expects($this->any())
->method('encodeText')
->willReturnArgument(0);

//Register console service
$sm = new ServiceManager();
$sm->setService('console', new ConsoleAdapter());

$mockApplication = new MockApplication;
$mockApplication->setServiceManager($sm);
/* @var \PHPUnit_Framework_MockObject_MockObject|ApplicationInterface $mockApplication */
$mockApplication = $this->getMock('Zend\Mvc\ApplicationInterface');
$mockApplication
->expects($this->any())
->method('getServiceManager')
->willReturn($sm);

$event = new MvcEvent();
$event->setApplication($mockApplication);
@@ -79,4 +91,33 @@ public function testIgnoresNonConsoleModelNotContainingResultKeyWhenObtainingRes
$content = $response->getContent();
$this->assertNotContains('Page not found', $content);
}

public function testIgnoresNonModel()
{
$console = $this->getMock('Zend\Console\Adapter\AbstractAdapter');
$console
->expects($this->any())
->method('encodeText')
->willReturnArgument(0);

//Register console service
$sm = new ServiceManager();
$sm->setService('console', $console);

/* @var \PHPUnit_Framework_MockObject_MockObject|ApplicationInterface $mockApplication */
$mockApplication = $this->getMock('Zend\Mvc\ApplicationInterface');
$mockApplication
->expects($this->any())
->method('getServiceManager')
->willReturn($sm);

$event = new MvcEvent();
$event->setApplication($mockApplication);

$model = true;
$response = new Response();
$event->setResult($model);
$event->setResponse($response);
$this->assertSame($response, $this->strategy->render($event));
}
}
@@ -35,6 +35,24 @@ public function testInsert()
}
}

public function testInsertDuplicates()
{
$this->list->insert('foo', new \stdClass());
$this->list->insert('bar', new \stdClass());

$this->assertEquals(2, count($this->list));

$this->list->insert('foo', new \stdClass());
$this->list->insert('foo', new \stdClass());
$this->list->insert('bar', new \stdClass());

$this->assertEquals(2, count($this->list));

$this->list->remove('foo');

$this->assertEquals(1, count($this->list));
}

public function testRemove()
{
$this->list->insert('foo', new \stdClass(), 0);
@@ -65,7 +65,7 @@ public function basicProvider()
array(null, false),
array(array(), false),
array(array(5), true),
array(0.0, false),
array(0.0, true),
array(1.0, true),
array(new stdClass(), true),
);
@@ -975,7 +975,6 @@ public function testDefaultType()
{
$this->assertSame(
NotEmpty::BOOLEAN
| NotEmpty::FLOAT
| NotEmpty::STRING
| NotEmpty::EMPTY_ARRAY
| NotEmpty::NULL
@@ -219,4 +219,12 @@ public function testCanUseXForwardedPortIfProvided()
$url->setUseProxy(true);
$this->assertEquals('http://www.secondhost.org:8888', $url->__invoke());
}

public function testUsesHostHeaderWhenPortForwardingDetected()
{
$_SERVER['HTTP_HOST'] = 'localhost:10088';
$_SERVER['SERVER_PORT'] = 10081;
$url = new Helper\ServerUrl();
$this->assertEquals('http://localhost:10088', $url->__invoke());
}
}