/usr/share/php/tests/Horde_Kolab_Storage/Horde/Kolab/Storage/Scenario.php is in php-horde-kolab-storage 2.0.5-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 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 | <?php
/**
* Base for PHPUnit scenarios.
*
* PHP version 5
*
* @category Kolab
* @package Kolab_Test
* @author Gunnar Wrobel <wrobel@pardus.de>
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
* @link http://pear.horde.org/index.php?package=Kolab_Storage
*/
/**
* Base for PHPUnit scenarios.
*
* Copyright 2008-2013 Horde LLC (http://www.horde.org/)
*
* See the enclosed file COPYING for license information (LGPL). If you
* did not receive this file, see http://www.horde.org/licenses/lgpl21.
*
* @category Kolab
* @package Kolab_Test
* @author Gunnar Wrobel <wrobel@pardus.de>
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
* @link http://pear.horde.org/index.php?package=Kolab_Storage
*/
class Horde_Kolab_Storage_Scenario extends Horde_Kolab_Server_Integration_Scenario
{
/**
* Handle a "given" step.
*
* @param array &$world Joined "world" of variables.
* @param string $action The description of the step.
* @param array $arguments Additional arguments to the step.
*
* @return mixed The outcome of the step.
*/
public function runGiven(&$world, $action, $arguments)
{
switch ($action) {
case 'an empty Kolab storage':
$world['storage'] = $this->prepareEmptyKolabStorage();
break;
case 'a Kolab setup':
$result = $this->prepareKolabSetup();
$world['server'] = &$result['server'];
$world['storage'] = &$result['storage'];
$world['auth'] = &$result['auth'];
break;
case 'a populated Kolab setup':
$result = $this->prepareBasicSetup();
$world['server'] = &$result['server'];
$world['storage'] = &$result['storage'];
$world['auth'] = &$result['auth'];
break;
default:
return parent::runGiven($world, $action, $arguments);
}
}
/**
* Handle a "when" step.
*
* @param array &$world Joined "world" of variables.
* @param string $action The description of the step.
* @param array $arguments Additional arguments to the step.
*
* @return mixed The outcome of the step.
*/
public function runWhen(&$world, $action, $arguments)
{
switch($action) {
case 'create a Kolab default calendar with name':
$folder = $world['storage']->getNewFolder();
$folder->setName($arguments[0]);
$world['folder_creation'] = $folder->save(array('type' => 'event',
'default' => true));
$folder->setACL(Auth::getAuth(), 'alrid');
break;
case 'allow a group full access to a folder':
$folder = $world['storage']->getFolder($arguments[1]);
$folder->setACL($arguments[0], 'alrid');
break;
case 'retrieving the list of shares for the application':
$shares = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Share')->create($arguments[0], 'kolab');
$world['list'] = $shares->listShares(Auth::getAuth());
break;
case 'logging in as a user with a password':
$world['login'] = $world['auth']->authenticate($arguments[0],
array('password' => $arguments[1]));
$world['storage'] = $this->prepareEmptyKolabStorage();
return parent::runWhen($world, $action, $arguments);
default:
return parent::runWhen($world, $action, $arguments);
}
}
/**
* Handle a "then" step.
*
* @param array &$world Joined "world" of variables.
* @param string $action The description of the step.
* @param array $arguments Additional arguments to the step.
*
* @return mixed The outcome of the step.
*/
public function runThen(&$world, $action, $arguments)
{
switch($action) {
case 'the creation of the folder was successful':
$this->assertNoError($world['folder_creation']);
break;
case 'the list contains a share named':
$this->assertNoError($world['list']);
$this->assertContains($arguments[0],
array_keys($world['list']));
break;
default:
return parent::runThen($world, $action, $arguments);
}
}
/**
* Prepare a Kolab server with some basic entries.
*
* @return Horde_Kolab_Server The empty server.
*/
public function &prepareBasicSetup()
{
$world = &$this->prepareKolabSetup();
$this->addBasicUsersToServer($world['server']);
return $world;
}
/**
* Prepare an empty Kolab storage.
*
* @return Horde_Kolab_Storage_List The empty storage.
*/
public function prepareEmptyKolabStorage($params = null)
{
/** Prepare a Kolab test storage */
if (empty($params)) {
$params = array('driver' => 'Mock',
'username' => 'test',
'password' => 'test');
}
$storage = Horde_Kolab_Storage::singleton('imap', $params);
return $storage;
}
/**
* Prepare the browser setup.
*
* @return NULL
*/
public function prepareBrowser()
{
/** Provide a browser setup */
$GLOBALS['browser'] = new Horde_Browser();
}
protected function getConfiguration()
{
$data = <<<EOD
\$conf['use_ssl'] = 2;
\$conf['server']['name'] = \$_SERVER['SERVER_NAME'];
\$conf['server']['port'] = \$_SERVER['SERVER_PORT'];
\$conf['debug_level'] = E_ALL;
\$conf['umask'] = 077;
\$conf['compress_pages'] = true;
\$conf['menu']['always'] = false;
\$conf['portal']['fixed_blocks'] = array();
\$conf['imsp']['enabled'] = false;
/** Additional config variables required for a clean Horde configuration */
\$conf['session']['use_only_cookies'] = false;
\$conf['session']['timeout'] = 0;
\$conf['cookie']['path'] = '/';
\$conf['cookie']['domain'] = \$_SERVER['SERVER_NAME'];
\$conf['use_ssl'] = false;
\$conf['session']['cache_limiter'] = null;
\$conf['session']['name'] = 'Horde';
\$conf['log']['enabled'] = false;
\$conf['prefs']['driver'] = 'session';
\$conf['auth']['driver'] = 'kolab';
\$conf['share']['driver'] = 'kolab';
\$conf['debug_level'] = E_ALL;
/** Make the share driver happy */
\$conf['kolab']['enabled'] = true;
/** Ensure we still use the LDAP test driver */
\$conf['kolab']['server']['driver'] = 'test';
\$conf['kolab']['server']['params']['hashtype'] = 'plain';
/** Ensure that we do not trigger on folder update */
\$conf['kolab']['no_triggering'] = true;
/** Storage location for the free/busy system */
\$conf['fb']['cache_dir'] = '/tmp';
\$conf['kolab']['freebusy']['server'] = 'https://fb.example.org/freebusy';
/** Setup the virtual file system for Kolab */
\$conf['vfs']['params']['all_folders'] = true;
\$conf['vfs']['type'] = 'kolab';
EOD;
return $data;
}
/**
* Prepare the configuration.
*
* @return NULL
*/
public function prepareConfiguration()
{
$fh = fopen(HORDE_BASE . '/config/conf.php', 'w');
$data = $this->getConfiguration();
fwrite($fh, "<?php\n" . $data);
fclose($fh);
}
/**
* Prepare the registry.
*
* @return NULL
*/
public function prepareRegistry()
{
$fh = fopen(HORDE_BASE . '/config/registry.php', 'w');
$data = <<<EOD
\$this->applications['horde'] = array(
'fileroot' => __DIR__ . '/..',
'webroot' => '/',
'initial_page' => 'login.php',
'name' => _("Horde"),
'status' => 'active',
'templates' => __DIR__ . '/../templates',
'provides' => 'horde',
);
EOD;
fwrite($fh, "<?php\n" . $data);
fclose($fh);
if (!file_exists(HORDE_BASE . '/config/registry.d')) {
mkdir(HORDE_BASE . '/config/registry.d');
}
}
/**
* Prepare the notification setup.
*
* @return NULL
*/
public function prepareNotification()
{
$fh = fopen(HORDE_BASE . '/config/nls.php', 'w');
$data = <<<EOD
\$nls['defaults']['language'] = '';
\$nls['languages']['en_US'] = '‭English (American)';
\$nls['aliases']['en'] = 'en_US';
\$nls['spelling']['en_US'] = '-d american';
\$GLOBALS['nls'] = &\$nls;
EOD;
fwrite($fh, "<?php\n" . $data);
fclose($fh);
}
/**
* Prepare a Kolab setup.
*
* @return NULL
*/
public function &prepareKolabSetup($username = 'test', $password = 'test')
{
// Ensure we have a session array. Otherwise the Auth handler will try
// to unset the session and issue a notice.
$_SESSION = array();
$world = array();
$params = array('driver' => 'Mock',
'username' => $username,
'password' => $password);
$world['server'] = $this->getKolabMockServer();
$world['storage'] = $this->prepareEmptyKolabStorage($params);
//$world['auth'] = $this->prepareKolabAuthDriver();
$this->prepareBasicConfiguration();
if (!defined('HORDE_BASE')) {
define('HORDE_BASE', $this->provideHordeBase());
}
if (!file_exists(HORDE_BASE . '/config')) {
$result = mkdir(HORDE_BASE . '/config', 0755, true);
}
/* Ensure that we send no heders when the session is started */
ini_set('session.use_cookies', 0);
ini_set('session.use_only_cookies', 0);
$this->prepareConfiguration();
$this->prepareRegistry();
$this->prepareNotification();
/** Provide the horde registry */
$GLOBALS['registry'] = new Horde_Registry();
$this->prepareFixedConfiguration();
$this->prepareBrowser();
/* Make sure the configuration is correct after initializing the registry */
$this->prepareBasicConfiguration();
return $world;
}
/**
* Fix the read configuration.
*
* @return NULL
*/
public function prepareFixedConfiguration()
{
$GLOBALS['registry']->importConfig('horde');
}
/**
* Prepare a basic Kolab configuration.
*
* @return NULL
*/
public function prepareBasicConfiguration()
{
/** We need a server name for MIME processing */
$_SERVER['SERVER_NAME'] = $this->provideServerName();
$_SERVER['SERVER_PORT'] = 80;
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
}
/**
* Create a new folder.
*
* @param string $name Name of the new folder.
* @param string $type Type of the new folder.
* @param boolean $default Should the new folder be a default folder?
*
* @return Kolab_Folder The new folder.
*/
public function prepareNewFolder(&$storage, $name, $type, $default = false)
{
$folder = $storage->getNewFolder();
$folder->setName($name);
$this->assertNoError($folder->save(array('type' => $type,
'default' => $default)));
return $folder;
}
function provideServerName()
{
return 'localhost';
}
function provideHordeBase()
{
return Horde::getTempDir() . '/test_config';
}
public function authenticate(Horde_Auth_Base $auth, $username = 'test', $password = 'test')
{
$this->assertTrue($auth->authenticate($username,
array('password' => $password)));
$params = array('driver' => 'Mock',
'username' => $username,
'password' => $password);
return $this->prepareEmptyKolabStorage($params);
}
}
/* Stand-in functions if gettext is not available. */
if (!function_exists('_')) {
function _($string)
{
return $string;
}
}
if (!function_exists('ngettext')) {
function ngettext($msgid1, $msgid2, $n)
{
return $n > 1 ? $msgid2 : $msgid1;
}
}
if (!function_exists('bindtextdomain')) {
function bindtextdomain()
{}
}
if (!function_exists('textdomain')) {
function textdomain()
{}
}
|