Skip to content
This repository has been archived by the owner on Nov 26, 2017. It is now read-only.

Commit

Permalink
few tests for JDocumentHtml
Browse files Browse the repository at this point in the history
  • Loading branch information
Piotr committed Mar 5, 2013
1 parent 479d416 commit 1537938
Showing 1 changed file with 200 additions and 27 deletions.
227 changes: 200 additions & 27 deletions tests/suites/unit/joomla/document/html/JDocumentHTMLTest.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -38,33 +38,136 @@ protected function setUp()
} }


/** /**
* Test getHeadData * Tears down the fixture, for example, closes a network connection.
* This method is called after a test is executed.
* *
* @todo Implement testGetHeadData(). * @access protected
* *
* @return void * @return void
*/ */
public function testGetHeadData() protected function tearDown()
{ {
// Remove the following lines when you implement this test. }
$this->markTestIncomplete(
'This test has not been implemented yet.' /**
* Terst construct
*
* @covers JDocumentHtml::__construct
*
* @return void
*/
public function test__construct($options = array())
{
$documentHtml = new JDocumentHtml;

$this->assertThat(
$documentHtml->_mime,
$this->equalTo('text/html'),
'JDocumentHtml::__construct: Default Mime does not match'
);

$this->assertThat(
$documentHtml->_type,
$this->equalTo('html'),
'JDocumentHtml::__construct: Default Type does not match'
); );
} }


/** /**
* Test... * Test getHeadData
* *
* @todo Implement testSetHeadData(). * @covers JDocumentHtml::setHeadData
* @covers JDocumentHtml::getHeadData
* *
* @return void * @return void
*/ */
public function testSetHeadData() public function testSetAndGetHeadData()
{ {
// Remove the following lines when you implement this test.
$this->markTestIncomplete( // Get default values
'This test has not been implemented yet.' $default = $this->object->getHeadData();

// Test invalid data
$return = $this->object->setHeadData('invalid');

$this->assertThat(
$this->object->getHeadData(),
$this->equalTo($default),
'JDocumentHtml::setHeadData invalid data allowed to be set'
); );

// Test return value
$this->assertThat(
$return,
$this->isNull(),
'JDocumentHtml::setHeadData did not return null'
);

// Test setting/ getting values
$test_data = array(
'title' => 'My Custom Title',
'description' => 'My Description',
'link' => 'http://joomla.org',
'metaTags' => array(
'myMetaTag' => 'myMetaContent'
),
'links' => array(
'index.php' => array(
'relation' => 'Start',
'relType' => 'rel',
'attribs' => array()
)
),
'styleSheets' => array(
'test.css' => array(
'mime' => 'text/css',
'media' => null,
'attribs' => array()
)
),
'style' => array(
'text/css' => 'body { background: white; }'
),
'scripts' => array(
'test.js' => array(
'mime' => 'text/javascript',
'defer' => false,
'async' => false
)
),
'script' => array(
'text/javascript' => "window.addEvent('load', function() { new JCaption('img.caption'); });"
),
'custom' => array(
"<script>var html5 = true;</script>"
)
);

foreach ($test_data as $dataKey => $dataValue)
{
// Set
$return = $this->object->setHeadData(array($dataKey => $dataValue));

// Get
$compareTo = $this->object->getHeadData();

// Assert
$this->assertThat(
$compareTo[$dataKey],
$this->equalTo($dataValue),
'JDocumentHtml::setHeadData did not return ' . $dataKey . ' properly or setHeadData with ' . $dataKey . ' did not work'
);

// Test return value
$this->assertThat(
$return,
$this->equalTo($this->object),
'JDocumentHtml::setHeadData did not return JDocumentHtml instance'
);
}


// Could use native methods (JDocument::addStyleSheet, etc) like $this->mergeHeadData
} }


/** /**
Expand All @@ -85,45 +188,115 @@ public function testMergeHeadData()
/** /**
* Test... * Test...
* *
* @todo Implement testAddHeadLink(). * @covers JDocumentHtml::addHeadLink
* *
* @return void * @return void
*
* @note MDC: <link> https://developer.mozilla.org/en-US/docs/HTML/Element/link
*/ */
public function testAddHeadLink() public function testAddHeadLink()
{ {
// Remove the following lines when you implement this test. // Simple
$this->markTestIncomplete( $this->object->addHeadLink('index.php', 'Start');
'This test has not been implemented yet.'
$this->assertThat(
$this->object->_links['index.php'],
$this->equalTo(array('relation' => 'Start', 'relType' => 'rel', 'attribs' => array())),
'addHeadLink did not work'
);

// RSS
$link = '&format=feed&limitstart=';
$attribs = array('type' => 'application/rss+xml', 'title' => 'RSS 2.0');

$this->object->addHeadLink($link, 'alternate', 'rel', $attribs);

$this->assertThat(
$this->object->_links[$link],
$this->equalTo(array('relation' => 'alternate', 'relType' => 'rel', 'attribs' => $attribs)),
'JDocumentHtml::addHeadLink did not work for RSS'
); );
} }


/** /**
* Test... * Test...
* *
* @todo Implement testAddFavicon(). * @covers JDocumentHtml::addFavicon
* *
* @return void * @return void
*/ */
public function testAddFavicon() public function testAddFavicon()
{ {
// Remove the following lines when you implement this test. $this->object->addFavicon('templates\protostar\favicon.ico');
$this->markTestIncomplete(
'This test has not been implemented yet.' $this->assertThat(
$this->object->_links['templates/protostar/favicon.ico'],
$this->equalTo(array('relation' => 'shortcut icon', 'relType' => 'rel', 'attribs' => array('type' => 'image/vnd.microsoft.icon'))),
'JDocumentHtml::addFavicon did not work'
);

$this->object->addFavicon('favicon.gif', null);

$this->assertThat(
$this->object->_links['favicon.gif'],
$this->equalTo(array('relation' => 'shortcut icon', 'relType' => 'rel', 'attribs' => array('type' => null))),
'JDocumentHtml::addFavicon did not work'
); );
} }


/** /**
* Test... * Test...
* *
* @todo Implement testAddCustomTag(). * @covers JDocumentHtml::addCustomTag
* *
* @return void * @return void
*/ */
public function testAddCustomTag() public function testAddCustomTag()
{ {
// Remove the following lines when you implement this test. $this->object->addCustomTag("\t <script>var html5 = true;</script>\r\n");
$this->markTestIncomplete(
'This test has not been implemented yet.' $this->assertThat(
in_array('<script>var html5 = true;</script>', $this->object->_custom),
$this->isTrue(),
'JDocumentHtml::addCustomTag did not work'
);
}

/**
* We test both at once
*
* @covers JDocumentHtml::isHtml5
* @covers JDocumentHtml::setHtml5
*
* @return void
*/
public function testIsAndSetHtml5()
{
// Check true
$this->object->setHtml5(true);

$this->assertThat(
$this->object->isHtml5(),
$this->isTrue(),
'JDocumentHtml::setHtml5(true) did not work'
);

// Check false
$this->object->setHtml5(false);

$this->assertThat(
$this->object->isHtml5(),
$this->isFalse(),
'JDocumentHtml::setHtml5(false) did not work'
);

// Check non-boolean
$this->object->setHtml5('non boolean');

$this->assertThat(
$this->object->isHtml5(),
$this->logicalNot($this->equalTo('non boolean')),
"JDocumentHtml::setHtml5('non boolean') did not work"
); );
} }


Expand Down

0 comments on commit 1537938

Please sign in to comment.