<commit_before><?php

namespace Kamereon;

class PageTest extends \PHPUnit_Framework_TestCase
{
    protected $page;
    protected $config;

    protected function setUp()
    {
        $this->config = include(__DIR__.'/../fixtures/config.php');
        $this->page = new Page($this->config);
    }

    /**
     * @covers Kamereon\Page::getConfig
     */
    public function testGetConfig()
    {
        $this->assertTrue(is_array($this->page->getConfig()));
    }

    /**
     * @covers Kamereon\Page::get
     */
    public function testGetDefaultCardForSlot()
    {
        $headlineCard = $this->page->get('headline');
        $this->assertEquals('Join our free service today.', $headlineCard);
    }

    /**
     * @covers Kamereon\Page::get
     */
    public function testGetCardForSlotWithArgument()
    {
        $headlineCard = $this->page->get('headline', 1);
        $this->assertEquals('Welcome, valued customer.', $headlineCard);
    }

    /**
     * @covers Kamereon\Page::get
     */
    public function testGetCardForSlotWithHttpGetParameter()
    {
        $request = \Symfony\Component\HttpFoundation\Request::create('?h=3', 'GET');

        $page = new Page($this->config, $request);
        
        $headlineCard = $page->get('headline');
        $this->assertEquals('Check out our special offers', $headlineCard);
    }


    /**
     * @covers Kamereon\Page::get
     */
    public function testGetCardForSlotWithHttpGetParameterAndArgument()
    {   
        $request = \Symfony\Component\HttpFoundation\Request::create('?h=3', 'GET');
        $page = new Page($this->config, $request);

        $headlineCard = $page->get('headline', 1);
        $this->assertEquals('Check out our special offers', $headlineCard);
    }

    /**
     * @covers Kamereon\Page::get
     * @covers Kamereon\Page::setRequest
     */
    public function testSetRequest()
    {
        $page = clone $this->page;
        $request = \Symfony\Component\HttpFoundation\Request::create('?h=3', 'GET');

        $page->setRequest($request);

        $headlineCard = $page->get('headline', 1);
        $this->assertEquals('Check out our special offers', $headlineCard);
    }

    /**
     * @covers Kamereon\Page::get
     */
    public function testGetCardForSlotWithHttpGetParametersAndNestedSlots()
    {
        $request = \Symfony\Component\HttpFoundation\Request::create('?h=2&uid=3', 'GET');
        $page = new Page($this->config, $request);

        $headlineCard = $page->get('headline');
        $this->assertEquals('Welcome back, Brian!', $headlineCard);
    }

    /**
     * @covers Kamereon\Page::getRequest
     */
    public function testGetRequest()
    {
        $request = $this->page->getRequest();

        $this->assertInstanceOf('\Symfony\Component\HttpFoundation\Request', $request);
        // $this->assertTrue($request instanceof \Symfony\Component\HttpFoundation\Request);
    }

    /**
     * @covers Kamereon\Page::offsetGet
     */
    public function testOffsetGet()
    {
        $this->assertInstanceOf('\Kamereon\Slot', $this->page['headline']);
    }

    /**
     * @covers Kamereon\Page::offsetExists
     */
    public function testOffsetExists()
    {
        $this->assertTrue(isset($this->page['headline']));
        $this->assertFalse(isset($this->page['missing']));
    }

    /**
     * @covers Kamereon\Page::offsetExists
     * @expectedException InvalidArgumentException
     */
    public function testGetThrowsException()
    {
        $this->setExpectedException('InvalidArgumentException');

        $fake = $this->page->get('fake');
    }

