<commit_before><?php

namespace CamelSpider\Spider;

use Goutte\Client;

class IndexerTest extends \PHPUnit_Framework_TestCase {

    /**
     * @dataProvider providerAuth()
     */
    public function testAuthToArray($auth, $len)
    {
        $spider = new Indexer;
        $auto = 3;
        $this->AssertEquals($len + $auto, count($spider->getAuthCredentials($auth)));
    }


    /**
     * @dataProvider providerAuth()
     */
    public function testLoginForm($auth)
    {
        $spider = new Indexer;
        $credentials = $spider->getAuthCredentials($auth);

        $this->assertArrayHasKey('type', $credentials);

        foreach ($spider->loginFormRequirements() as $r) {
            if (!array_key_exists($r, $credentials)) {
                $this->setExpectedException('Exception');
                $spider->loginForm($credentials);
            }
        }

    }


    /**
     * @dataProvider providerNavegation()
     */
    public function testParameters($host, $paths)
    {

        $client = new Client();

        //Test with absolute path
        foreach ($paths as $path) {
            $crawler = $client->request('GET', 'http://' . $host . $path);
            $server = $client;

            $this->assertEquals(200, $client->getResponse()->getStatus());
            var_dump($client->getRequest()->uri);
  // $this->assertTrue($crawler->statusCode); 
        }


       // $crawler = $client->request('GET', '/tv/noticias/');
       //$headers = $client->getHeaders();
        //var_dump($crawler);
        //
                //var_dump($server['HTTP_REFERER']);
        //var_dump($client->getHistory());

    }

    public function providerNavegation()
    {
        $a = array();

        $a[] = array(
            'host'  =>  'diversao.terra.com.br',
            'paths' =>  array('/', '/tv/')
        );

        return $a;
    }

    public function providerAuth()
    {
        $s = '';
        $i = 0;
        $a = array();
        foreach (array('something', 'button', 'username', 'password', 'expected') as $n) {
            $s .= '"'. $n . '":"' . $n . '"' . "\n";
            $i++;
            $a[] = array($s, $i);
        }
        return $a;
    }
<commit_msg>add unit test, navegation and wrong navegation<commit_after><?php

namespace CamelSpider\Spider;

use Goutte\Client;

class IndexerTest extends \PHPUnit_Framework_TestCase {

    /**
     * @dataProvider providerAuth()
     */
    public function testAuthToArray($auth, $len)
    {
        $spider = new Indexer;
        $auto = 3;
        $this->AssertEquals($len + $auto, count($spider->getAuthCredentials($auth)));
    }


    /**
     * @dataProvider providerAuth()
     */
    public function testLoginForm($auth)
    {
        $spider = new Indexer;
        $credentials = $spider->getAuthCredentials($auth);

        $this->assertArrayHasKey('type', $credentials);

        foreach ($spider->loginFormRequirements() as $r) {
            if (!array_key_exists($r, $credentials)) {
                $this->setExpectedException('Exception');
                $spider->loginForm($credentials);
            }
        }

    }


    /**
     * @dataProvider providerNavegation()
     */
    public function testNavegation($host, $paths)
    {
        $client = new Client();
        //Test with absolute path
        foreach ($paths as $path) {
            $uri = 'http://' . $host . $path;
            $crawler = $client->request('GET', $uri);
            $this->assertEquals(200, $client->getResponse()->getStatus());
            $this->assertEquals($uri, $client->getRequest()->getUri());
        }
        //Test with relative path and get absolute URI
        foreach ($paths as $path) {
            $uri = 'http://' . $host . $path;
            $crawler = $client->request('GET', $path);
            $this->assertEquals(200, $client->getResponse()->getStatus());
            $this->assertEquals($uri, $client->getRequest()->getUri());
        }
    }

    /**
     * @dataProvider providerNavegation()
     */
    public function testWrongNavegation($host, $paths)
    {
        $client = new Client();
        //Test with absolute path
        $uri = 'http://' . $host . '/some' . rand();
        $crawler = $client->request('GET', $uri);
        $this->assertEquals(404, $client->getResponse()->getStatus());
    }

    public function providerNavegation()
    {
        $a = array();

        $a[] = array(
            'host'  =>  'diversao.terra.com.br',
            'paths' =>  array('/', '/tv/')
        );

        $a[] = array(
            'host'  =>  'www.mozilla.org',
            'paths' =>  array('/en-US/firefox/new/', '/en-US/firefox/features/', '/en-US/mobile/faq/')
        );

        return $a;
    }

    public function providerAuth()
    {
        $s = '';
        $i = 0;
        $a = array();
        foreach (array('something', 'button', 'username', 'password', 'expected') as $n) {
            $s .= '"'. $n . '":"' . $n . '"' . "\n";
            $i++;
            $a[] = array($s, $i);
        }
        return $a;
    }

{'fraction_non_alphanumeric': 0.1774129746835443, 'fraction_numerical': 0.0031645569620253164, 'mean_word_length': 1.8963344788087055, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 52, 'https://': 0, 'lorem ipsum': 0, 'www.': 1, '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': '4617221', 'n_tokens_mistral': 1566, 'n_tokens_neox': 1521, 'n_words': 292}