<commit_before><?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_Mvc
 */

namespace ZendTest\Mvc\View;

use PHPUnit_Framework_TestCase as TestCase;
use Zend\EventManager\EventManager;
use Zend\Http\Request;
use Zend\Http\Response;
use Zend\Mvc\Application;
use Zend\Mvc\MvcEvent;
use Zend\Mvc\View\Http\RouteNotFoundStrategy;
use Zend\View\Model\ViewModel;

/**
 * @category   Zend
 * @package    Zend_Mvc
 * @subpackage UnitTest
 */
class RouteNotFoundStrategyTest extends TestCase
{
    public function setUp()
    {
        $this->strategy = new RouteNotFoundStrategy();
    }

    public function testMessageParamsInViewModel()
    {
        $response = new Response();
        $event    = new MvcEvent();
        $event->setResponse($response);
        $response->setStatusCode(404);

        $event->setResult(null);

        $testCase = array(
            'assertEquals' => array (
                'bar',
                new ViewModel(array('message' => 'bar')),
            ),
            'assertTrue' => array (
                null,
                new ViewModel(),
            )
        );
        foreach ($testCase as $type => $results) {
            foreach ($results as $resultEvent) {
                $event->setResult($resultEvent);
                $this->strategy->prepareNotFoundViewModel($event);
                $viewModel = $event->getResult();
                $this->assertInstanceOf('Zend\View\Model\ModelInterface', $viewModel);
                $variables = $viewModel->getVariables();
                switch ($type) {
                    case 'assertEquals':
                        $this->assertEquals('bar', $variables['message']);
                        break;
                    case 'assertTrue':
                        $this->assertTrue(isset($variables['message']));
                        break;
                }
            }<commit_msg>[#2286] Test cleanup<commit_after><?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_Mvc
 */

namespace ZendTest\Mvc\View;

use PHPUnit_Framework_TestCase as TestCase;
use Zend\EventManager\EventManager;
use Zend\Http\Request;
use Zend\Http\Response;
use Zend\Mvc\Application;
use Zend\Mvc\MvcEvent;
use Zend\Mvc\View\Http\RouteNotFoundStrategy;
use Zend\View\Model\ViewModel;

/**
 * @category   Zend
 * @package    Zend_Mvc
 * @subpackage UnitTest
 */
class RouteNotFoundStrategyTest extends TestCase
{
    public function setUp()
    {
        $this->strategy = new RouteNotFoundStrategy();
    }

    public function notFoundResponseProvider()
    {
        return array(
            array('bar', 'assertEquals'),
            array(null,  'assertTrue'),
            array(new ViewModel(array('message' => 'bar')), 'assertEquals'),
            array(new ViewModel(),  'assertTrue'),
        );
    }

    /**
     * @dataProvider notFoundResponseProvider
     */
    public function testLeavesReturnedMessageIntact($result, $assertion)
    {
        $response = new Response();
        $event    = new MvcEvent();
        $response->setStatusCode(404);
        $event->setResponse($response);

        $event->setResult($result);
        $this->strategy->prepareNotFoundViewModel($event);

        $viewModel = $event->getResult();
        $this->assertInstanceOf('Zend\View\Model\ModelInterface', $viewModel);

        $variables = $viewModel->getVariables();
        switch ($assertion) {
            case 'assertEquals':
                // Testing if we returned a message in the result
                $this->assertEquals('bar', $variables['message']);
                break;
            case 'assertTrue':
                // Testing if no message was returned in the result; in that
                // case, default message is used from strategy
                $this->assertTrue(isset($variables['message']));
                break;
{'fraction_non_alphanumeric': 0.12623138602520045, 'fraction_numerical': 0.006414662084765177, 'mean_word_length': 2.2655198204936426, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '931711', 'n_tokens_mistral': 1219, 'n_tokens_neox': 1156, 'n_words': 257}