From 6496bd32f49e7be1b0c21e13f2d3981393414dec Mon Sep 17 00:00:00 2001 From: Jan Schneider Date: Fri, 2 Jul 2010 13:16:17 +0200 Subject: [PATCH] Turba_ListView -> Turba_View_List --- turba/lib/Forms/EditContact.php | 4 +- turba/lib/View/Browse.php | 4 +- turba/lib/{ListView.php => View/List.php} | 20 +++---- turba/lib/tests/ListViewTest.php | 14 ++--- turba/lib/tests/ViewListTest.php | 87 +++++++++++++++++++++++++++++++ turba/search.php | 2 +- 6 files changed, 108 insertions(+), 23 deletions(-) rename turba/lib/{ListView.php => View/List.php} (96%) create mode 100644 turba/lib/tests/ViewListTest.php diff --git a/turba/lib/Forms/EditContact.php b/turba/lib/Forms/EditContact.php index 9830d2952..65bf06314 100644 --- a/turba/lib/Forms/EditContact.php +++ b/turba/lib/Forms/EditContact.php @@ -135,10 +135,8 @@ class Turba_EditContactGroupForm extends Turba_EditContactForm { $sources = Turba::getColumns(); $columns = isset($sources[$source]) ? $sources[$source] : array(); - require_once TURBA_BASE . '/lib/List.php'; - require_once TURBA_BASE . '/lib/ListView.php'; $results = new Turba_List($vars->get('objectkeys')); - $listView = new Turba_ListView($results, array('Group' => true), $columns); + $listView = new Turba_View_List($results, array('Group' => true), $columns); echo '
' . $listView->getPage($numDisplayed); } diff --git a/turba/lib/View/Browse.php b/turba/lib/View/Browse.php index e77548e29..50f414040 100644 --- a/turba/lib/View/Browse.php +++ b/turba/lib/View/Browse.php @@ -362,7 +362,7 @@ class Turba_View_Browse { $count = $list->count() - $results->count(); $notification->push(sprintf(ngettext("There is %d contact in this list that is not viewable to you", "There are %d contacts in this list that are not viewable to you", $count), $count), 'horde.message'); } - $view = new Turba_ListView($results, null, $columns); + $view = new Turba_View_List($results, null, $columns); $view->setType('list'); } } else { @@ -391,7 +391,7 @@ class Turba_View_Browse { } elseif (is_a($results, 'PEAR_Error')) { $notification->push($results, 'horde.error'); } else { - $view = new Turba_ListView($results, null, $columns); + $view = new Turba_View_List($results, null, $columns); $view->setType('directory'); } } diff --git a/turba/lib/ListView.php b/turba/lib/View/List.php similarity index 96% rename from turba/lib/ListView.php rename to turba/lib/View/List.php index 32bdcc7a7..1d1379627 100644 --- a/turba/lib/ListView.php +++ b/turba/lib/View/List.php @@ -1,13 +1,13 @@ * @author Jon Parise * @package Turba */ -class Turba_ListView { +class Turba_View_List { /** * The Turba_List object that we are visualizing. @@ -94,13 +94,13 @@ class Turba_ListView { var $columns; /** - * Constructs a new Turba_ListView object. + * Constructs a new Turba_View_List object. * * @param Turba_List $list List of contacts to display. * @param array $controls Which icons to display * @param array $columns The list of columns to display */ - function Turba_ListView(&$list, $controls = null, $columns = null) + function Turba_View_List(&$list, $controls = null, $columns = null) { if ($controls === null) { $controls = array('Mark' => true, @@ -265,7 +265,7 @@ class Turba_ListView { $max = $this->list->count(); } return $this->_get($numDisplayed, - new Turba_ListView_PageFilter($min, $max)); + new Turba_View_List_PageFilter($min, $max)); } /** @@ -280,7 +280,7 @@ class Turba_ListView { function getAlpha(&$numDisplayed, $alpha) { return $this->_get($numDisplayed, - new Turba_ListView_AlphaFilter($alpha)); + new Turba_View_List_AlphaFilter($alpha)); } /** @@ -451,12 +451,12 @@ class Turba_ListView { /** * Skips objects whose name does not start with the specified letter */ -class Turba_ListView_AlphaFilter { +class Turba_View_List_AlphaFilter { var $_alpha; var $_format; - function Turba_ListView_AlphaFilter($alpha) + function Turba_View_List_AlphaFilter($alpha) { $this->_alpha = Horde_String::lower($alpha); $this->_format = $GLOBALS['prefs']->getValue('name_sort'); @@ -477,13 +477,13 @@ class Turba_ListView_AlphaFilter { /** * Skips objects which are not on the current page */ -class Turba_ListView_PageFilter { +class Turba_View_List_PageFilter { var $_min; var $_max; var $_count = 0; - function Turba_ListView_PageFilter($min, $max) + function Turba_View_List_PageFilter($min, $max) { $this->_min = $min; $this->_max = $max; diff --git a/turba/lib/tests/ListViewTest.php b/turba/lib/tests/ListViewTest.php index 62531c12b..ed388d892 100644 --- a/turba/lib/tests/ListViewTest.php +++ b/turba/lib/tests/ListViewTest.php @@ -7,16 +7,16 @@ require_once dirname(__FILE__) . '/TestBase.php'; * @package Turba * @subpackage UnitTests */ -class Turba_ListViewTest extends Turba_TestBase { +class Turba_ViewListTest extends Turba_TestBase { function setUp() { parent::setUp(); $this->setUpDatabase(); - require_once dirname(__FILE__) . '/../ListView.php'; + require_once dirname(__FILE__) . '/../View/List.php'; } - function callListView($method, &$numDisplayed, $param = null) + function callView_List($method, &$numDisplayed, $param = null) { $GLOBALS['source'] = '_test_sql'; $GLOBALS['cfgSources'] = array('_test_sql' => $this->getDriverConfig()); @@ -24,7 +24,7 @@ class Turba_ListViewTest extends Turba_TestBase { $list = $this->getList(); $sources = Turba::getColumns(); $columns = isset($sources['_test_sql']) ? $sources['_test_sql'] : array(); - $view = new Turba_ListView($list, null, $columns); + $view = new Turba_View_List($list, null, $columns); $this->_output = $view->$method($numDisplayed, $param); $this->assertOk($this->_output); $this->assertNoUnwantedPattern('/Fatal error/', $this->_output); @@ -34,7 +34,7 @@ class Turba_ListViewTest extends Turba_TestBase { function test_getAddSources_returns_sources_sorted_by_name() { - $result = Turba_ListView::getAddSources(); + $result = Turba_View_List::getAddSources(); if (!$this->assertOk($result)) { return; } @@ -56,7 +56,7 @@ class Turba_ListViewTest extends Turba_TestBase { function test_getPage_renders_all_list_items() { - $this->callListView('getPage', $numDisplayed); + $this->callView_List('getPage', $numDisplayed); foreach ($this->_sortedByLastname as $name) { $this->assertWantedPattern('/' . preg_quote($name, '/') . '/', $this->_output); @@ -67,7 +67,7 @@ class Turba_ListViewTest extends Turba_TestBase { function test_getAlpha_renders_filtered_items() { - $this->callListView('getAlpha', $numDisplayed, 'j'); + $this->callView_List('getAlpha', $numDisplayed, 'j'); $count = 0; foreach ($this->_sortedByLastname as $name) { if (Horde_String::lower($name{0}) == 'j') { diff --git a/turba/lib/tests/ViewListTest.php b/turba/lib/tests/ViewListTest.php new file mode 100644 index 000000000..c1bc5654b --- /dev/null +++ b/turba/lib/tests/ViewListTest.php @@ -0,0 +1,87 @@ + + * @package Turba + * @subpackage UnitTests + */ +class Turba_View_ListTest extends Turba_TestBase { + + function setUp() + { + parent::setUp(); + $this->setUpDatabase(); + require_once dirname(__FILE__) . '/../View/List.php'; + } + + function callView_List($method, &$numDisplayed, $param = null) + { + $GLOBALS['source'] = '_test_sql'; + $GLOBALS['cfgSources'] = array('_test_sql' => $this->getDriverConfig()); + + $list = $this->getList(); + $sources = Turba::getColumns(); + $columns = isset($sources['_test_sql']) ? $sources['_test_sql'] : array(); + $view = new Turba_View_List($list, null, $columns); + $this->_output = $view->$method($numDisplayed, $param); + $this->assertOk($this->_output); + $this->assertNoUnwantedPattern('/Fatal error/', $this->_output); + $this->assertNoUnwantedPattern('/Warning/', $this->_output); + return $view; + } + + function test_getAddSources_returns_sources_sorted_by_name() + { + $result = Turba_View_List::getAddSources(); + if (!$this->assertOk($result)) { + return; + } + + list($addToList, $addToListSources) = $result; + + $groups = $this->_groups; + sort($groups); + foreach ($addToList as $item) { + if (!empty($groups) && !empty($item['name']) && + $groups[0] == $item['name']) { + array_shift($groups); + } + } + + $this->assertTrue(empty($groups), + "Some group not found or not found in right order."); + } + + function test_getPage_renders_all_list_items() + { + $this->callView_List('getPage', $numDisplayed); + foreach ($this->_sortedByLastname as $name) { + $this->assertWantedPattern('/' . preg_quote($name, '/') . '/', + $this->_output); + } + + $this->assertEqual(count($this->_sortedByLastname), $numDisplayed); + } + + function test_getAlpha_renders_filtered_items() + { + $this->callView_List('getAlpha', $numDisplayed, 'j'); + $count = 0; + foreach ($this->_sortedByLastname as $name) { + if (Horde_String::lower($name{0}) == 'j') { + $this->assertWantedPattern('/' . preg_quote($name, '/') . '/', + $this->_output); + $count++; + } else { + $this->assertNoUnwantedPattern('/' . preg_quote($name, '/') . + '/', $this->_output); + } + } + + $this->assertEqual($count, $numDisplayed); + $this->assertNotEqual(0, $count); + } + +} diff --git a/turba/search.php b/turba/search.php index 1c2bd417d..8ff728fa6 100644 --- a/turba/search.php +++ b/turba/search.php @@ -168,7 +168,7 @@ if (is_a($driver, 'PEAR_Error')) { $columns = isset($sources[$source]) ? $sources[$source] : array(); $results->sort(Turba::getPreferredSortOrder()); - $view = new Turba_ListView($results, null, $columns); + $view = new Turba_View_List($results, null, $columns); $view->setType('search'); } } else { -- 2.11.0