Exemple #1
0
 public function testGettersAndSetters()
 {
     $tag = new HtmlTag();
     $tag->setTag('a');
     $this->assertEquals('a', $tag->getTag());
     $tag->setId('myid');
     $this->assertEquals('myid', $tag->getId());
     $this->assertFalse($tag->hasAttribute('random'));
     $this->assertEquals('no', $tag->getAttribute('random', 'no'));
     $tag->setAttribute('random', 'test');
     $this->assertTrue($tag->hasAttribute('random'));
     $this->assertEquals('test', $tag->getAttribute('random'));
     $attr = ['test' => 'ran', 'class' => 'test', 'id' => 'four'];
     $tag->setAttributes($attr);
     $this->assertSame($attr, $tag->getAttributes());
     $this->assertEquals('four', $tag->getId());
     $tag->setContent('testing');
     $this->assertEquals('testing', $tag->getContent(false));
     $this->assertEquals(['testing'], $tag->getContent());
     $tag->appendContent('content');
     $this->assertEquals(['testing', 'content'], $tag->getContent());
     $this->assertEquals('testingcontent', $tag->getContent(false));
     $tag->setContent('testing');
     $tag->prependContent('content');
     $this->assertEquals(['content', 'testing'], $tag->getContent());
     $this->assertEquals('contenttesting', $tag->getContent(false));
     $tag->removeAttribute('class');
     $this->assertFalse($tag->hasClass('red'));
     $tag->addClass('red');
     $this->assertTrue($tag->hasClass('red'));
     $this->assertEquals(['red' => 'red'], $tag->getClasses());
     $tag->removeClass('red');
     $this->assertFalse($tag->hasClass('red'));
     $tag->addClass('red', 'blue', ['green', 'yellow'], 'orange');
     $this->assertTrue($tag->hasClass('yellow'));
     $this->assertTrue($tag->hasClass('blue'));
     $this->assertTrue($tag->hasClass('green'));
     $this->assertTrue($tag->hasClass('red'));
     $this->assertTrue($tag->hasClass('orange'));
     $tag->removeClass('yellow', ['blue', 'green'], 'red');
     $this->assertFalse($tag->hasClass('yellow'));
     $this->assertFalse($tag->hasClass('blue'));
     $this->assertFalse($tag->hasClass('green'));
     $this->assertFalse($tag->hasClass('red'));
     $this->assertTrue($tag->hasClass('orange'));
 }