<commit_before><?php

namespace Jadu\Pulsar\Twig\Extension;

class AttributeParserExtensionTest extends \PHPUnit_Framework_TestCase
{
	public function setUp()
	{
		$this->ext = new AttributeParserExtension(array());
	}

	public function testGetName()
	{
		$this->assertEquals('attribute_parser_extension', $this->ext->getName());
	}

	public function testParseAttributesReturnsFalseIfNoAttributesSupplied()
	{
		$tests = array('', false, null, array());
		foreach ($tests as $test) {
			$this->assertEquals(false, $this->ext->parseAttributes($test));
		}
	}

	public function testParseAttributesReturnsFalseIfEmptyStringSupplied()
	{
		$this->assertEquals(false, $this->ext->parseAttributes(''));
	}

	public function testParseAttributesReturnsFalseIfEmptyArraySupplied()
	{
		$this->assertEquals(false, $this->ext->parseAttributes([]));
	}

	public function testParseAttributesParsesSingleAttribute()
	{
		$dataIn = array('slim' => 'shady');
		$dataOut = 'slim="shady"';
		$this->assertEquals($dataOut, $this->ext->parseAttributes($dataIn));
	}

	public function testParseAttributesParsesMultipleAttributes()
	{
		$dataIn = array('slim' => 'shady', 'marshall' => 'mathers', 'eminem' => true);
		$dataOut = 'slim="shady" marshall="mathers" eminem="1"';
		$this->assertEquals($dataOut, $this->ext->parseAttributes($dataIn));
	}

	public function testParseAttributesEscapesDoubleQuotes()
	{
		$dataIn = array('foo' => 'bar"baz');
		$dataOut = 'foo="bar&quot;baz"';
		$this->assertEquals($dataOut, $this->ext->parseAttributes($dataIn));
	}

	public function testParseAttributesConvertsHtmlEntities()
	{
		$dataIn = array('foo' => '<span>bar</span> <blink>baz</blink>');
		$dataOut = 'foo="&lt;span&gt;bar&lt;/span&gt; &lt;blink&gt;baz&lt;/blink&gt;"';
		$this->assertEquals($dataOut, $this->ext->parseAttributes($dataIn));
	}

	public function testParseAttributesRemovesAttributeWithEmptyValues()
	{
		$dataIn = array('foo' => '');
		$dataOut = '';
		$this->assertEquals($dataOut, $this->ext->parseAttributes($dataIn));
	}


}
<commit_msg>Test to make sure attribute parser removes attributes with empty values<commit_after><?php

namespace Jadu\Pulsar\Twig\Extension;

class AttributeParserExtensionTest extends \PHPUnit_Framework_TestCase
{
	public function setUp()
	{
		$this->ext = new AttributeParserExtension(array());
	}

	public function testGetName()
	{
		$this->assertEquals('attribute_parser_extension', $this->ext->getName());
	}

	public function testParseAttributesReturnsFalseIfNoAttributesSupplied()
	{
		$tests = array('', false, null, array());
		foreach ($tests as $test) {
			$this->assertEquals(false, $this->ext->parseAttributes($test));
		}
	}

	public function testParseAttributesReturnsFalseIfEmptyStringSupplied()
	{
		$this->assertEquals(false, $this->ext->parseAttributes(''));
	}

	public function testParseAttributesReturnsFalseIfEmptyArraySupplied()
	{
		$this->assertEquals(false, $this->ext->parseAttributes([]));
	}

	public function testParseAttributesParsesSingleAttribute()
	{
		$dataIn = array('slim' => 'shady');
		$dataOut = 'slim="shady"';
		$this->assertEquals($dataOut, $this->ext->parseAttributes($dataIn));
	}

	public function testParseAttributesParsesMultipleAttributes()
	{
		$dataIn = array('slim' => 'shady', 'marshall' => 'mathers', 'eminem' => true);
		$dataOut = 'slim="shady" marshall="mathers" eminem="1"';
		$this->assertEquals($dataOut, $this->ext->parseAttributes($dataIn));
	}

	public function testParseAttributesEscapesDoubleQuotes()
	{
		$dataIn = array('foo' => 'bar"baz');
		$dataOut = 'foo="bar&quot;baz"';
		$this->assertEquals($dataOut, $this->ext->parseAttributes($dataIn));
	}

	public function testParseAttributesConvertsHtmlEntities()
	{
		$dataIn = array('foo' => '<span>bar</span> <blink>baz</blink>');
		$dataOut = 'foo="&lt;span&gt;bar&lt;/span&gt; &lt;blink&gt;baz&lt;/blink&gt;"';
		$this->assertEquals($dataOut, $this->ext->parseAttributes($dataIn));
	}

	public function testParseAttributesRemovesAttributeWithEmptyValues()
	{
		$dataIn = array('foo' => '');
		$dataOut = '';
		$this->assertEquals($dataOut, $this->ext->parseAttributes($dataIn));
	}

	public function testParseAttributesRemovesAttributesWithNullValues()
	{
		$dataIn = array('foo' => null);
		$dataOut = '';
		$this->assertEquals($dataOut, $this->ext->parseAttributes($dataIn));
	}

	public function testParseAttributesRemovesAttributesWithFalseValues()
	{
		$dataIn = array('foo' => false);
		$dataOut = '';
		$this->assertEquals($dataOut, $this->ext->parseAttributes($dataIn));
	}


}

{'fraction_non_alphanumeric': 0.17527593818984546, 'fraction_numerical': 0.0004415011037527594, 'mean_word_length': 6.489256198347108, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 89, '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': '2654750', 'n_tokens_mistral': 1540, 'n_tokens_neox': 1458, 'n_words': 224}