<commit_before><?php
/**
 * Phergie plugin for providing information about YouTube videos (https://github.com/phergie/phergie-irc-plugin-react-youtube)
 *
 * @link https://github.com/phergie/phergie-irc-plugin-react-youtube for the canonical source repository
 * @copyright Copyright (c) 2008-2014 Phergie Development Team (http://phergie.org)
 * @license http://phergie.org/license Simplified BSD License
 * @package Phergie\Irc\Plugin\React\YouTube
 */

namespace Phergie\Irc\Tests\Plugin\React\YouTube;

use Phake;
use Phergie\Irc\Bot\React\EventQueueInterface as Queue;
use Phergie\Irc\Plugin\React\Command\CommandEvent as Event;
use Phergie\Irc\Plugin\React\YouTube\Plugin;

/**
 * Tests for the Plugin class.
 *
 * @category Phergie
 * @package Phergie\Irc\Plugin\React\YouTube
 */
class PluginTest extends \PHPUnit_Framework_TestCase
{
    /**
     * Mock event emitter
     *
     * @var \Evenement\EventEmitterInterface
     */
    protected $emitter;

    /**
     * Mock logger
     *
     * @var \Psr\Log\LoggerInterface
     */
    protected $logger;

    /**
     * Mock event
     *
     * @var \Phergie\Irc\Event\EventInterface
     */
    protected $event;

    /**
     * Mock event queue
     *
     * @var \Phergie\Irc\Bot\React\EventQueueInterface
     */
    protected $queue;

    /**
     * URL for an API request
     *
     * @var string
     */
    protected $requestUrl = 'https://www.googleapis.com/youtube/v3/videos?id=HFuTvTVAO-M&key=KEY&part=id%2C+snippet%2C+contentDetails%2C+statistics';

    /**
     * Creates mock instances for common parameters.
     */
    protected function setUp()
    {
        $this->event = Phake::mock('\Phergie\Irc\Event\UserEventInterface');
        $this->queue = Phake::mock('\Phergie\Irc\Bot\React\EventQueueInterface');
        $this->emitter = Phake::mock('\Evenement\EventEmitterInterface');
        $this->logger = Phake::mock('\Psr\Log\LoggerInterface');
        $this->plugin = $this->getPlugin();

        date_default_timezone_set('America/Chicago');
    }

    /**
     * Returns a configured instance of the class under test.
     *
     * @param array $config
     * @return \Phergie\Irc\Plugin\React\YouTube\Plugin
     */
    protected function getPlugin(array $config = array())
    {
        $config['key'] = 'KEY';
        $plugin = new Plugin($config);
        $plugin->setEventEmitter($this->emitter);
        $plugin->setLogger($this->logger);
        return $plugin;
    }

    /**
     * Data provider for testInvalidConfiguration().
     *
     * @return array
     */
    public function dataProviderInvalidConfiguration()
    {
        $valid = array('key' => 'KEY');

        $data = array();

        $data[] = array(
            array('key' => 1),
            Plugin::ERR_INVALID_KEY,
        );

        $data[] = array(
            array_merge($valid, array('responseFormat' => 1)),
            Plugin::ERR_INVALID_RESPONSEFORMAT,
        );

        $data[] = array(
            array_merge($valid, array('publishedFormat' => 1)),
            Plugin::ERR_INVALID_PUBLISHEDFORMAT,
        );

        $data[] = array(
            array_merge($valid, array('durationFormat' => 1)),
            Plugin::ERR_INVALID_DURATIONFORMAT,
        );

        return $data;
    }

    /**
     * Tests that an exception is thrown when invalid configuration values are
     * used.
     *
     * @param array $config
     * @param int $error
     * @dataProvider dataProviderInvalidConfiguration
     */
    public function testInvalidConfiguration(array $config, $error)
    {
        try {
            $plugin = new Plugin($config);
        } catch (\DomainException $e) {
            $this->assertSame($error, $e->getCode());
        }
    }

    /**
     * Data provider for testHandleUrl().
     *
     * @return array
     */
    public function dataProviderHandleUrl()
    {
        return array(
            array('http://www.youtube.com/watch?v=HFuTvTVAO-M'),
            array('http://youtube.com/watch?v=HFuTvTVAO-M'),
            array('http://youtu.be/HFuTvTVAO-M'),
        );
    }

