<commit_before><?php

namespace OOUI\Tests;

use OOUI\Tag;

class TagTest extends \PHPUnit\Framework\TestCase {

	/**
	 * @covers Tag::__construct
	 */
	public function testConstructor() {
		$this->assertInstanceOf( 'OOUI\Tag', new Tag() );
		$this->assertInstanceOf( 'OOUI\Tag', new Tag( 'input' ) );
	}

	/**
	 * @covers Tag::addClasses
	 * @covers Tag::removeClasses
	 * @covers Tag::hasClass
	 */
	public function testClasses() {
		$tag = ( new Tag() )->addClasses( [ 'class1', 'class2' ] );
		$this->assertTrue( $tag->hasClass( 'class1' ) );
		$this->assertTrue( $tag->hasClass( 'class2' ) );
		$tag->removeClasses( [ 'class1' ] );
		$this->assertFalse( $tag->hasClass( 'class1' ) );
		$this->assertTrue( $tag->hasClass( 'class2' ) );
	}

	/**
	 * @covers Tag::appendContent
	 * @covers Tag::prependContent
	 * @covers Tag::clearContent
	 */
	public function testContent() {
		$content = new \ReflectionProperty( 'OOUI\Tag', 'content' );
		$content->setAccessible( true );
		$tag = new Tag( 'div' );
		$aTag = new Tag( 'a' );
		$bTag = new Tag( 'b' );
		$cTag = new Tag( 'c' );

		$tag->appendContent( 'a' );
		$this->assertEquals( [ 'a' ], $content->getValue( $tag ) );
		$tag->clearContent();
		$this->assertEquals( [], $content->getValue( $tag ) );

		$tag->appendContent( [ 'a', 'b' ] );
		$this->assertEquals( [ 'a', 'b' ], $content->getValue( $tag ) );
		// Strings can be duplicated
		$tag->appendContent( [ 'b', 'a' ] );
		$this->assertEquals( [ 'a', 'b', 'b', 'a' ], $content->getValue( $tag ) );
		$tag->clearContent();

		$tag->appendContent( 'a', 'b' );
		$this->assertEquals( [ 'a', 'b' ], $content->getValue( $tag ) );
		$tag->clearContent();

		$tag->appendContent( 'a' );
		$tag->appendContent( 'b' );
		$this->assertEquals( [ 'a', 'b' ], $content->getValue( $tag ) );
		$tag->clearContent();

		$tag->prependContent( [ 'a', 'b' ] );
		$this->assertEquals( [ 'a', 'b' ], $content->getValue( $tag ) );
		$tag->clearContent();

		$tag->prependContent( 'a', 'b' );
		$this->assertEquals( [ 'a', 'b' ], $content->getValue( $tag ) );
		$tag->clearContent();

		$tag->prependContent( 'a' );
		$tag->prependContent( 'b' );
		$this->assertEquals( [ 'b', 'a' ], $content->getValue( $tag ) );
		$tag->clearContent();

		// Tags can't be duplicated
		$tag->appendContent( [ $aTag, $bTag ] );
		$tag->appendContent( [ $bTag, $cTag ] );
		$this->assertEquals( [ $aTag, $bTag, $cTag ], $content->getValue( $tag ) );
		$tag->clearContent();

		$tag->prependContent( [ $aTag, $bTag ] );
		$tag->prependContent( [ $bTag, $cTag ] );
		$this->assertEquals( [ $bTag, $cTag, $aTag ], $content->getValue( $tag ) );
		$tag->clearContent();

		// Tags aren't compared with strings
		$tag->appendContent( '<a></a>' );
		$tag->appendContent( $aTag );
		$this->assertEquals( [ '<a></a>', $aTag ], $content->getValue( $tag ) );
		$tag->clearContent();

		// Good practice for variable-length argument lists to support being empty as well
		$tag->appendContent();
		$tag->prependContent();
	}

	/**
	 * @covers Tag::appendContent
	 * @covers Tag::prependContent
	 * @covers Tag::removeContent
	 */
	public function testVariadicContentMethods() {
		$tag = new Tag();
		$empty = [];

		$tag->appendContent( $empty );
		$tag->appendContent( ...$empty );
		$tag->prependContent( $empty );
		$tag->prependContent( ...$empty );
		$tag->removeContent( $empty );
		$tag->removeContent( ...$empty );

		// What we really care about is that the calls above don't fail
		$this->assertSame( '<div></div>', $tag->toString() );
	}

	/**
	 * @covers Tag::setAttributes
	 * @covers Tag::getAttribute<commit_msg>Document inconsistent Tag methods with PHPUnit tests<commit_after><?php

namespace OOUI\Tests;

use OOUI\Tag;

class TagTest extends \PHPUnit\Framework\TestCase {

	/**
	 * @covers Tag::__construct
	 */
	public function testConstructor() {
		$this->assertInstanceOf( 'OOUI\Tag', new Tag() );
		$this->assertInstanceOf( 'OOUI\Tag', new Tag( 'input' ) );
	}

