/usr/share/php/tests/turba/Turba/ToDo/ViewBrowseTest.php is in php-horde-turba 4.1.3-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 | <?php
require_once __DIR__ . '/TestBase.php';
/**
* @author Jason M. Felice <jason.m.felice@gmail.com>
* @package Turba
* @subpackage UnitTests
*/
class Turba_ToDo_ViewBrowseTest extends Turba_TestBase {
function setUp()
{
$this->markTestIncomplete('Convert to use Horde_Test.');
parent::setUp();
require_once TURBA_BASE . '/lib/View/Browse.php';
$this->setUpDatabase();
$this->setUpBrowseView();
}
function setUpBrowseView()
{
$vars = new Horde_Variables();
$notification = $GLOBALS['notification'];
$turbaConf = array();
$turbaConf['menu']['import_export'] = true;
$turbaConf['menu']['apps'] = array();
$turbaConf['client']['addressbook'] = '_test_sql';
$turbaConf['shares']['source'] = 'foo';
$turbaConf['comments']['allow'] = true;
$turbaConf['documents']['type'] = 'horde';
include TURBA_BASE . '/config/attributes.php';
$cfgSources = array('_test_sql' => $this->getDriverConfig());
$this->_pageParams = array('vars' => $vars,
'prefs' => $GLOBALS['prefs'],
'notification' => $notification,
'registry' => $GLOBALS['registry'],
'browse_source_count' => 1,
'browse_source_options' => "My Address Book",
'copymoveSources' => array(),
'addSources' => $cfgSources,
'cfgSources' => $cfgSources,
'attributes' => $attributes,
'turba_shares' => false,
'conf' => $turbaConf,
'source' => '_test_sql',
'browser' => $GLOBALS['browser']);
// These are referenced explicitly from $GLOBALS, *sigh*
$GLOBALS['browse_source_count'] = $this->_pageParams['browse_source_count'];
$GLOBALS['addSources'] = $cfgSources;
$GLOBALS['copymoveSources'] = array();
$GLOBALS['cfgSources'] = $cfgSources;
$this->setPref('addressbooks', json_encode(array('_test_sql')));
}
function getPage()
{
$this->_pageParams['registry']->pushApp('turba', array('check_perms' => false));
$this->fakeAuth();
$page = new Turba_View_Browse($this->_pageParams);
Horde::startBuffer();
$page->run();
$this->_output = Horde::endBuffer();
if ($push_result) {
$this->_pageParams['registry']->popApp();
}
$this->assertNoUnwantedPattern('/<b>Warning/', $this->_output);
$this->assertNoUnwantedPattern('/<b>Fatal error/i', $this->_output);
return $this->_output;
}
function setPref($name, $value)
{
$prefs = $this->_pageParams['prefs'];
$this->assertOk($prefs->setValue($name, $value));
$this->assertEqual($value, $prefs->getValue($name));
}
function getPref($name)
{
return $this->_pageParams['prefs']->getValue($name);
}
function setVar($name, $value)
{
$vars = $this->_pageParams['vars'];
$vars->set($name, $value);
}
function assertOutputContainsItems($items, $m = 'assertWantedPattern')
{
$fail = false;
foreach ($items as $item) {
$pattern = '!>' . preg_quote($item, '!') . '</a>!';
if (!$this->$m($pattern, $this->_output)) {
$fail = true;
}
}
if ($fail) {
print $this->_output;
}
return !$fail;
}
function assertOutputDoesNotContainItems($items)
{
return $this->assertOutputContainsItems($items,
'assertNoUnwantedPattern');
}
function test_getting_page_shows_all_contacts_and_groups_from_test_addressbook()
{
$this->getPage();
$this->assertOutputContainsItems(array_merge($this->_sortedByLastname, $this->_groups));
}
function test_getting_page_with_sort_parameters_updates_sort_preferences()
{
$this->setPref('sortorder', '');
$this->setVar('sortby', '0');
$this->setVar('sortdir', '1');
$this->getPage();
$this->assertEqual(serialize(array(array('field' => 'lastname', 'ascending' => false))),
$this->getPref('sortorder'));
}
function test_getting_page_with_show_equals_contacts_will_show_only_contacts()
{
$this->setVar('show', 'contacts');
$this->getPage();
$this->assertOutputContainsItems($this->_sortedByLastname);
$this->assertOutputDoesNotContainItems($this->_groups);
}
function test_getting_page_with_show_equals_lists_will_show_only_groups()
{
$this->setVar('show', 'lists');
$this->getPage();
$this->assertOutputDoesNotContainItems($this->_sortedByLastname);
$this->assertOutputContainsItems($this->_groups);
}
function test_browsing_list_shows_list_members_only()
{
$groupId = 'ggg';
$this->setVar('key', $groupId);
$this->getPage();
$found = false;
foreach ($this->_fixtures as $fixture) {
if ($fixture['object_id'] == $groupId) {
$found = true;
$this->assertEqual('Group', $fixture['object_type']);
$memberIds = unserialize($fixture['object_members']);
}
}
$this->assertTrue($found);
$inList = array();
$notInList = array();
foreach ($this->_fixtures as $fixture) {
if ($fixture['object_type'] == 'Object') {
if (in_array($fixture['object_id'], $memberIds)) {
$inList[] = $fixture['object_name'];
} else {
$notInList[] = $fixture['object_name'];
}
}
}
$this->assertFalse(empty($inList));
$this->assertOutputContainsItems($inList);
$this->assertFalse(empty($notInList));
$this->assertOutputDoesNotContainItems($notInList);
}
}
|