<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_View
 */

namespace ZendTest\View\Model;

use ArrayObject;
use stdClass;
use PHPUnit_Framework_TestCase as TestCase;
use Zend\View\Model\ViewModel;
use Zend\View\Variables as ViewVariables;
use ZendTest\View\Model\TestAsset\Variable;

/**
 * @category   Zend
 * @package    Zend_View
 * @subpackage UnitTest
 */
class ViewModelTest extends TestCase
{
    public function testAllowsEmptyConstructor()
    {
        $model = new ViewModel();
        $this->assertInstanceOf('Zend\View\Variables', $model->getVariables());
        $this->assertEquals(array(), $model->getOptions());
    }

    public function testAllowsEmptyOptionsArgumentToConstructor()
    {
        $model = new ViewModel(array('foo' => 'bar'));
        $this->assertEquals(array('foo' => 'bar'), $model->getVariables());
        $this->assertEquals(array(), $model->getOptions());
    }

    public function testAllowsPassingBothVariablesAndOptionsArgumentsToConstructor()
    {
        $model = new ViewModel(array('foo' => 'bar'), array('template' => 'foo/bar'));
        $this->assertEquals(array('foo' => 'bar'), $model->getVariables());
        $this->assertEquals(array('template' => 'foo/bar'), $model->getOptions());
    }

    public function testAllowsPassingTraversableArgumentsToVariablesAndOptionsInConstructor()
    {
        $vars    = new ArrayObject;
        $options = new ArrayObject;
        $model = new ViewModel($vars, $options);
        $this->assertSame($vars, $model->getVariables());
        $this->assertSame(iterator_to_array($options), $model->getOptions());
    }

    public function testAllowsPassingNonArrayAccessObjectsAsArrayInConstructor()
    {
        $vars  = array('foo' => new Variable);
        $model = new ViewModel($vars);
        $this->assertSame($vars, $model->getVariables());
    }

    public function testCanSetVariablesSingly()
    {
        $model = new ViewModel(array('foo' => 'bar'));
        $model->setVariable('bar', 'baz');
        $this->assertEquals(array('foo' => 'bar', 'bar' => 'baz'), $model->getVariables());
    }

    public function testCanOverwriteVariablesSingly()
    {
        $model = new ViewModel(array('foo' => 'bar'));
        $model->setVariable('foo', 'baz');
        $this->assertEquals(array('foo' => 'baz'), $model->getVariables());
    }

    public function testSetVariablesMergesWithPreviouslyStoredVariables()
    {
        $model = new ViewModel(array('foo' => 'bar', 'bar' => 'baz'));
        $model->setVariables(array('bar' => 'BAZBAT'));
        $this->assertEquals(array('foo' => 'bar', 'bar' => 'BAZBAT'), $model->getVariables());
    }

    public function testCanUnsetVariable()
    {
        $model = new ViewModel(array('foo' => 'bar'));
        $model->__unset('foo');                
        $this->assertEquals(array(), $model->getVariables());
    }<commit_msg>Fixed trailing spaces<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_View
 */

namespace ZendTest\View\Model;

use ArrayObject;
use stdClass;
use PHPUnit_Framework_TestCase as TestCase;
use Zend\View\Model\ViewModel;
use Zend\View\Variables as ViewVariables;
use ZendTest\View\Model\TestAsset\Variable;

/**
 * @category   Zend
 * @package    Zend_View
 * @subpackage UnitTest
 */
class ViewModelTest extends TestCase
{
    public function testAllowsEmptyConstructor()
    {
        $model = new ViewModel();
        $this->assertInstanceOf('Zend\View\Variables', $model->getVariables());
        $this->assertEquals(array(), $model->getOptions());
    }

    public function testAllowsEmptyOptionsArgumentToConstructor()
    {
        $model = new ViewModel(array('foo' => 'bar'));
        $this->assertEquals(array('foo' => 'bar'), $model->getVariables());
        $this->assertEquals(array(), $model->getOptions());
    }

    public function testAllowsPassingBothVariablesAndOptionsArgumentsToConstructor()
    {
        $model = new ViewModel(array('foo' => 'bar'), array('template' => 'foo/bar'));
        $this->assertEquals(array('foo' => 'bar'), $model->getVariables());
        $this->assertEquals(array('template' => 'foo/bar'), $model->getOptions());
    }

    public function testAllowsPassingTraversableArgumentsToVariablesAndOptionsInConstructor()
    {
        $vars    = new ArrayObject;
        $options = new ArrayObject;
        $model = new ViewModel($vars, $options);
        $this->assertSame($vars, $model->getVariables());
        $this->assertSame(iterator_to_array($options), $model->getOptions());
    }

    public function testAllowsPassingNonArrayAccessObjectsAsArrayInConstructor()
    {
        $vars  = array('foo' => new Variable);
        $model = new ViewModel($vars);
        $this->assertSame($vars, $model->getVariables());
    }

    public function testCanSetVariablesSingly()
    {
        $model = new ViewModel(array('foo' => 'bar'));
        $model->setVariable('bar', 'baz');
        $this->assertEquals(array('foo' => 'bar', 'bar' => 'baz'), $model->getVariables());
    }

    public function testCanOverwriteVariablesSingly()
    {
        $model = new ViewModel(array('foo' => 'bar'));
        $model->setVariable('foo', 'baz');
        $this->assertEquals(array('foo' => 'baz'), $model->getVariables());
    }

    public function testSetVariablesMergesWithPreviouslyStoredVariables()
    {
        $model = new ViewModel(array('foo' => 'bar', 'bar' => 'baz'));
        $model->setVariables(array('bar' => 'BAZBAT'));
        $this->assertEquals(array('foo' => 'bar', 'bar' => 'BAZBAT'), $model->getVariables());
    }

    public function testCanUnsetVariable()
    {
        $model = new ViewModel(array('foo' => 'bar'));
        $model->__unset('foo');
        $this->assertEquals(array(), $model->getVariables());
    }
{'fraction_non_alphanumeric': 0.16593059936908516, 'fraction_numerical': 0.0028391167192429023, 'mean_word_length': 3.5585909417685118, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 99, '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': '3096411', 'n_tokens_mistral': 1876, 'n_tokens_neox': 1812, 'n_words': 348}