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

Fix JTable::addIncludePath - includes tests #1609

Merged
merged 1 commit into from Oct 18, 2012
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 5 additions & 2 deletions libraries/joomla/table/table.php
Expand Up @@ -228,7 +228,7 @@ public static function addIncludePath($path = null)
settype($path, 'array'); settype($path, 'array');


// If we have new paths to add, do so. // If we have new paths to add, do so.
if (!empty($path) && !in_array($path, self::$_includePaths)) if (!empty($path))
{ {
// Check and add each individual new path. // Check and add each individual new path.
foreach ($path as $dir) foreach ($path as $dir)
Expand All @@ -237,7 +237,10 @@ public static function addIncludePath($path = null)
$dir = trim($dir); $dir = trim($dir);


// Add to the front of the list so that custom paths are searched first. // Add to the front of the list so that custom paths are searched first.
array_unshift(self::$_includePaths, $dir); if (!in_array($dir, self::$_includePaths))
{
array_unshift(self::$_includePaths, $dir);
}
} }
} }


Expand Down
14 changes: 14 additions & 0 deletions tests/suites/unit/joomla/table/JTableTest.php
Expand Up @@ -92,6 +92,20 @@ public function testAddIncludePath()
$this->equalTo(realpath(JPATH_PLATFORM . '/joomla/table')), $this->equalTo(realpath(JPATH_PLATFORM . '/joomla/table')),
'The default return from addIncludePath without additional parameters should be to "JPATH_PLATFORM . /joomla/table"' 'The default return from addIncludePath without additional parameters should be to "JPATH_PLATFORM . /joomla/table"'
); );

// Test that adding paths that already exist don't get re-added
$expected = array(
'/dummy/',
'dir/not/exist',
JPATH_PLATFORM . '/joomla/table'
);

// Add dummy paths
$paths = JTable::addIncludePath(array('dir/not/exist', '/dummy/'));
// Re-add the returned paths - these shouldn't get added again.
$paths = JTable::addIncludePath($paths);

$this->assertEquals($expected, $paths);
} }


/** /**
Expand Down