Skip to content

Instantly share code, notes, and snippets.

@realityking
Created July 2, 2012 12:58
Show Gist options
  • Save realityking/3033150 to your computer and use it in GitHub Desktop.
Save realityking/3033150 to your computer and use it in GitHub Desktop.
Unit tests to be moved to the CMS
<?php
/**
* @package Joomla.UnitTest
* @subpackage HTML
*
* @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
require_once JPATH_PLATFORM . '/legacy/html/batch.php';
/**
* Test class for JHtmlBatch.
*
* @since 11.3
*/
class JHtmlBatchTest extends TestCaseDatabase
{
/**
* @var JHtmlBatch
* @since 11.3
*/
protected $object;
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*
* @return void
*
* @since 11.3
*/
protected function setUp()
{
parent::setUp();
}
/**
* Gets the data set to be loaded into the database during setup
*
* @return xml dataset
*
* @since 11.3
*/
protected function getDataSet()
{
return $this->createXMLDataSet(JPATH_TESTS . '/suites/unit/joomla/html/html/testfiles/JHtmlTest.xml');
}
/**
* Tests the JHtmlBatch::access method.
*
* @return void
*
* @since 11.3
* @covers JHtmlBatch::access
*/
public function testAccess()
{
$this->assertThat(
JHtmlBatch::access(),
$this->StringContains('<option value="1">Public</option>')
);
}
/**
* Tests the JHtmlBatch::item method.
*
* @return void
*
* @since 11.3
* @covers JHtmlBatch::item
*/
public function testItem()
{
$this->assertThat(
JHtmlBatch::item('com_content'),
$this->StringContains('<option value="2">Uncategorised</option>')
);
}
/**
* Tests the JHtmlBatch::language method.
*
* @return void
*
* @since 11.3
* @covers JHtmlBatch::language
*/
public function testLanguage()
{
$this->assertThat(
JHtmlBatch::language(),
$this->StringContains('<option value="en-GB">English (UK)</option>')
);
}
/**
* Tests the JHtmlBatch::user method.
*
* @return void
*
* @since 11.4
* @covers JHtmlBatch::user
*/
public function testUser()
{
$this->assertThat(
JHtmlBatch::user(true),
$this->StringContains('<option value="42">Super User</option>')
);
}
}
<?php
/**
* @package Joomla.UnitTest
* @subpackage HTML
*
* @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
/**
* Test class for JToolbar.
* Generated by PHPUnit on 2009-10-27 at 15:38:36.
*/
class JToolbarTest extends PHPUnit_Framework_TestCase
{
/**
* @var JToolbar
*/
protected $object;
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
protected function setUp()
{
$this->object = new JToolbar;
}
/**
* Tears down the fixture, for example, closes a network connection.
* This method is called after a test is executed.
*/
protected function tearDown()
{
}
/**
* @covers JToolbar::addButtonPath
*/
public function testAddButtonPathString()
{
$initialValue = $this->readAttribute($this->object, '_buttonPath');
$this->object->addButtonPath('MyTestPath');
$newValue = $this->readAttribute($this->object, '_buttonPath');
$this->assertThat(
$newValue[0],
$this->equalTo('MyTestPath'.DIRECTORY_SEPARATOR)
);
$initialCount = count($initialValue);
for($i = 0; $i < $initialCount; $i++) {
$this->assertThat(
$initialValue[$i],
$this->equalTo($newValue[$i+1])
);
}
}
/**
* @covers JToolbar::addButtonPath
*/
public function testAddButtonPathArray()
{
$initialValue = $this->readAttribute($this->object, '_buttonPath');
$this->object->addButtonPath(array('MyTestPath1', 'MyTestPath2'));
$newValue = $this->readAttribute($this->object, '_buttonPath');
$this->assertThat(
$newValue[0],
$this->equalTo('MyTestPath2'.DIRECTORY_SEPARATOR)
);
$this->assertThat(
$newValue[1],
$this->equalTo('MyTestPath1'.DIRECTORY_SEPARATOR)
);
$initialCount = count($initialValue);
for($i = 0; $i < $initialCount; $i++) {
$this->assertThat(
$initialValue[$i],
$this->equalTo($newValue[$i+2])
);
}
}
/**
* Test the getInstance method.
*
* @return void
*
* @since 11.3
* @covers JToolbar::getInstance
*/
public function testGetInstance()
{
$this->object = JToolBar::getInstance();
$this->assertThat(
$this->object,
$this->isInstanceOf('JToolBar')
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment