<commit_before><?php

use Mockery as M;

/**
 * Class ExpandLinkTest.
 */
class ExpandLinkTest extends PHPUnit_Framework_TestCase
{
    /**
     * @dataProvider linksProvider
     *
     * @param $expected
     * @param $input
     */
    public function test_expand_expands_single_links($input, $expected)
    {
        $mushroom = new \Mushroom\Mushroom();

        $this->assertEquals($expected, $mushroom->expand($input));
    }

    public function test_expand_expands_array_of_links()
    {
        $links = $this->linksProvider();

        $mushroom = new \Mushroom\Mushroom();

        $inputs = array_map(function ($value) {
            return $value[0];
        }, $links);

        $expected = array_map(function ($value) {
            return $value[1];
        }, $links);

        $this->assertEquals($expected, $mushroom->expand($inputs));
    }

    /**
     * @return array
     */
    public function linksProvider()
    {
        return [
            ['http://bit.ly/1bdDlXc', 'https://www.google.com/?gws_rd=ssl'], // shortened
            ['https://www.google.com/', 'https://www.google.com/'], // nothing
            ['https://jigsaw.w3.org/HTTP/300/301.html', 'https://jigsaw.w3.org/HTTP/300/Overview.html'], // 301 redirect
            ['http://blog.tailwindapp.com/pinterest-smart-feed-pin-visibility/', 'http://blog.tailwindapp.com/pinterest-smart-feed-pin-visibility/'], // trailing slash
            ['http://wp.me//p7gsPW-Gi', 'http://traveltalesoflife.com/2014/06/06/travel-theme-unexpected-the-co-ed-turkish-bath/'],
        ];
    }

    /**
     * @dataProvider canonicalLinksProvider
     *
     * @param $input
     * @param $expected
     */
    public function test_expand_single_canonical_link($input, $expected)
    {
        $mushroom = new \Mushroom\Mushroom();

        $this->assertEquals($expected, $mushroom->canonical($input));
    }

    public function test_expand_multiple_canonical_link()
    {
        $mushroom = new \Mushroom\Mushroom();
        $links    = $this->canonicalLinksProvider();

        $inputs = array_map(function ($value) {
            return $value[0];
        }, $links);

        $expected = array_map(function ($value) {
            return $value[1];
        }, $links);

        $this->assertEquals($expected, $mushroom->canonical($inputs));
    }

    /**
     * @return array
     */
    public function canonicalLinksProvider()
    {
        return [
            ['http://blog.tailwindapp.com/tailwind-publisher-2-0/?foo=foobar', 'http://blog.tailwindapp.com/tailwind-publisher-2-0/'],
            ['http://blog.tailwindapp.com/tailwind-publisher-2-0?foo=foobar', 'http://blog.tailwindapp.com/tailwind-publisher-2-0/'],
            ['http://www.willwashburn.com/?foo', 'http://www.willwashburn.com/?foo'], //no tags
            ['http://www.practicallyfunctional.com/so-creative-18-delicious-game-day-appetizers/', 'http://www.practicallyfunctional.com/so-creative-18-delicious-game-day-appetizers/'], // protocol issues
        ];
    }