    /**
     * @covers Kamereon\Page::offsetSet
     */
    public function testOffsetSet()
    {
        $newSlot = new Slot('newslot', array(
            'keyBind' => 'z',
            'cards'   => array('One', 'Two')
        ));
        $page = new Page($this->config);
        $page['newslot'] = $newSlot;<commit_msg>Closes #4, loading test config in setUpBeforeClass method<commit_after><?php

namespace Kamereon;

class PageTest extends \PHPUnit_Framework_TestCase
{
    protected $page;
    protected static $config;

    public static function setUpBeforeClass()
    {
        self::$config = include(__DIR__.'/../fixtures/config.php');
    }

    protected function setUp()
    {
        $this->page = new Page(self::$config);
    }

    /**
     * @covers Kamereon\Page::getConfig
     */
    public function testGetConfig()
    {
        $this->assertTrue(is_array($this->page->getConfig()));
    }

    /**
     * @covers Kamereon\Page::get
     */
    public function testGetDefaultCardForSlot()
    {
        $headlineCard = $this->page->get('headline');
        $this->assertEquals('Join our free service today.', $headlineCard);
    }

    /**
     * @covers Kamereon\Page::get
     */
    public function testGetCardForSlotWithArgument()
    {
        $headlineCard = $this->page->get('headline', 1);
        $this->assertEquals('Welcome, valued customer.', $headlineCard);
    }

    /**
     * @covers Kamereon\Page::get
     */
    public function testGetCardForSlotWithHttpGetParameter()
    {
        $request = \Symfony\Component\HttpFoundation\Request::create('?h=3', 'GET');

        $page = new Page(self::$config, $request);
        
        $headlineCard = $page->get('headline');
        $this->assertEquals('Check out our special offers', $headlineCard);
    }


    /**
     * @covers Kamereon\Page::get
     */
    public function testGetCardForSlotWithHttpGetParameterAndArgument()
    {   
        $request = \Symfony\Component\HttpFoundation\Request::create('?h=3', 'GET');
        $page = new Page(self::$config, $request);

        $headlineCard = $page->get('headline', 1);
        $this->assertEquals('Check out our special offers', $headlineCard);
    }

    /**
     * @covers Kamereon\Page::get
     * @covers Kamereon\Page::setRequest
     */
    public function testSetRequest()
    {
        $page = clone $this->page;
        $request = \Symfony\Component\HttpFoundation\Request::create('?h=3', 'GET');

        $page->setRequest($request);

        $headlineCard = $page->get('headline', 1);
        $this->assertEquals('Check out our special offers', $headlineCard);
    }

    /**
     * @covers Kamereon\Page::get
     */
    public function testGetCardForSlotWithHttpGetParametersAndNestedSlots()
    {
        $request = \Symfony\Component\HttpFoundation\Request::create('?h=2&uid=3', 'GET');
        $page = new Page(self::$config, $request);

        $headlineCard = $page->get('headline');
        $this->assertEquals('Welcome back, Brian!', $headlineCard);
    }

    /**
     * @covers Kamereon\Page::getRequest
     */
    public function testGetRequest()
    {
        $request = $this->page->getRequest();

        $this->assertInstanceOf('\Symfony\Component\HttpFoundation\Request', $request);
        // $this->assertTrue($request instanceof \Symfony\Component\HttpFoundation\Request);
    }

    /**
     * @covers Kamereon\Page::offsetGet
     */
    public function testOffsetGet()
    {
        $this->assertInstanceOf('\Kamereon\Slot', $this->page['headline']);
    }

    /**
     * @covers Kamereon\Page::offsetExists
     */
    public function testOffsetExists()
    {
        $this->assertTrue(isset($this->page['headline']));
        $this->assertFalse(isset($this->page['missing']));
    }

    /**
     * @covers Kamereon\Page::offsetExists
     * @expectedException InvalidArgumentException
     */
    public function testGetThrowsException()
    {
        $this->setExpectedException('InvalidArgumentException');

        $fake = $this->page->get('fake');
    }

    /**
     * @covers Kamereon\Page::offsetSet
     */
    public function testOffsetSet()
    {
        $newSlot = new Slot('newslot', array(
            'keyBind' => 'z',
            'cards'   => array('One', 'Two')
        ));
        $page = new Page(self::$config);
        $page['newslot'] = $newSlot;
{'fraction_non_alphanumeric': 0.15907374779763403, 'fraction_numerical': 0.002139441228290964, 'mean_word_length': 2.655473781048758, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 79, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '4122922', 'n_tokens_mistral': 2397, 'n_tokens_neox': 2354, 'n_words': 385}