Commit f835b377 authored by Oliver Klee's avatar Oliver Klee Committed by Helmut Hummel
Browse files

[TASK] Add more unit tests for t3lib_tree_pagetree_DataProvider

Clean up the class a bit and add unit tests for getRoot().

Change-Id: I9a60c9531bca8683708ddfb7e898926fb2c7d5c5
Releases: 6.0
Resolves: #39348
Reviewed-on: http://review.typo3.org/13320
Reviewed-by: Helmut Hummel
Tested-by: Helmut Hummel
parent 8999ac76
......@@ -2,7 +2,7 @@
/***************************************************************
* Copyright notice
*
* (c) 2010-2011 TYPO3 Tree Team <http://forge.typo3.org/projects/typo3v4-extjstrees>
* (c) 2010-2012 TYPO3 Tree Team <http://forge.typo3.org/projects/typo3v4-extjstrees>
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
......@@ -26,7 +26,7 @@
***************************************************************/
/**
* Abstract Tree Data Provider
* Page tree data provider.
*
* @author Stefan Galinski <stefan.galinski@gmail.com>
* @package TYPO3
......@@ -50,7 +50,7 @@ class t3lib_tree_pagetree_DataProvider extends t3lib_tree_AbstractDataProvider {
/**
* Hidden Records
*
* @var array
* @var array<string>
*/
protected $hiddenRecords = array();
......@@ -90,9 +90,9 @@ class t3lib_tree_pagetree_DataProvider extends t3lib_tree_AbstractDataProvider {
}
/**
* Returns the root node
* Returns the root node.
*
* @return t3lib_tree_Node
* @return t3lib_tree_Node the root node
*/
public function getRoot() {
/** @var $node t3lib_tree_pagetree_Node */
......@@ -188,8 +188,7 @@ class t3lib_tree_pagetree_DataProvider extends t3lib_tree_AbstractDataProvider {
* @return array
*/
protected function getRecordWithWorkspaceOverlay($uid, $unsetMovePointers = FALSE) {
$subpage = t3lib_befunc::getRecordWSOL('pages', $uid, '*', '', TRUE, $unsetMovePointers);
return $subpage;
return t3lib_befunc::getRecordWSOL('pages', $uid, '*', '', TRUE, $unsetMovePointers);
}
/**
......@@ -198,7 +197,7 @@ class t3lib_tree_pagetree_DataProvider extends t3lib_tree_AbstractDataProvider {
* @param t3lib_tree_Node $node
* @param string $searchFilter
* @param integer $mountPoint
* @return void
* @return t3lib_tree_pagetree_NodeCollection the filtered nodes
*/
public function getFilteredNodes(t3lib_tree_Node $node, $searchFilter, $mountPoint = 0) {
/** @var $nodeCollection t3lib_tree_pagetree_NodeCollection */
......@@ -329,7 +328,7 @@ class t3lib_tree_pagetree_DataProvider extends t3lib_tree_AbstractDataProvider {
* Note: If you add the search filter parameter, the nodes will be filtered by this string.
*
* @param string $searchFilter
* @return array
* @return t3lib_tree_pagetree_NodeCollection
*/
public function getTreeMounts($searchFilter = '') {
/** @var $nodeCollection t3lib_tree_pagetree_NodeCollection */
......@@ -440,20 +439,20 @@ class t3lib_tree_pagetree_DataProvider extends t3lib_tree_AbstractDataProvider {
if ($searchFilter !== '') {
if (is_numeric($searchFilter) && $searchFilter > 0) {
$seachWhere .= 'uid = ' . intval($searchFilter) . ' OR ';
$searchWhere .= 'uid = ' . intval($searchFilter) . ' OR ';
}
$searchFilter = $GLOBALS['TYPO3_DB']->fullQuoteStr('%' . $searchFilter . '%', 'pages');
$useNavTitle = $GLOBALS['BE_USER']->getTSConfigVal('options.pageTree.showNavTitle');
if ($useNavTitle) {
$seachWhere .= '(nav_title LIKE ' . $searchFilter .
' OR (nav_title = "" && title LIKE ' . $searchFilter . '))';
$searchWhere .= '(nav_title LIKE ' . $searchFilter .
' OR (nav_title = "" AND title LIKE ' . $searchFilter . '))';
} else {
$seachWhere .= 'title LIKE ' . $searchFilter;
$searchWhere .= 'title LIKE ' . $searchFilter;
}
$where .= ' AND (' . $seachWhere . ')';
$where .= ' AND (' . $searchWhere . ')';
}
return $where;
......@@ -468,11 +467,9 @@ class t3lib_tree_pagetree_DataProvider extends t3lib_tree_AbstractDataProvider {
*/
protected function getSubpages($id, $searchFilter = '') {
$where = $this->getWhereClause($id, $searchFilter);
$subpages = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
return $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
'uid', 'pages', $where, '', 'sorting', '', 'uid'
);
return $subpages;
}
/**
......@@ -495,5 +492,4 @@ class t3lib_tree_pagetree_DataProvider extends t3lib_tree_AbstractDataProvider {
return $returnValue;
}
}
?>
\ No newline at end of file
......@@ -26,31 +26,57 @@
* Testcase for class t3lib_tree_pagetree_DataProvider.
*
* @author Stefan Galinski <stefan.galinski@gmail.com>
* @author Oliver Klee <typo3-coding@oliverklee.de>
*
* @package TYPO3
* @subpackage t3lib
*/
class t3lib_tree_pagetree_DataProviderTest extends tx_phpunit_testcase {
/**
* @var PHPUnit_Framework_MockObject_MockObject|t3lib_tree_pagetree_DataProvider
* @var boolean
*/
protected $fixture = NULL;
protected $backupGlobals = TRUE;
/**
* Excludes TYPO3_DB from backup/restore of $GLOBALS because resource types cannot be handled during serializing.
*
* @var array
*/
protected $backupGlobalVariables = array();
protected $backupGlobalsBlacklist = array('TYPO3_DB');
/**
* @var t3lib_tree_pagetree_DataProvider|PHPUnit_Framework_MockObject_MockObject
*/
protected $fixture = NULL;
public function setUp() {
$this->backupGlobalVariables['TYPO3_CONF_VARS'] = $GLOBALS['TYPO3_CONF_VARS'];
$GLOBALS['TYPO3_CONF_VARS']['BE']['pageTree']['preloadLimit'] = 0;
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/tree/pagetree/class.t3lib_tree_pagetree_dataprovider.php']['postProcessCollections'] = array();
$this->fixture = new t3lib_tree_pagetree_DataProvider();
}
public function tearDown() {
unset($this->fixture);
}
foreach ($this->backupGlobalVariables as $name => $value) {
$GLOBALS[$name] = $value;
}
/**
* @test
*/
public function getRootNodeReturnsNodeWithRootId() {
$this->assertSame(
'root',
$this->fixture->getRoot()->getId()
);
}
/**
* @test
*/
public function getRootNodeReturnsExpandedNode() {
$this->assertTrue(
$this->fixture->getRoot()->isExpanded()
);
}
/**
......@@ -86,24 +112,23 @@ class t3lib_tree_pagetree_DataProviderTest extends tx_phpunit_testcase {
),
);
$this->fixture = $this->getMock('t3lib_tree_pagetree_DataProvider', array('getSubpages', 'getRecordWithWorkspaceOverlay'));
$this->fixture->expects($this->once())->method('getSubpages')
->will($this->returnValue($subpages));
$fixture = $this->getMock('t3lib_tree_pagetree_DataProvider', array('getSubpages', 'getRecordWithWorkspaceOverlay'));
$fixture->expects($this->once())->method('getSubpages')->will($this->returnValue($subpages));
$this->fixture->expects($this->at(1))->method('getRecordWithWorkspaceOverlay')->with(1)
$fixture->expects($this->at(1))->method('getRecordWithWorkspaceOverlay')->with(1)
->will($this->returnValue($subpagesWithWorkspaceOverlay[0]));
$this->fixture->expects($this->at(2))->method('getRecordWithWorkspaceOverlay')->with(2)
$fixture->expects($this->at(2))->method('getRecordWithWorkspaceOverlay')->with(2)
->will($this->returnValue($subpagesWithWorkspaceOverlay[1]));
$this->fixture->expects($this->at(3))->method('getRecordWithWorkspaceOverlay')->with(3)
$fixture->expects($this->at(3))->method('getRecordWithWorkspaceOverlay')->with(3)
->will($this->returnValue($subpagesWithWorkspaceOverlay[2]));
$node = new t3lib_tree_Node();
$node->setId(12);
$nodeCollection = $this->fixture->getNodes($node);
$nodeCollection = $fixture->getNodes($node);
/** @var $node t3lib_tree_pagetree_Node */
$isMountPointResult = array();
/** @var $node t3lib_tree_pagetree_Node */
foreach ($nodeCollection as $node) {
$isMountPointResult[] = $node->isMountPoint();
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment