1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
|
<?php
require_once dirname(__FILE__) . '/TestBase.php';
/**
* $Horde: turba/lib/tests/ListViewTest.php,v 1.2.2.1 2007/12/20 14:34:31 jan Exp $
*
* @author Jason M. Felice <jason.m.felice@gmail.com>
* @package Turba
* @subpackage UnitTests
*/
class Turba_ListViewTest extends Turba_TestBase {
function setUp()
{
parent::setUp();
$this->setUpDatabase();
require_once dirname(__FILE__) . '/../ListView.php';
}
function callListView($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_ListView($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_ListView::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->callListView('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->callListView('getAlpha', $numDisplayed, 'j');
$count = 0;
foreach ($this->_sortedByLastname as $name) {
if (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);
}
}
|