<commit_before><?php
/**
 * @copyright	Copyright 2006-2013, <NAME> - http://milesj.me
 * @license		http://opensource.org/licenses/mit-license.php - Licensed under the MIT License
 * @link		http://milesj.me/code/php/decoda
 */

namespace Decoda\Hook;

use Decoda\Decoda;
use Decoda\Filter\ImageFilter;
use Decoda\Hook\EmoticonHook;
use Decoda\Test\TestCase;

class EmoticonHookTest extends TestCase {

	/**
	 * Set up Decoda.
	 */
	protected function setUp() {
		parent::setUp();

		$decoda = new Decoda();
		$decoda->addFilter(new ImageFilter());

		$this->object = new EmoticonHook();
		$this->object->setParser($decoda);
		$this->object->startup();
	}

	/**
	 * Test smiley detection according to the positioning.
	 *
	 * @dataProvider getSmileyDetectionData
	 */
	public function testSmileyDetection($value, $expected) {
		$this->assertEquals($expected, $this->object->beforeParse($value));
	}

	public function getSmileyDetectionData() {
		return array(
			array(':/ at the beginning', '<img src="/images/hm.png" alt=""> at the beginning'),
			array('Smiley at the end :O', 'Smiley at the end <img src="/images/gah.png" alt="">'),
			array('Smiley in the middle :P of a string', 'Smiley in the middle <img src="/images/tongue.png" alt=""> of a string'),
			array(':):):)', ':):):)'),
			array('At the :)start of the word', 'At the :)start of the word'),
			array('At the mid:)dle of the word', 'At the mid:)dle of the word'),
			array('At the end:) of the word', 'At the end:) of the word'),
			array('http://', 'http://'),
		);
	}

	/**
	 * Test that smiley faces are converted to emoticon images.
	 *
	 * @dataProvider getSmileyConversionData
	 */
	public function testSmileyConversion($value, $expected) {
		$this->assertEquals($expected, $this->object->beforeParse($value));
	}

	public function getSmileyConversionData() {
		$decoda = new Decoda();
		$hook = new EmoticonHook();
		$hook->setParser($decoda);
		$hook->startup();

		$datas = array();
		foreach ($hook->getSmilies() as $smile) {
			$datas[] = array($smile, $hook->render($smile, $decoda->getConfig('xhtmlOutput')));
		}

		return $datas;
	}
}<commit_msg>Add some tests<commit_after><?php
/**
 * @copyright	Copyright 2006-2013, <NAME> - http://milesj.me
 * @license		http://opensource.org/licenses/mit-license.php - Licensed under the MIT License
 * @link		http://milesj.me/code/php/decoda
 */

namespace Decoda\Hook;

use Decoda\Decoda;
use Decoda\Filter\ImageFilter;
use Decoda\Hook\EmoticonHook;
use Decoda\Test\TestCase;

class EmoticonHookTest extends TestCase {

	/**
	 * Set up Decoda.
	 */
	protected function setUp() {
		parent::setUp();

		$decoda = new Decoda();
		$decoda->addFilter(new ImageFilter());

		$this->object = new EmoticonHook();
		$this->object->setParser($decoda);
		$this->object->startup();
	}

	/**
	 * Test smiley detection according to the positioning.
	 *
	 * @dataProvider getSmileyDetectionData
	 */
	public function testSmileyDetection($value, $expected) {
		$this->assertEquals($expected, $this->object->beforeParse($value));
	}

	public function getSmileyDetectionData() {
		return array(
			array(':/ at the beginning', '<img src="/images/hm.png" alt=""> at the beginning'),
			array('Smiley at the end :O', 'Smiley at the end <img src="/images/gah.png" alt="">'),
			array('Smiley in the middle :P of a string', 'Smiley in the middle <img src="/images/tongue.png" alt=""> of a string'),
			array(':):):)', ':):):)'),
			array('At the :)start of the word', 'At the :)start of the word'),
			array('At the mid:)dle of the word', 'At the mid:)dle of the word'),
			array('At the end:) of the word', 'At the end:) of the word'),
			array('http://', 'http://'),
			array('With a :/'."\n". ' linefeed', 'With a <img src="/images/hm.png" alt="">'."\n". ' linefeed'),
			array('With a :/'."\r". ' carriage return', 'With a <img src="/images/hm.png" alt="">'."\r". ' carriage return'),
			array('With a :/'."\t". ' tab', 'With a <img src="/images/hm.png" alt="">'."\t". ' tab'),
			array(':/ :/', '<img src="/images/hm.png" alt=""> <img src="/images/hm.png" alt="">'),
			array(' :/ :/ ', ' <img src="/images/hm.png" alt=""> <img src="/images/hm.png" alt=""> '),
			array(' :/ :/ :/ ', ' <img src="/images/hm.png" alt=""> <img src="/images/hm.png" alt=""> <img src="/images/hm.png" alt=""> '),
		);
	}

	/**
	 * Test that smiley faces are converted to emoticon images.
	 *
	 * @dataProvider getSmileyConversionData
	 */
	public function testSmileyConversion($value, $expected) {
		$this->assertEquals($expected, $this->object->beforeParse($value));
	}

	public function getSmileyConversionData() {
		$decoda = new Decoda();
		$hook = new EmoticonHook();
		$hook->setParser($decoda);
		$hook->startup();

		$datas = array();
		foreach ($hook->getSmilies() as $smile) {
			$datas[] = array($smile, $hook->render($smile, $decoda->getConfig('xhtmlOutput')));
		}

		return $datas;
	}
}
{'fraction_non_alphanumeric': 0.20069629326233873, 'fraction_numerical': 0.0032766741757116525, 'mean_word_length': 4.029866117404738, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 55, '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': '960979', 'n_tokens_mistral': 1807, 'n_tokens_neox': 1623, 'n_words': 428}