<commit_before><?php

namespace Symfony\Cmf\Component\Routing\Tests\Enhancer;

use Symfony\Component\HttpFoundation\Request;

use Symfony\Cmf\Component\Routing\Enhancer\RouteContentEnhancer;

use Symfony\Cmf\Component\Routing\Test\CmfUnitTestCase;

class RouteContentEnhancerTest extends CmfUnitTestCase
{
    /**
     * @var RouteContentEnhancer
     */
    private $mapper;
    private $document;
    private $request;

    public function setUp()
    {
        $this->document = $this->buildMock('Symfony\\Cmf\\Component\\Routing\\Tests\\Enhancer\\RouteObject',
                                            array('getRouteContent', 'getRouteDefaults', 'getUrl'));

        $this->mapper = new RouteContentEnhancer('_route', '_content');

        $this->request = Request::create('/test');
    }

    public function testContent()
    {
        $targetDocument = new TargetDocument();
        $this->document->expects($this->once())
            ->method('getRouteContent')
            ->will($this->returnValue($targetDocument));

        $defaults = array('_route' => $this->document);
        $expected = array('_route' => $this->document, '_content' => $targetDocument);

        $this->assertEquals($expected, $this->mapper->enhance($defaults, $this->request));
    }


    public function testFieldAlreadyThere()
    {
        $this->document->expects($this->never())
            ->method('getRouteContent')
        ;

        $defaults = array('_route' => $this->document, '_content' => 'foo');

        $this->assertEquals($defaults, $this->mapper->enhance($defaults, $this->request));
    }

    public function testNoContent()
    {
        $this->document->expects($this->once())
            ->method('getRouteContent')
            ->will($this->returnValue(null));

        $defaults = array('_route' => $this->document);
        $this->assertEquals($defaults, $this->mapper->enhance($defaults, $this->request));
    }

    public function testNoCmfRoute()
    {
        $defaults = array('_route' => $this->buildMock('Symfony\\Component\\Routing\\Route'));
        $this->assertEquals($defaults, $this->mapper->enhance($defaults, $this->request));
    }
}

class TargetDocument
{
}

class UnknownDocument
{
}<commit_msg>adjust test to use the convention too<commit_after><?php

namespace Symfony\Cmf\Component\Routing\Tests\Enhancer;

use Symfony\Component\HttpFoundation\Request;

use Symfony\Cmf\Component\Routing\Enhancer\RouteContentEnhancer;
use Symfony\Cmf\Component\Routing\RouteObjectInterface;

use Symfony\Cmf\Component\Routing\Test\CmfUnitTestCase;

class RouteContentEnhancerTest extends CmfUnitTestCase
{
    /**
     * @var RouteContentEnhancer
     */
    private $mapper;
    private $document;
    private $request;

    public function setUp()
    {
        $this->document = $this->buildMock('Symfony\\Cmf\\Component\\Routing\\Tests\\Enhancer\\RouteObject',
                                            array('getRouteContent', 'getRouteDefaults', 'getUrl'));

        $this->mapper = new RouteContentEnhancer(RouteObjectInterface::ROUTE_OBJECT, '_content');

        $this->request = Request::create('/test');
    }

    public function testContent()
    {
        $targetDocument = new TargetDocument();
        $this->document->expects($this->once())
            ->method('getRouteContent')
            ->will($this->returnValue($targetDocument));

        $defaults = array(RouteObjectInterface::ROUTE_OBJECT => $this->document);
        $expected = array(RouteObjectInterface::ROUTE_OBJECT => $this->document, '_content' => $targetDocument);

        $this->assertEquals($expected, $this->mapper->enhance($defaults, $this->request));
    }


    public function testFieldAlreadyThere()
    {
        $this->document->expects($this->never())
            ->method('getRouteContent')
        ;

        $defaults = array(RouteObjectInterface::ROUTE_OBJECT => $this->document, '_content' => 'foo');

        $this->assertEquals($defaults, $this->mapper->enhance($defaults, $this->request));
    }

    public function testNoContent()
    {
        $this->document->expects($this->once())
            ->method('getRouteContent')
            ->will($this->returnValue(null));

        $defaults = array(RouteObjectInterface::ROUTE_OBJECT => $this->document);
        $this->assertEquals($defaults, $this->mapper->enhance($defaults, $this->request));
    }

    public function testNoCmfRoute()
    {
        $defaults = array(RouteObjectInterface::ROUTE_OBJECT => $this->buildMock('Symfony\\Component\\Routing\\Route'));
        $this->assertEquals($defaults, $this->mapper->enhance($defaults, $this->request));
    }
}

class TargetDocument
{
}

class UnknownDocument
{
}
{'fraction_non_alphanumeric': 0.15801786473840918, 'fraction_numerical': 0.0, 'mean_word_length': 3.1953612845673507, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 99, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7476193', 'n_tokens_mistral': 1326, 'n_tokens_neox': 1311, 'n_words': 194}