Skip to content

Commit

Permalink
Incorrect field names used in JTableCorecontent (discovered implement…
Browse files Browse the repository at this point in the history
…ing unit tests)
  • Loading branch information
Michael Babker committed Mar 30, 2013
1 parent 92a6a7f commit f3b429e
Show file tree
Hide file tree
Showing 8 changed files with 764 additions and 9 deletions.
1 change: 1 addition & 0 deletions installation/CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ $ -> Language fix or change
^ [#30425] Remove duplicated filterText() methods
# [#29551] Fixed list_price and sale_price. Thanks Gabriele
# [#30076] Pagination does not work for components with more than one administrative view. Thanks Ram
# Incorrect field names used in JTableCorecontent (discovered implementing unit tests)

29-Mar-2013 Mark Dexter
# [#30205] findmanifest should prioritize main folder manifests. Thanks Roberto.
Expand Down
21 changes: 13 additions & 8 deletions libraries/cms/table/corecontent.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,10 @@ public function check()

if (trim($this->core_alias) == '')
{
$this->alias = $this->core_title;
$this->core_alias = $this->core_title;
}

$this->alias = JApplication::stringURLSafe($this->alias);
$this->core_alias = JApplication::stringURLSafe($this->core_alias);

if (trim(str_replace('-', '', $this->core_alias)) == '')
{
Expand Down Expand Up @@ -166,29 +166,32 @@ public function store($updateNulls = false)
$date = JFactory::getDate();
$user = JFactory::getUser();

if ($this->id)
if ($this->core_content_id)
{
// Existing item
$this->core_modified_time = $date->toSql();
$this->core_modified_by_user_id = $user->get('id');
$this->core_modified_user_id = $user->get('id');
}
else
{
// New content item. A content item core_created_time and core_created_by_user_id field can be set by the user,
// New content item. A content item core_created_time and core_created_user_id field can be set by the user,
// so we don't touch either of these if they are set.
if (!(int) $this->core_created_time)
{
$this->core_created_time = $date->toSql();
}

if (empty($this->core_created_by_user_id))
if (empty($this->core_created_user_id))
{
$this->core_created_by_user_id = $user->get('id');
$this->core_created_user_id = $user->get('id');
}
}
// Verify that the alias is unique
$table = JTable::getInstance('Corecontent', 'JTable');
if ($table->load(array('alias' => $this->core_alias, 'catid' => $this->core_catid)) && ($table->core_content_id != $this->core_content_id || $this->core_content_id == 0))
if (
$table->load(array('core_alias' => $this->core_alias, 'core_catid' => $this->core_catid))
&& ($table->core_content_id != $this->core_content_id || $this->core_content_id == 0)
)
{
$this->setError(JText::_('JLIB_DATABASE_ERROR_ARTICLE_UNIQUE_ALIAS'));
return false;
Expand Down Expand Up @@ -245,8 +248,10 @@ public function publish($pks = null, $state = 1, $userId = 0)
$query->where($this->_db->quoteName($k) . 'IN (' . $pksImploded . ')');

// Determine if there is checkin support for the table.
$checkin = false;
if (property_exists($this, 'core_checked_out_user_id') && property_exists($this, 'core_checked_out_time'))
{
$checkin = true;
$query->where(' (' . $this->_db->quoteName('core_checked_out_user_id') . ' = 0 OR ' . $this->_db->quoteName('core_checked_out_user_id') . ' = ' . (int) $userId . ')');
}
$this->_db->setQuery($query);
Expand Down
3 changes: 3 additions & 0 deletions tests/CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ $ -> Language fix or change
- -> Removed
! -> Note

29-Mar-2013 Michael Babker
+# Test JTableCorecontent, fix bugs found in class

29-Mar-2013 Mark Dexter
# Fix failing system tests.
# More system test fixes, fix CHANGELOG typo.
Expand Down
57 changes: 56 additions & 1 deletion tests/unit/schema/ddl.sql
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,62 @@ CREATE TABLE `jos_content_types` (
`router` TEXT NOT NULL DEFAULT ''
);

CREATE INDEX `idx_alias` ON `jos_content_types` (`type_alias`);
CREATE INDEX `idx_content_types_alias` ON `jos_content_types` (`type_alias`);

-- --------------------------------------------------------

--
-- Table structure for table `jos_core_content`
--

CREATE TABLE `jos_core_content` (
`core_content_id` INTEGER PRIMARY KEY AUTOINCREMENT,
`core_type_alias` TEXT NOT NULL DEFAULT '',
`core_title` TEXT NOT NULL DEFAULT '',
`core_alias` TEXT NOT NULL DEFAULT '',
`core_body` TEXT NOT NULL DEFAULT '',
`core_state` INTEGER NOT NULL DEFAULT '0',
`core_checked_out_time` TEXT NOT NULL DEFAULT '0000-00-00 00:00:00',
`core_checked_out_user_id` INTEGER NOT NULL DEFAULT '0',
`core_access` INTEGER NOT NULL DEFAULT '0',
`core_params` TEXT NOT NULL DEFAULT '',
`core_featured` INTEGER NOT NULL DEFAULT '0',
`core_metadata` TEXT NOT NULL DEFAULT '',
`core_created_user_id` INTEGER NOT NULL DEFAULT '0',
`core_created_by_alias` TEXT NOT NULL DEFAULT '',
`core_created_time` TEXT NOT NULL DEFAULT '0000-00-00 00:00:00',
`core_modified_user_id` INTEGER NOT NULL DEFAULT '0',
`core_modified_time` TEXT NOT NULL DEFAULT '0000-00-00 00:00:00',
`core_language` TEXT NOT NULL DEFAULT '',
`core_publish_up` TEXT NOT NULL DEFAULT '0000-00-00 00:00:00',
`core_publish_down` TEXT NOT NULL DEFAULT '0000-00-00 00:00:00',
`core_content_item_id` INTEGER NOT NULL DEFAULT '0',
`asset_id` INTEGER NOT NULL DEFAULT '0',
`core_images` TEXT NOT NULL DEFAULT '',
`core_urls` TEXT NOT NULL DEFAULT '',
`core_hits` INTEGER NOT NULL DEFAULT '0',
`core_version` INTEGER NOT NULL DEFAULT '1',
`core_ordering` INTEGER NOT NULL DEFAULT '0',
`core_metakey` TEXT NOT NULL DEFAULT '',
`core_metadesc` TEXT NOT NULL DEFAULT '',
`core_catid` INTEGER NOT NULL DEFAULT '0',
`core_xreference` TEXT NOT NULL DEFAULT '',
`core_type_id` INTEGER NOT NULL DEFAULT '0'/*,
CONSTRAINT `idx_core_content_type_alias_item_id` UNIQUE (`core_type_alias`,`core_content_item_id`)*/
);

CREATE INDEX `tag_idx` ON `jos_core_content` (`core_state`,`core_access`);
CREATE INDEX `idx_core_content_access` ON `jos_core_content` (`core_access`);
CREATE INDEX `idx_core_content_alias` ON `jos_core_content` (`core_alias`);
CREATE INDEX `idx_core_content_language` ON `jos_core_content` (`core_language`);
CREATE INDEX `idx_core_content_title` ON `jos_core_content` (`core_title`);
CREATE INDEX `idx_core_content_modified_time` ON `jos_core_content` (`core_modified_time`);
CREATE INDEX `idx_core_content_created_time` ON `jos_core_content` (`core_created_time`);
CREATE INDEX `idx_core_content_content_type` ON `jos_core_content` (`core_type_alias`);
CREATE INDEX `idx_core_content_core_modified_user_id` ON `jos_core_content` (`core_modified_user_id`);
CREATE INDEX `idx_core_content_core_checked_out_user_id` ON `jos_core_content` (`core_checked_out_user_id`);
CREATE INDEX `idx_core_content_core_created_user_id` ON `jos_core_content` (`core_created_user_id`);
CREATE INDEX `idx_core_content_core_type_id` ON `jos_core_content` (`core_type_id`);

-- --------------------------------------------------------

Expand Down
34 changes: 34 additions & 0 deletions tests/unit/suites/libraries/html/data/JHtmlTest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,40 @@
<column>field_mappings</column>
<column>router</column>
</table>
<table name="jos_core_content">
<column>core_content_id</column>
<column>core_type_alias</column>
<column>core_title</column>
<column>core_alias</column>
<column>core_body</column>
<column>core_state</column>
<column>core_checked_out_time</column>
<column>core_checked_out_user_id</column>
<column>core_access</column>
<column>core_params</column>
<column>core_featured</column>
<column>core_metadata</column>
<column>core_created_user_id</column>
<column>core_created_by_alias</column>
<column>core_created_time</column>
<column>core_modified_user_id</column>
<column>core_modified_time</column>
<column>core_language</column>
<column>core_publish_up</column>
<column>core_publish_down</column>
<column>core_content_item_id</column>
<column>asset_id</column>
<column>core_images</column>
<column>core_urls</column>
<column>core_hits</column>
<column>core_version</column>
<column>core_ordering</column>
<column>core_metakey</column>
<column>core_metadesc</column>
<column>core_catid</column>
<column>core_xreference</column>
<column>core_type_id</column>
</table>
<table name="jos_core_log_searches">
<column>search_term</column>
<column>hits</column>
Expand Down
204 changes: 204 additions & 0 deletions tests/unit/suites/libraries/table/JTableCorecontentTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,204 @@
<?php
/**
* @package Joomla.UnitTest
* @subpackage Table
*
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/

/**
* Test class for JTableMenuType.
*
* @package Joomla.UnitTest
* @subpackage Table
* @since 3.1
*/
class JTableCorecontentTest extends TestCaseDatabase
{
/**
* @var JTableCorecontent
* @since 3.1
*/
protected $object;

/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*
* @return void
*
* @since 3.1
*/
protected function setUp()
{
parent::setUp();

// Get the mocks
$this->saveFactoryState();

JFactory::$session = $this->getMockSession();

$this->object = new JTableCorecontent(self::$driver);
}

/**
* Tears down the fixture, for example, closes a network connection.
* This method is called after a test is executed.
*
* @return void
*
* @since 3.1
*/
protected function tearDown()
{
$this->restoreFactoryState();

parent::tearDown();
}

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

$dataSet->addTable('jos_assets', __DIR__ . '/stubs/jos_assets.csv');
$dataSet->addTable('jos_core_content', __DIR__ . '/stubs/jos_core_content.csv');

return $dataSet;
}

/**
* Test JTableCorecontent::bind
*
* @todo Implement testBind().
*
* @return void
*/
public function testBind()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete('This test has not been implemented yet.');
}

/**
* Tests JTableCorecontent::check
*
* @return void
*
* @since 3.1
*/
public function testCheck()
{
$table = $this->object;

$this->assertThat(
$table->check(),
$this->isFalse(),
'Line: ' . __LINE__ . ' Checking an empty table should fail.'
);

$table->core_title = 'Test Title';
$this->assertThat(
$table->check(),
$this->isTrue(),
'Line: ' . __LINE__ . ' Checking the table with just the title should pass.'
);

$this->assertThat(
$table->core_alias,
$this->equalTo('test-title'),
'Line: ' . __LINE__ . ' An empty alias should assume the value of the title.'
);

$table->core_body = '';
$this->assertThat(
$table->check(),
$this->isTrue(),
'Line: ' . __LINE__ . ' Checking with an empty body should pass.'
);

$table->core_body = 'The intro text object.';
$table->core_publish_down = '2001-01-01 00:00:00';
$table->core_publish_up = JFactory::getDate();

$this->assertThat(
$table->check(),
$this->isTrue(),
'Line: ' . __LINE__ . ' The check function should now complete without error.'
);

$this->assertThat(
$table->core_publish_up,
$this->equalTo('2001-01-01 00:00:00'),
'Line: ' . __LINE__ . ' The check function should have reversed the previously set publish_up and down times.'
);
}

/**
* Tests JTableCorecontent::store
*
* @return void
*
* @since 3.1
*/
public function testStore()
{
$table = $this->object;

// Handle updating an existing article
$table->load('3');
$originalAlias = $table->core_alias;
$table->core_title = 'New Title';
$table->core_alias = 'archive-module';
$this->assertFalse($table->store(), 'Line: ' . __LINE__ . ' Table store should fail due to a duplicated alias');
$table->core_alias = 'article-categories-module';
$this->assertTrue($table->store(), 'Line: ' . __LINE__ . ' Table store should succeed');
$table->reset();
$table->load('3');
$this->assertEquals('New Title', $table->core_title, 'Line: ' . __LINE__ . ' Title should be updated');
$this->assertEquals($originalAlias, $table->core_alias, 'Line: ' . __LINE__ . ' Alias should be the same as originally set');

// Store a new article
$table->load('8');
$table->core_content_id = null;
$table->core_title = 'Beginners (Copy)';
$table->core_alias = 'beginners-copy';
$table->core_created_time = null;
$table->core_created_user_id = null;
$this->assertTrue($table->store(), 'Line: ' . __LINE__ . ' Table store should succeed and insert a new record');
}

/**
* Tests JTableCorecontent::publish
*
* @return void
*
* @since 3.1
*/
public function testPublish()
{
$table = $this->object;

// Test with pk's in an array
$pks = array('18', '31');
$this->assertTrue($table->publish($pks, '0'), 'Line: ' . __LINE__ . ' Publish with an array of pks should work');
$table->load('18');
$this->assertEquals('0', $table->core_state, 'Line: ' . __LINE__ . ' Id 18 should be unpublished');
$table->reset();
$table->load('31');
$this->assertEquals('0', $table->core_state, 'Line: ' . __LINE__ . ' Id 31 should be unpublished');
$table->reset();

// Test with a single pk
$this->assertTrue($table->publish('32', '1'), 'Line: ' . __LINE__ . ' Publish with a single pk should work');
$table->load('32');
$this->assertEquals('1', $table->core_state, 'Line: ' . __LINE__ . ' Id 32 should be published');
}
}
Loading

0 comments on commit f3b429e

Please sign in to comment.