Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions libraries/cms/helper/contenthistory.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function __construct($typeAlias = null)
/**
* Method to delete the history for an item.
*
* @param JTable $table JTable object being tagged
* @param JTable $table JTable object being versioned
*
* @return boolean true on success, otherwise false.
*
Expand Down Expand Up @@ -92,7 +92,7 @@ public function getHistory($typeId, $id)
/**
* Method to save a version snapshot to the content history table.
*
* @param JTable $table JTable object being tagged
* @param JTable $table JTable object being versioned
*
* @return boolean True on success, otherwise false.
*
Expand Down
73 changes: 58 additions & 15 deletions tests/unit/suites/libraries/cms/helper/JHelperContentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,31 @@
* @subpackage Helper
* @since 3.2
*/
class JHelperContentTest extends PHPUnit_Framework_TestCase
class JHelperContentTest extends TestCaseDatabase
{
/**
* @var JHelper
* @since 3.2
*/
protected $object;

/**
* Gets the data set to be loaded into the database during setup
*
* @return PHPUnit_Extensions_Database_DataSet_CsvDataSet
*
* @since 3.2
*/
protected function getDataSet()
{
$dataSet = new PHPUnit_Extensions_Database_DataSet_CsvDataSet(',', "'", '\\');

$dataSet->addTable('jos_languages', JPATH_TEST_DATABASE . '/jos_languages.csv');
$dataSet->addTable('jos_users', JPATH_TEST_DATABASE . '/jos_users.csv');

return $dataSet;
}

/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
Expand All @@ -35,65 +52,91 @@ protected function setUp()
parent::setUp();

$this->object = new JHelperContent;
JFactory::$application = $this->getMockApplication();
}

/**
* Tests the tagItem method
* Tests the getCurrentLanguage()
*
* @return void
*
* @since 3.2
*/
public function testTagItem()
public function testGetCurrentLanguage()
{
$this->markTestSkipped('Test not implemented.');
}

/**
* Tests the getCurrentLanguage()
* getLanguageId data
*
* @return void
* @return array
*
* @since 3.2
*/
public function testGetCurrentLanguage()
public function languageIdProvider()
{
$this->markTestSkipped('Test not implemented.');
return array(
array('Exists' => 'en-GB', 1),
array('Does not exit' => 'ab-CD', null),
);
}

/**
* Tests the getLanguageId() method
* Tests the getLanguageId()
*
* @return void
*
* @since 3.2
* @dataProvider languageIdProvider
*/
public function testLanguageId()
public function testGetLanguageId($languageName, $expected)
{
$this->markTestSkipped('Test not implemented.');
$languageId = $this->object->getLanguageId($languageName);
$this->assertEquals($languageId, $expected);
}

/**
* Tests the getStore() method
* Tests the getActions() method
*
* @return void
*
* @since 3.2
*/
public function testStore()
public function testGetActions()
{
$this->markTestSkipped('Test not implemented.');
}

/**
* Tests the getPrimaryKey() method
* Tests the addSubmenu() method
*
* @return void
*
* @since 3.2
*/
public function testGetPrimaryKey()
public function testAddSubmenu()
{
$this->markTestSkipped('Test not implemented.');
$this->markTestSkipped('Test should be implemented in classes extendig this.');
}