    public function test_setting_curl_options_works()
    {

        $expected_curl_opts = [
            CURLOPT_FOLLOWLOCATION => false,
        ];

        $curl
            = M::mock(\WillWashburn\Curl::class)
               ->shouldReceive('curl_init')->getMock()
               ->shouldReceive('curl_exec')->getMock()
               ->shouldReceive('curl_close')->getMock()
               ->shouldReceive('curl_getinfo')->getMock()
               ->shouldReceive('curl_setopt_array')
               ->with(M::any(), M::on(function ($arg) use ($expected_curl_opts) {

                   foreach ( array_keys($expected_curl_opts) as $key ) {

                       if ( $arg[$key] != $expected_curl_opts[$key] ) {
                           return false;
                       }
                   }

                   return true;
               }))
               ->getMock();


        $mushroom = new \Mushroom\Mushroom($curl);

        $mushroom->expand('http://www.foobar.com', ['curl_opts' => $expected_curl_opts]);
    }
}<commit_msg>Applied fixes from StyleCI (#7)<commit_after><?php

use Mockery as M;

/**
 * Class ExpandLinkTest.
 */
class ExpandLinkTest extends PHPUnit_Framework_TestCase
{
    /**
     * @dataProvider linksProvider
     *
     * @param $expected
     * @param $input
     */
    public function test_expand_expands_single_links($input, $expected)
    {
        $mushroom = new \Mushroom\Mushroom();

        $this->assertEquals($expected, $mushroom->expand($input));
    }

    public function test_expand_expands_array_of_links()
    {
        $links = $this->linksProvider();

        $mushroom = new \Mushroom\Mushroom();

        $inputs = array_map(function ($value) {
            return $value[0];
        }, $links);

        $expected = array_map(function ($value) {
            return $value[1];
        }, $links);

        $this->assertEquals($expected, $mushroom->expand($inputs));
    }

    /**
     * @return array
     */
    public function linksProvider()
    {
        return [
            ['http://bit.ly/1bdDlXc', 'https://www.google.com/?gws_rd=ssl'], // shortened
            ['https://www.google.com/', 'https://www.google.com/'], // nothing
            ['https://jigsaw.w3.org/HTTP/300/301.html', 'https://jigsaw.w3.org/HTTP/300/Overview.html'], // 301 redirect
            ['http://blog.tailwindapp.com/pinterest-smart-feed-pin-visibility/', 'http://blog.tailwindapp.com/pinterest-smart-feed-pin-visibility/'], // trailing slash
            ['http://wp.me//p7gsPW-Gi', 'http://traveltalesoflife.com/2014/06/06/travel-theme-unexpected-the-co-ed-turkish-bath/'],
        ];
    }

    /**
     * @dataProvider canonicalLinksProvider
     *
     * @param $input
     * @param $expected
     */
    public function test_expand_single_canonical_link($input, $expected)
    {
        $mushroom = new \Mushroom\Mushroom();

        $this->assertEquals($expected, $mushroom->canonical($input));
    }

    public function test_expand_multiple_canonical_link()
    {
        $mushroom = new \Mushroom\Mushroom();
        $links    = $this->canonicalLinksProvider();

        $inputs = array_map(function ($value) {
            return $value[0];
        }, $links);

        $expected = array_map(function ($value) {
            return $value[1];
        }, $links);

        $this->assertEquals($expected, $mushroom->canonical($inputs));
    }

    /**
     * @return array
     */
    public function canonicalLinksProvider()
    {
        return [
            ['http://blog.tailwindapp.com/tailwind-publisher-2-0/?foo=foobar', 'http://blog.tailwindapp.com/tailwind-publisher-2-0/'],
            ['http://blog.tailwindapp.com/tailwind-publisher-2-0?foo=foobar', 'http://blog.tailwindapp.com/tailwind-publisher-2-0/'],
            ['http://www.willwashburn.com/?foo', 'http://www.willwashburn.com/?foo'], //no tags
            ['http://www.practicallyfunctional.com/so-creative-18-delicious-game-day-appetizers/', 'http://www.practicallyfunctional.com/so-creative-18-delicious-game-day-appetizers/'], // protocol issues
        ];
    }

    public function test_setting_curl_options_works()
    {
        $expected_curl_opts = [
            CURLOPT_FOLLOWLOCATION => false,
        ];

        $curl
            = M::mock(\WillWashburn\Curl::class)
               ->shouldReceive('curl_init')->getMock()
               ->shouldReceive('curl_exec')->getMock()
               ->shouldReceive('curl_close')->getMock()
               ->shouldReceive('curl_getinfo')->getMock()
               ->shouldReceive('curl_setopt_array')
               ->with(M::any(), M::on(function ($arg) use ($expected_curl_opts) {

                   foreach (array_keys($expected_curl_opts) as $key) {
                       if ($arg[$key] != $expected_curl_opts[$key]) {
                           return false;
                       }
                   }

                   return true;
               }))
               ->getMock();

        $mushroom = new \Mushroom\Mushroom($curl);

        $mushroom->expand('http://www.foobar.com', ['curl_opts' => $expected_curl_opts]);
    }
}
{'fraction_non_alphanumeric': 0.16234484453729875, 'fraction_numerical': 0.009954528696079636, 'mean_word_length': 2.1469450889404484, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 51, 'https://': 10, 'lorem ipsum': 0, 'www.': 16, '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': '3594921', 'n_tokens_mistral': 2642, 'n_tokens_neox': 2457, 'n_words': 326}