From: Dan F. <dfr...@cs...> - 2004-06-03 16:58:43
|
Fix a couple sorting bugs, more unit tests. Dan =================================== More detail to an error message: =================================== diff -b -u -r1.5 -r1.6 --- Theme.php 28 May 2004 20:15:56 -0000 1.5 +++ Theme.php 3 Jun 2004 16:40:04 -0000 1.6 @@ -379,7 +379,7 @@ return $this->_default_theme->_findFile($file, $missing_okay); } else if (!$missing_okay) { - trigger_error("$file: not found", E_USER_NOTICE); + trigger_error("$file: not found, looked in $this->_theme", E_USER_NOTICE); } return false; } =================================== Fix sorting by column name (e.g., "+pagename"). Fix sorting by pagename if page doesn't exist. =================================== diff -b -u -r1.15 -r1.16 --- PageList.php 28 May 2004 16:07:11 -0000 1.15 +++ PageList.php 3 Jun 2004 16:43:45 -0000 1.16 @@ -1,4 +1,4 @@ -<?php rcs_id('$Id: PageList.php,v 1.15 2004/05/28 16:07:11 dfrankow Exp $'); +<?php rcs_id('$Id: PageList.php,v 1.16 2004/06/03 16:43:45 dfrankow Exp $'); /** * List a number of pagenames, optionally as table with various columns. @@ -479,16 +479,28 @@ return WikiLink($page_handle, 'unknown'); } + function _getPageNameFromCol($colval) { + $name = ''; + if (is_a($colval, 'WikiDB_Page')) { + $name = $colval->getName(); + } + else if (is_a($colval, 'XmlContent')) { + // Gotta sort by something + $name = $colval->asString(); + } + else { + // colvala was of unexpected type + assert( false ); + } + return $name; + } + /** * Compare two pages for sorting. See _PageList_Column::_compare. **/ function _compare($colvala, $colvalb) { - assert($colvala, 'WikiDB_Page'); - $contenta = $colvala->getContent(); - $namea = $contenta[0]; - assert($colvalb, 'WikiDB_Page'); - $contentb = $colvalb->getContent(); - $nameb = $contentb[0]; + $namea = $this->_getPageNameFromCol($colvala); + $nameb = $this->_getPageNameFromCol($colvalb); return strcmp($namea, $nameb); } }; @@ -921,7 +933,7 @@ if ($column == 'rating' and !$GLOBALS['request']->_user->isSignedIn()) return false; - $this->addColumnObject($this->_types[$column]); + $this->addColumnObject($this->_types[$column], $column); return true; } @@ -930,15 +942,19 @@ * Add a column to this PageList, given a column object. * * @param $col object An object derived from _PageList_Column. + * @param $typename string The name of the column type, e.g. 'pagename' + * If this is given, you can refer to the column + * to sort by name, e.g., "+pagename". Otherwise + * you must use column # (starting from 0). **/ - function addColumnObject($col) { + function addColumnObject($col, $typename = false) { $heading = $col->getHeading(); if (!empty($heading)) $col->setHeading($heading); $this->_columns[] = $col; end($this->_columns); - $this->_columnsMap[$heading] = key($this->_columns); + $this->_columnsMap[$typename] = key($this->_columns); } /** =================================== More unit tests changes. Here are things I remember: Print a simple traceback for both broken assert() and error callback. Get ALL errors reported, e.g. "function not found", parse errors, etc. Add a real test for PageList sorting =================================== I don't remember which files changed, so I tar-ed up the whole thing again. See attached unit.tgz. |