	/**
	 * @covers Tag::addClasses
	 * @covers Tag::removeClasses
	 * @covers Tag::hasClass
	 */
	public function testClasses() {
		$tag = ( new Tag() )->addClasses( [ 'class1', 'class2' ] );
		$this->assertTrue( $tag->hasClass( 'class1' ) );
		$this->assertTrue( $tag->hasClass( 'class2' ) );
		$tag->removeClasses( [ 'class1' ] );
		$this->assertFalse( $tag->hasClass( 'class1' ) );
		$this->assertTrue( $tag->hasClass( 'class2' ) );
	}

	/**
	 * @covers Tag::appendContent
	 * @covers Tag::prependContent
	 * @covers Tag::clearContent
	 */
	public function testContent() {
		$content = new \ReflectionProperty( 'OOUI\Tag', 'content' );
		$content->setAccessible( true );
		$tag = new Tag( 'div' );
		$aTag = new Tag( 'a' );
		$bTag = new Tag( 'b' );
		$cTag = new Tag( 'c' );

		$tag->appendContent( 'a' );
		$this->assertEquals( [ 'a' ], $content->getValue( $tag ) );
		$tag->clearContent();
		$this->assertEquals( [], $content->getValue( $tag ) );

		$tag->appendContent( [ 'a', 'b' ] );
		$this->assertEquals( [ 'a', 'b' ], $content->getValue( $tag ) );
		// Strings can be duplicated
		$tag->appendContent( [ 'b', 'a' ] );
		$this->assertEquals( [ 'a', 'b', 'b', 'a' ], $content->getValue( $tag ) );
		$tag->clearContent();

		$tag->appendContent( 'a', 'b' );
		$this->assertEquals( [ 'a', 'b' ], $content->getValue( $tag ) );
		$tag->clearContent();

		$tag->appendContent( 'a' );
		$tag->appendContent( 'b' );
		$this->assertEquals( [ 'a', 'b' ], $content->getValue( $tag ) );
		$tag->clearContent();

		$tag->prependContent( [ 'a', 'b' ] );
		$this->assertEquals( [ 'a', 'b' ], $content->getValue( $tag ) );
		$tag->clearContent();

		$tag->prependContent( 'a', 'b' );
		$this->assertEquals( [ 'a', 'b' ], $content->getValue( $tag ) );
		$tag->clearContent();

		$tag->prependContent( 'a' );
		$tag->prependContent( 'b' );
		$this->assertEquals( [ 'b', 'a' ], $content->getValue( $tag ) );
		$tag->clearContent();

		// Tags can't be duplicated
		$tag->appendContent( [ $aTag, $bTag ] );
		$tag->appendContent( [ $bTag, $cTag ] );
		$this->assertEquals( [ $aTag, $bTag, $cTag ], $content->getValue( $tag ) );
		$tag->clearContent();

		$tag->prependContent( [ $aTag, $bTag ] );
		$tag->prependContent( [ $bTag, $cTag ] );
		$this->assertEquals( [ $bTag, $cTag, $aTag ], $content->getValue( $tag ) );
		$tag->clearContent();

		// Tags aren't compared with strings
		$tag->appendContent( '<a></a>' );
		$tag->appendContent( $aTag );
		$this->assertEquals( [ '<a></a>', $aTag ], $content->getValue( $tag ) );
		$tag->clearContent();

		// Good practice for variable-length argument lists to support being empty as well
		$tag->appendContent();
		$tag->prependContent();
	}

	/**
	 * @covers Tag::appendContent
	 * @covers Tag::prependContent
	 * @covers Tag::removeContent
	 */
	public function testVariadicContentMethods() {
		$tag = new Tag();
		$empty = [];

		$tag->appendContent( $empty );
		$tag->appendContent( ...$empty );
		$tag->prependContent( $empty );
		$tag->prependContent( ...$empty );
		$tag->removeContent( $empty );
		$tag->removeContent( ...$empty );

		// What we really care about is that the calls above don't fail
		$this->assertSame( '<div></div>', $tag->toString() );
	}

	/**
	 * @covers Tag::appendContent
	 */
	public function testAppendContentWithArrayKeys() {
		$tag = new Tag();
		// FIXME: The behavior of appendContent() and prependContent() is not consistent
		$this->expectError();
		$tag->appendContent( [ 'foo' => 'bar' ] );
	}

	/**
	 * @covers Tag::prependContent
	 */
	public function testPrependContentWithArrayKeys() {
		$tag = new Tag();
		// FIXME: The behavior of appendContent() and prependContent() is not consistent
		$tag->prependContent( [ 'foo' => 'bar' ] );
		$this->assertSame( '<div>bar</div>', $tag->toString() );
	}

	/**
	 * @covers Tag::setAttributes
	 * @covers Tag::getAttribute
{'fraction_non_alphanumeric': 0.22506098343818204, 'fraction_numerical': 0.0017974065990499421, 'mean_word_length': 3.89937106918239, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 170, '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': '2819408', 'n_tokens_mistral': 2945, 'n_tokens_neox': 2736, 'n_words': 585}