/*
* Tests the getRowData() method
*
* @return void
*
* @since 3.2
*/
public function testGetRowData()
{
$db = JFactory::getDbo();
$db->setQuery('SELECT * FROM ' . $db->quoteName('#__users') . ' WHERE ' . $db->quoteName('id') . ' = ' . (int) 42);
$arrayFromQuery = $db->loadAssoc();

$testTable = new JTableUser(self::$driver);
$testTable->load(42);
$arrayFromMethod = $this->object->getRowData($testTable);

$this->assertEquals($arrayFromQuery, $arrayFromMethod);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* @subpackage Helper
* @since 3.2
*/
class JHelperContenthistoryTest extends PHPUnit_Framework_TestCase
class JHelperContenthistoryTest extends TestCaseDatabase
{
/**
* @var JHelperContenthistory
Expand All @@ -35,8 +35,26 @@ protected function setUp()
parent::setUp();

$this->object = new JHelperContenthistory;
JFactory::$application = $this->getMockApplication();
}

/**
* Gets the data set to be loaded into the database during setup
*
* @return PHPUnit_Extensions_Database_DataSet_CsvDataSet
*
* @since 3.2
*/
protected function getDataSet()
{
$dataSet = new PHPUnit_Extensions_Database_DataSet_CsvDataSet(',', "'", '\\');

$dataSet->addTable('jos_users', JPATH_TEST_DATABASE . '/jos_users.csv');
$dataSet->addTable('jos_content', JPATH_TEST_DATABASE . '/jos_content.csv');
//$dataSet->addTable('jos_ucm_base', JPATH_TEST_DATABASE . '/jos_ucm_history.csv');

return $dataSet;
}
/**
* Tests the deleteHistory() method
*
Expand Down
42 changes: 41 additions & 1 deletion tests/unit/suites/libraries/cms/helper/JHelperMediaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,11 @@ public function canUploadProvider()
array('Name contains bad characters' => array('name' => 'my<body>picture.jpg', 'type' => 'image/jpeg', 'tmp_name' => JPATH_TESTS . '/suites/libraries/joomla/image/stubs/koala.jpg', 'error' => 0, 'size' => 8), false),
array('Name contains bad extension' => array('name' => 'myscript.php.jpg', 'type' => 'image/jpeg', 'tmp_name' => JPATH_TESTS . '/suites/libraries/joomla/image/stubs/koala.jpg', 'error' => 0, 'size' => 8), false),
array('Name contains a space' => array('name' => 'my script.php.jpg', 'type' => 'image/jpeg', 'tmp_name' => JPATH_TESTS . '/suites/libraries/joomla/image/stubs/koala.jpg', 'error' => 0, 'size' => 8), false),
);
array('Empty name' => array('name' => '', 'type' => 'image/jpeg', 'tmp_name' => JPATH_TESTS . '/suites/libraries/joomla/image/stubs/koala.jpg', 'error' => 0, 'size' => 8), false),
array('Unknown format' => array('name' => 'myfile.xyz', 'type' => 'image/jpeg', 'tmp_name' => JPATH_TESTS . '/suites/libraries/joomla/image/stubs/koala.jpg', 'error' => 0, 'size' => 8), false),
array('File above php limit' => array('name' => 'mypicture.jpg', 'type' => 'image/jpeg', 'tmp_name' => JPATH_TESTS . '/suites/libraries/joomla/image/stubs/koala.jpg', 'error' => 0, 'size' => 20485770), false),
array('File above max configured but below php limit' => array('name' => 'mypicture.jpg', 'type' => 'image/jpeg', 'tmp_name' => JPATH_TESTS . '/suites/libraries/joomla/image/stubs/koala.jpg', 'error' => 0, 'size' => 10685770), false),
);
}

/**
Expand All @@ -170,4 +174,40 @@ public function testCanUpload($file, $expected)
$canUpload = $this->object->canUpload($file);
$this->assertEquals($canUpload, $expected);
}

/**
* imageResize data
*
* @return array
*
* @since 3.2
*/
public function imageResizeProvider()
{
return array(
array('Bigger Height' => 300, 200, 150, array(150, 100)),
array('Bigger Width' => 200, 300, 150, array(100, 150)),
array('Square' => 300, 300, 150, array(150, 150)),
array('0 Height' => 300, 0, 150, array(150, 0)),
array('0 Width' => 0, 300, 150, array(0, 150)),
array('0 Target' => 300, 200, 0, array(0, 0)),
);
}

/**
* Tests the imageResize method
*
* @param string $fileName The filename
* @param string $expected Expected result
*
* @return void
*
* @dataProvider imageResizeProvider
* @since 3.2
*/
public function testImageResize($width, $height, $target, $expected)
{
$newSize = $this->object->imageResize($width, $height, $target);
$this->assertEquals($newSize, $expected);
}
}
23 changes: 22 additions & 1 deletion tests/unit/suites/libraries/cms/helper/JHelperTagsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* @subpackage Helper
* @since 3.1
*/
class JHelperTagsTest extends PHPUnit_Framework_TestCase
class JHelperTagsTest extends TestCaseDatabase
{
/**
* @var JHelperTags
Expand All @@ -35,6 +35,27 @@ protected function setUp()
parent::setUp();

$this->object = new JHelperTags;
JFactory::$application = $this->getMockApplication();
}
/**
* Gets the data set to be loaded into the database during setup
*
* @return PHPUnit_Extensions_Database_DataSet_CsvDataSet
*
* @since 3.2
*/
protected function getDataSet()
{
$dataSet = new PHPUnit_Extensions_Database_DataSet_CsvDataSet(',', "'", '\\');

$dataSet->addTable('jos_tags', JPATH_TEST_DATABASE . '/jos_tags.csv');
$dataSet->addTable('jos_users', JPATH_TEST_DATABASE . '/jos_users.csv');
$dataSet->addTable('jos_content', JPATH_TEST_DATABASE . '/jos_content.csv');
$dataSet->addTable('jos_content_types', JPATH_TEST_DATABASE . '/jos_content_types.csv');
$dataSet->addTable('jos_ucm_content', JPATH_TEST_DATABASE . '/jos_ucm_content.csv');
$dataSet->addTable('jos_ucm_base', JPATH_TEST_DATABASE . '/jos_ucm_base.csv');

return $dataSet;
}

/**
Expand Down
70 changes: 67 additions & 3 deletions tests/unit/suites/libraries/cms/helper/JHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,31 @@
* @subpackage Helper
* @since 3.2
*/
class JHelperTest extends PHPUnit_Framework_TestCase
class JHelperTest extends TestCaseDatabase
{
/**
* @var JHelper
* @since 3.2
*/
protected $object;

/**
* Gets the data set to be loaded into the database during setup
*
* @return PHPUnit_Extensions_Database_DataSet_CsvDataSet
*
* @since 3.2
*/
protected function getDataSet()
{
$dataSet = new PHPUnit_Extensions_Database_DataSet_CsvDataSet(',', "'", '\\');

$dataSet->addTable('jos_languages', JPATH_TEST_DATABASE . '/jos_languages.csv');
$dataSet->addTable('jos_users', JPATH_TEST_DATABASE . '/jos_users.csv');

return $dataSet;
}

/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
Expand All @@ -35,6 +52,7 @@ protected function setUp()
parent::setUp();

$this->object = new JHelper;
JFactory::$application = $this->getMockApplication();
}

/**
Expand All @@ -49,6 +67,35 @@ public function testGetCurrentLanguage()
$this->markTestSkipped('Test not implemented.');
}

/**
* getLanguageId data
*
* @return array
*
* @since 3.2
*/
public function languageIdProvider()
{
return array(
array('Exists' => 'en-GB', 1),
array('Does not exit' => 'ab-CD', null),
);
}

/**
* Tests the getLanguageId()
*
* @return void
*
* @since 3.2
* @dataProvider languageIdProvider
*/
public function testGetLanguageId($languageName, $expected)
{
$languageId = $this->object->getLanguageId($languageName);
$this->assertEquals($languageId, $expected);
}

/**
* Tests the getRowData() method
*
Expand All @@ -58,7 +105,15 @@ public function testGetCurrentLanguage()
*/
public function testGetRowData()
{
$this->markTestSkipped('Test not implemented.');
$db = JFactory::getDbo();
$db->setQuery('SELECT * FROM ' . $db->quoteName('#__users') . ' WHERE ' . $db->quoteName('id') . ' = ' . (int) 42);
$arrayFromQuery = $db->loadAssoc();

$testTable = new JTableUser(self::$driver);
$testTable->load(42);
$arrayFromMethod = $this->object->getRowData($testTable);

$this->assertEquals($arrayFromQuery, $arrayFromMethod);
}

/**
Expand All @@ -70,6 +125,15 @@ public function testGetRowData()
*/
public function testDataObject()
{
$this->markTestSkipped('Test not implemented.');
$db = JFactory::getDbo();
$db->setQuery('SELECT * FROM ' . $db->quoteName('#__users') . ' WHERE ' . $db->quoteName('id') . ' = ' . (int) 42);
$objectFromQuery = $db->loadObject();

$testTable = new JTableUser(self::$driver);
$testTable->load(42);
$objectFromMethod = $this->object->getDataObject($testTable);

$this->assertEquals($objectFromQuery, $objectFromMethod);

}
}