basePath = dirname(__FILE__) . '/_files/modules';
$this->helper = new Zend_View_Helper_HeadStyle();
}
/**
* Tears down the fixture, for example, close a network connection.
* This method is called after a test is executed.
*
* @return void
*/
public function tearDown()
{
unset($this->helper);
}
public function testNamespaceRegisteredInPlaceholderRegistryAfterInstantiation()
{
$registry = Zend_View_Helper_Placeholder_Registry::getRegistry();
if ($registry->containerExists('Zend_View_Helper_HeadStyle')) {
$registry->deleteContainer('Zend_View_Helper_HeadStyle');
}
$this->assertFalse($registry->containerExists('Zend_View_Helper_HeadStyle'));
$helper = new Zend_View_Helper_HeadStyle();
$this->assertTrue($registry->containerExists('Zend_View_Helper_HeadStyle'));
}
public function testHeadStyleReturnsObjectInstance()
{
$placeholder = $this->helper->headStyle();
$this->assertTrue($placeholder instanceof Zend_View_Helper_HeadStyle);
}
public function testAppendPrependAndSetThrowExceptionsWhenNonStyleValueProvided()
{
try {
$this->helper->append('foo');
$this->fail('Non-style value should not append');
} catch (Zend_View_Exception $e) { }
try {
$this->helper->offsetSet(5, 'foo');
$this->fail('Non-style value should not offsetSet');
} catch (Zend_View_Exception $e) { }
try {
$this->helper->prepend('foo');
$this->fail('Non-style value should not prepend');
} catch (Zend_View_Exception $e) { }
try {
$this->helper->set('foo');
$this->fail('Non-style value should not set');
} catch (Zend_View_Exception $e) { }
}
public function testOverloadAppendStyleAppendsStyleToStack()
{
$string = 'a {}';
for ($i = 0; $i < 3; ++$i) {
$string .= PHP_EOL . 'a {}';
$this->helper->appendStyle($string);
$values = $this->helper->getArrayCopy();
$this->assertEquals($i + 1, count($values));
$item = $values[$i];
$this->assertTrue($item instanceof stdClass);
$this->assertObjectHasAttribute('content', $item);
$this->assertObjectHasAttribute('attributes', $item);
$this->assertEquals($string, $item->content);
}
}
public function testOverloadPrependStylePrependsStyleToStack()
{
$string = 'a {}';
for ($i = 0; $i < 3; ++$i) {
$string .= PHP_EOL . 'a {}';
$this->helper->prependStyle($string);
$values = $this->helper->getArrayCopy();
$this->assertEquals($i + 1, count($values));
$item = array_shift($values);
$this->assertTrue($item instanceof stdClass);
$this->assertObjectHasAttribute('content', $item);
$this->assertObjectHasAttribute('attributes', $item);
$this->assertEquals($string, $item->content);
}
}
public function testOverloadSetOversitesStack()
{
$string = 'a {}';
for ($i = 0; $i < 3; ++$i) {
$this->helper->appendStyle($string);
$string .= PHP_EOL . 'a {}';
}
$this->helper->setStyle($string);
$values = $this->helper->getArrayCopy();
$this->assertEquals(1, count($values));
$item = array_shift($values);
$this->assertTrue($item instanceof stdClass);
$this->assertObjectHasAttribute('content', $item);
$this->assertObjectHasAttribute('attributes', $item);
$this->assertEquals($string, $item->content);
}
public function testCanBuildStyleTagsWithAttributes()
{
$this->helper->setStyle('a {}', array(
'lang' => 'us_en',
'title' => 'foo',
'media' => 'projection',
'dir' => 'rtol',
'bogus' => 'unused'
));
$value = $this->helper->getValue();
$this->assertObjectHasAttribute('attributes', $value);
$attributes = $value->attributes;
$this->assertTrue(isset($attributes['lang']));
$this->assertTrue(isset($attributes['title']));
$this->assertTrue(isset($attributes['media']));
$this->assertTrue(isset($attributes['dir']));
$this->assertTrue(isset($attributes['bogus']));
$this->assertEquals('us_en', $attributes['lang']);
$this->assertEquals('foo', $attributes['title']);
$this->assertEquals('projection', $attributes['media']);
$this->assertEquals('rtol', $attributes['dir']);
$this->assertEquals('unused', $attributes['bogus']);
}
public function testRenderedStyleTagsContainHtmlEscaping()
{
$this->helper->setStyle('a {}', array(
'lang' => 'us_en',
'title' => 'foo',
'media' => 'screen',
'dir' => 'rtol',
'bogus' => 'unused'
));
$value = $this->helper->toString();
$this->assertContains('', $value);
}
public function testRenderedStyleTagsContainsDefaultMedia()
{
$this->helper->setStyle('a {}', array(
));
$value = $this->helper->toString();
$this->assertRegexp('#');
$this->assertEquals(3, $styles);
$this->assertContains($style3, $html);
$this->assertContains($style2, $html);
$this->assertContains($style1, $html);
}
public function testCapturingCapturesToObject()
{
$this->helper->captureStart();
echo 'foobar';
$this->helper->captureEnd();
$values = $this->helper->getArrayCopy();
$this->assertEquals(1, count($values));
$item = array_shift($values);
$this->assertContains('foobar', $item->content);
}
public function testOverloadingOffsetSetWritesToSpecifiedIndex()
{
$this->helper->offsetSetStyle(100, 'foobar');
$values = $this->helper->getArrayCopy();
$this->assertEquals(1, count($values));
$this->assertTrue(isset($values[100]));
$item = $values[100];
$this->assertContains('foobar', $item->content);
}
public function testInvalidMethodRaisesException()
{
try {
$this->helper->bogusMethod();
$this->fail('Invalid method should raise exception');
} catch (Zend_View_Exception $e) { }
}
public function testTooFewArgumentsRaisesException()
{
try {
$this->helper->appendStyle();
$this->fail('Too few arguments should raise exception');
} catch (Zend_View_Exception $e) { }
}
public function testIndentationIsHonored()
{
$this->helper->setIndent(4);
$this->helper->appendStyle('
a {
display: none;
}');
$this->helper->appendStyle('
h1 {
font-weight: bold
}');
$string = $this->helper->toString();
$scripts = substr_count($string, '
';
$this->assertEquals($expected, $test);
}
}
// Call Zend_View_Helper_HeadStyleTest::main() if this source file is executed directly.
if (PHPUnit_MAIN_METHOD == "Zend_View_Helper_HeadStyleTest::main") {
Zend_View_Helper_HeadStyleTest::main();
}