    /**
     * Tests handleUrl() with a valid URL for a single video.
     *
     * @param string $url
     * @return array Request configuration, used by other tests<commit_msg>Add test for embed urls<commit_after><?php
/**
 * Phergie plugin for providing information about YouTube videos (https://github.com/phergie/phergie-irc-plugin-react-youtube)
 *
 * @link https://github.com/phergie/phergie-irc-plugin-react-youtube for the canonical source repository
 * @copyright Copyright (c) 2008-2014 Phergie Development Team (http://phergie.org)
 * @license http://phergie.org/license Simplified BSD License
 * @package Phergie\Irc\Plugin\React\YouTube
 */

namespace Phergie\Irc\Tests\Plugin\React\YouTube;

use Phake;
use Phergie\Irc\Bot\React\EventQueueInterface as Queue;
use Phergie\Irc\Plugin\React\Command\CommandEvent as Event;
use Phergie\Irc\Plugin\React\YouTube\Plugin;

/**
 * Tests for the Plugin class.
 *
 * @category Phergie
 * @package Phergie\Irc\Plugin\React\YouTube
 */
class PluginTest extends \PHPUnit_Framework_TestCase
{
    /**
     * Mock event emitter
     *
     * @var \Evenement\EventEmitterInterface
     */
    protected $emitter;

    /**
     * Mock logger
     *
     * @var \Psr\Log\LoggerInterface
     */
    protected $logger;

    /**
     * Mock event
     *
     * @var \Phergie\Irc\Event\EventInterface
     */
    protected $event;

    /**
     * Mock event queue
     *
     * @var \Phergie\Irc\Bot\React\EventQueueInterface
     */
    protected $queue;

    /**
     * URL for an API request
     *
     * @var string
     */
    protected $requestUrl = 'https://www.googleapis.com/youtube/v3/videos?id=HFuTvTVAO-M&key=KEY&part=id%2C+snippet%2C+contentDetails%2C+statistics';

    /**
     * Creates mock instances for common parameters.
     */
    protected function setUp()
    {
        $this->event = Phake::mock('\Phergie\Irc\Event\UserEventInterface');
        $this->queue = Phake::mock('\Phergie\Irc\Bot\React\EventQueueInterface');
        $this->emitter = Phake::mock('\Evenement\EventEmitterInterface');
        $this->logger = Phake::mock('\Psr\Log\LoggerInterface');
        $this->plugin = $this->getPlugin();

        date_default_timezone_set('America/Chicago');
    }

    /**
     * Returns a configured instance of the class under test.
     *
     * @param array $config
     * @return \Phergie\Irc\Plugin\React\YouTube\Plugin
     */
    protected function getPlugin(array $config = array())
    {
        $config['key'] = 'KEY';
        $plugin = new Plugin($config);
        $plugin->setEventEmitter($this->emitter);
        $plugin->setLogger($this->logger);
        return $plugin;
    }

    /**
     * Data provider for testInvalidConfiguration().
     *
     * @return array
     */
    public function dataProviderInvalidConfiguration()
    {
        $valid = array('key' => 'KEY');

        $data = array();

        $data[] = array(
            array('key' => 1),
            Plugin::ERR_INVALID_KEY,
        );

        $data[] = array(
            array_merge($valid, array('responseFormat' => 1)),
            Plugin::ERR_INVALID_RESPONSEFORMAT,
        );

        $data[] = array(
            array_merge($valid, array('publishedFormat' => 1)),
            Plugin::ERR_INVALID_PUBLISHEDFORMAT,
        );

        $data[] = array(
            array_merge($valid, array('durationFormat' => 1)),
            Plugin::ERR_INVALID_DURATIONFORMAT,
        );

        return $data;
    }

    /**
     * Tests that an exception is thrown when invalid configuration values are
     * used.
     *
     * @param array $config
     * @param int $error
     * @dataProvider dataProviderInvalidConfiguration
     */
    public function testInvalidConfiguration(array $config, $error)
    {
        try {
            $plugin = new Plugin($config);
        } catch (\DomainException $e) {
            $this->assertSame($error, $e->getCode());
        }
    }

    /**
     * Data provider for testHandleUrl().
     *
     * @return array
     */
    public function dataProviderHandleUrl()
    {
        return array(
            array('http://www.youtube.com/watch?v=HFuTvTVAO-M'),
            array('https://www.youtube.com/embed/HFuTvTVAO-M'),
            array('https://youtube.com/embed/HFuTvTVAO-M'),
            array('http://youtube.com/watch?v=HFuTvTVAO-M'),
            array('http://youtu.be/HFuTvTVAO-M'),
        );
    }

    /**
     * Tests handleUrl() with a valid URL for a single video.
     *
     * @param string $url
     * @return array Request configuration, used by other tests
{'fraction_non_alphanumeric': 0.13646868500115553, 'fraction_numerical': 0.0036977120406748326, 'mean_word_length': 2.328846153846154, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 37, 'https://': 8, 'lorem ipsum': 0, 'www.': 5, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2841742', 'n_tokens_mistral': 2694, 'n_tokens_neox': 2609, 'n_words': 507}