/usr/share/php/tests/Horde_Share/Horde/Share/Kolab/UnitTest.php is in php-horde-share 2.0.4-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 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 | <?php
/**
* Unit testing for the Kolab driver.
*
* PHP version 5
*
* @category Horde
* @package Share
* @subpackage UnitTests
* @author Gunnar Wrobel <wrobel@pardus.de>
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
* @link http://pear.horde.org/index.php?package=Share
*/
/**
* Unit testing for the Kolab driver.
*
* Copyright 2011-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 Horde
* @package Share
* @subpackage UnitTests
* @author Gunnar Wrobel <wrobel@pardus.de>
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
* @link http://pear.horde.org/index.php?package=Share
*/
class Horde_Share_Kolab_UnitTest
extends PHPUnit_Framework_TestCase
{
public function setUp()
{
if (!interface_exists('Horde_Kolab_Storage')) {
$this->markTestSkipped('The Kolab_Storage package seems to be unavailable.');
}
}
public function testGetStorage()
{
$storage = $this->getMock('Horde_Kolab_Storage');
$list = $this->getMock('Horde_Kolab_Storage_List');
$storage->expects($this->once())
->method('getList')
->will($this->returnValue($list));
$driver = $this->_getDriver();
$driver->setStorage($storage);
$this->assertSame($list, $driver->getList());
}
/**
* @expectedException Horde_Share_Exception
*/
public function testStorageMissing()
{
$driver = $this->_getDriver();
$driver->getStorage();
}
public function testListArray()
{
$this->assertInternalType(
'array',
$this->_getCompleteDriver()->listShares('john')
);
}
public function testGetTypeString()
{
$driver = new Horde_Share_Kolab(
'mnemo', 'john', new Horde_Perms_Null(), new Horde_Share_Stub_Group()
);
$this->assertInternalType('string', $driver->getType());
}
public function testMnemoSupport()
{
$driver = new Horde_Share_Kolab(
'mnemo', 'john', new Horde_Perms_Null(), new Horde_Share_Stub_Group()
);
$this->assertEquals('note', $driver->getType());
}
public function testKronolithSupport()
{
$driver = new Horde_Share_Kolab(
'kronolith', 'john', new Horde_Perms_Null(), new Horde_Share_Stub_Group()
);
$this->assertEquals('event', $driver->getType());
}
public function testTurbaSupport()
{
$driver = new Horde_Share_Kolab(
'turba', 'john', new Horde_Perms_Null(), new Horde_Share_Stub_Group()
);
$this->assertEquals('contact', $driver->getType());
}
public function testNagSupport()
{
$driver = new Horde_Share_Kolab(
'nag', 'john', new Horde_Perms_Null(), new Horde_Share_Stub_Group()
);
$this->assertEquals('task', $driver->getType());
}
/**
* @expectedException Horde_Share_Exception
*/
public function testSupportException()
{
$driver = new Horde_Share_Kolab(
'NOTSUPPORTED', 'john', new Horde_Perms_Null(), new Horde_Share_Stub_Group()
);
}
public function testListIds()
{
$this->assertEquals(
array('internal_id'),
array_keys(
$this->_getPrefilledDriver()->listShares('john')
)
);
}
/**
* @expectedException Horde_Share_Exception
*/
public function testUndefinedId()
{
$object = new Horde_Share_Object_Kolab(null, new Horde_Group_Mock());
$object->getId();
}
/**
* @expectedException Horde_Share_Exception
*/
public function testUndefinedName()
{
$object = new Horde_Share_Object_Kolab(null, new Horde_Group_Mock());
$object->getName();
}
public function testUndefinedPermissionId()
{
$object = new Horde_Share_Object_Kolab(null, new Horde_Group_Mock());
$this->assertInternalType(
'string',
$object->getPermissionId()
);
}
public function testIdFromName()
{
$share = $this->_getCompleteDriver();
$object = $share->newShare('john', 'IGNORED', 'test');
$this->assertEquals(
array('john', 'test', 'INBOX'), $this->_decodeId($object->getId())
);
}
public function testObjectId()
{
$object = new Horde_Share_Object_Kolab('test', new Horde_Group_Mock());
$this->assertEquals('test', $object->getId());
}
public function testObjectName()
{
$object = new Horde_Share_Object_Kolab('test', new Horde_Group_Mock());
$this->assertEquals('test', $object->getName());
}
public function testGetShare()
{
$result = $this->_decodeId(
$this->_getPrefilledDriver()->getShare('internal_id')->getId()
);
$this->assertContains('john', $result);
$this->assertContains('Calendar', $result);
}
public function testGetShareName()
{
$this->assertEquals(
'internal_id',
$this->_getPrefilledDriver()->getShare('internal_id')->getName()
);
}
public function testExistsByName()
{
$this->assertTrue(
$this->_getPrefilledDriver()->exists('internal_id')
);
}
public function testDoesNotExists()
{
$this->assertFalse(
$this->_getPrefilledDriver()->exists($this->_getId('john', 'DOES_NOT_EXIST'))
);
}
public function testIdExists()
{
$this->assertTrue(
$this->_getPrefilledDriver()->idExists($this->_getId('john', 'Calendar'))
);
}
public function testIdDoesNotExists()
{
$this->assertFalse(
$this->_getPrefilledDriver()->idExists($this->_getId('john', 'DOES_NOT_EXIST'))
);
}
public function testGetShareById()
{
$this->assertEquals(
array('john', 'Calendar'),
$this->_decodeId(
$this->_getPrefilledDriver()
->getShareById($this->_getId('john', 'Calendar'))
->getId()
)
);
}
/**
* @expectedException Horde_Exception_NotFound
*/
public function testMissingShare()
{
$this->_getPrefilledDriver()->getShareById('DOES_NOT_EXIST');
}
public function testShareOwner()
{
$this->assertEquals(
'john',
$this->_getPrefilledDriver()
->getShareById($this->_getId('john', 'Calendar'))
->get('owner')
);
}
public function testShareName()
{
$this->assertEquals(
'Calendar',
$this->_getPrefilledDriver()
->getShareById($this->_getId('john', 'Calendar'))
->get('name')
);
}
public function testShareDescription()
{
$this->assertEquals(
'DESCRIPTION',
$this->_getPrefilledDriver()
->getShareById($this->_getId('john', 'Calendar'))
->get('desc')
);
}
public function testShareShareName()
{
$this->assertEquals(
'internal_id',
$this->_getPrefilledDriver()
->getShareById($this->_getId('john', 'Calendar'))
->get('share_name')
);
}
public function testShareFolder()
{
$this->assertEquals(
'INBOX/Calendar',
$this->_getPrefilledDriver()
->getShareById($this->_getId('john', 'Calendar'))
->get('folder')
);
}
public function testShareData()
{
$share = $this->_getPrefilledDriver()
->getShareById($this->_getId('john', 'Calendar'));
$share->set('other', 'OTHER');
$share->save();
$this->assertEquals(
array(
'other' => 'OTHER',
'share_name' => 'internal_id'
),
$this->list
->getQuery(Horde_Kolab_Storage_List_Tools::QUERY_SHARE)
->getParameters('INBOX/Calendar')
);
}
public function testSetDefault()
{
$share = $this->_getPrefilledDriver()
->getShareById($this->_getId('john', 'Calendar'));
$share->set('default', true);
$share->save();
$this->assertTrue(
$this->_getPrefilledDriver()
->getShareById($this->_getId('john', 'Calendar'))
->get('default')
);
}
public function testNewShare()
{
$this->assertEquals(
'john',
$this->_getPrefilledDriver()
->newShare('john', 'IGNORE', 'test')
->get('owner')
);
}
public function testNewShareSupportsName()
{
$this->assertEquals(
'SHARE',
$this->_getPrefilledDriver()
->newShare('john', 'SHARE', 'test')
->getName()
);
}
public function testNewShareData()
{
$share = $this->_getPrefilledDriver()
->newShare('john', 'SHARE', 'test');
$share->set('other', 'OTHER');
$share->save();
$result = $this->list
->getQuery(Horde_Kolab_Storage_List_Tools::QUERY_SHARE)
->getParameters('INBOX/test');
$this->assertEquals(
array(
'other' => 'OTHER',
'share_name' => 'SHARE'
),
$result
);
}
public function testNewShareDelimiter()
{
$this->assertEquals(
'/',
$this->_getPrefilledDriver()
->newShare('john', 'IGNORE', 'test')
->get('delimiter')
);
}
public function testNewShareSubpath()
{
$this->assertEquals(
'test',
$this->_getPrefilledDriver()
->newShare('john', 'IGNORE', 'test')
->get('subpath')
);
}
public function testNewShareFolder()
{
$this->assertEquals(
'INBOX/test',
$this->_getPrefilledDriver()
->newShare('john', 'IGNORE', 'test')
->get('folder')
);
}
public function testNewShareType()
{
$this->assertEquals(
'event',
$this->_getPrefilledDriver()
->newShare('john', 'IGNORE', 'test')
->get('type')
);
}
public function testAddShare()
{
$share = $this->_getPrefilledDriver();
$object = $share->newShare('john', 'IGNORED', 'Test');
$share->addShare($object);
$this->assertEquals(
array('john', 'Test'),
$this->_decodeId(
$share->getShareById($this->_getId('john', 'Test'))->getId()
)
);
}
public function testShareAddedToList()
{
$share = $this->_getPrefilledDriver();
$object = $share->newShare('john', 'SHARE_NAME', 'Test');
$share->addShare($object);
$this->assertContains(
'SHARE_NAME',
array_keys($share->listShares('john'))
);
}
public function testDeleteShare()
{
$share = $this->_getPrefilledDriver();
$object = $share->newShare('john', 'NAME', 'Test');
$share->addShare($object);
$share->removeShare($object);
$this->assertNotContains(
'NAME',
array_keys($share->listShares('john'))
);
}
public function testGetPermission()
{
$share = $this->_getPrefilledDriver();
$object = $share->newShare('john', 'IGNORED', 'Test');
$object->addUserPermission('tina', Horde_Perms::SHOW);
$share->addShare($object);
$this->assertEquals(
array('tina' => Horde_Perms::SHOW),
$share->getShareById($this->_getId('john', 'Test'))
->getPermission()->getUserPermissions()
);
}
public function testSetPermission()
{
$share = $this->_getPrefilledDriver();
$object = $share->newShare('john', 'IGNORED', 'Test');
$object->addUserPermission('tina', Horde_Perms::SHOW);
$share->addShare($object);
$this->assertTrue(
$share->getShareById($this->_getId('john', 'Test'))
->hasPermission('tina', Horde_Perms::SHOW)
);
}
public function testOwnerPermission()
{
$share = $this->_getPrefilledDriver();
$object = $share->newShare('john', 'IGNORED', 'Test');
$share->addShare($object);
$this->assertTrue(
$share->getShareById($this->_getId('john', 'Test'))
->hasPermission('john', Horde_Perms::SHOW)
);
}
public function testNewShareName()
{
$share = $this->_getCompleteDriver();
$object = $share->newShare('john', 'NAME', 'test');
$this->assertEquals('NAME', $object->get('share_name'));
}
public function testConstructFolderName()
{
$share = $this->_getCompleteDriver();
$this->assertEquals('INBOX/test', $share->constructFolderName('john', 'test'));
}
/**
* @expectedException Horde_Share_Exception
*/
public function testConstructFolderNameInComplexNamespace()
{
$share = $this->_getComplexNamespaceDriver();
$this->assertEquals('INBOX/test', $share->constructFolderName('john', 'test'));
}
public function testConstructFolderNameInInbox()
{
$share = $this->_getComplexNamespaceDriver();
$this->assertEquals('INBOX/test', $share->constructFolderName('john', 'test', 'INBOX'));
}
public function testConstructFolderNameInSecond()
{
$share = $this->_getComplexNamespaceDriver();
$this->assertEquals('SECOND/test', $share->constructFolderName('john', 'test', 'SECOND'));
}
public function testSetDescription()
{
$share = $this->_getPrefilledDriver()
->getShareById($this->_getId('john', 'Calendar'));
$share->set('desc', 'NEW');
$share->save();
$query =
$this->assertEquals(
'NEW',
$this->list
->getQuery(Horde_Kolab_Storage_List_Tools::QUERY_SHARE)
->getDescription('INBOX/Calendar')
);
}
public function testSetData()
{
$share = $this->_getPrefilledDriver()
->getShareById($this->_getId('john', 'Calendar'));
$share->set('other', 'OTHER');
$share->save();
$result = $this->list
->getQuery(Horde_Kolab_Storage_List_Tools::QUERY_SHARE)
->getParameters('INBOX/Calendar');
$this->assertEquals('OTHER', $result['other']);
$this->assertEquals('internal_id', $result['share_name']);
}
public function testListShareCache()
{
$storage = $this->getMock('Horde_Kolab_Storage');
$list = $this->getMock('Horde_Kolab_Storage_List_Tools', array(), array(), '', false, false);
$query = $this->getMock('Horde_Kolab_Storage_List_Query_List');
$query->expects($this->once())
->method('listByType')
->will($this->returnValue(array()));
$list->expects($this->exactly(3))
->method('getQuery')
->will($this->returnValue($query));
$storage->expects($this->exactly(3))
->method('getList')
->will($this->returnValue($list));
$driver = $this->_getDriver();
$driver->setStorage($storage);
$driver->listShares('test');
$driver->listShares('test');
}
public function testEditableShares()
{
$this->assertEquals(
1,
count(
$this->_getPermissionDriver()
->listShares('john', array('perm' => Horde_Perms::EDIT))
)
);
}
public function testRootLevel()
{
$this->assertEquals(
3,
count(
$this->_getHierarchyDriver()
->listShares('john', array('all_levels' => false))
)
);
}
private function _getPrefilledDriver()
{
return $this->_getDriverWithData($this->_getPrefilledData());
}
private function _getCompleteDriver()
{
return $this->_getDriverWithData($this->_getCompleteData());
}
private function _getPermissionDriver()
{
return $this->_getDriverWithData($this->_getPermissionData());
}
private function _getHierarchyDriver()
{
return $this->_getDriverWithData($this->_getHierarchyData());
}
private function _getComplexNamespaceDriver()
{
return $this->_getDriverWithData($this->_getComplexNamespaceData());
}
private function _getDriverWithData($data)
{
$factory = new Horde_Kolab_Storage_Factory(
array(
'driver' => 'mock',
'queries' => array(
'list' => array(
Horde_Kolab_Storage_List_Tools::QUERY_BASE => array(
'cache' => true
),
Horde_Kolab_Storage_List_Tools::QUERY_ACL => array(
'cache' => true
),
Horde_Kolab_Storage_List_Tools::QUERY_SHARE => array(
'cache' => true
),
)
),
'params' => $data,
'cache' => new Horde_Cache(
new Horde_Cache_Storage_Mock()
),
'logger' => new Horde_Log_Logger()
)
);
$driver = $this->_getDriver('kronolith');
$this->storage = $factory->create();
$this->list = $this->storage->getList();
$this->list->getListSynchronization()->synchronize();
$driver->setStorage($this->storage);
return $driver;
}
private function _getPrefilledData()
{
return array(
'username' => 'john',
'data' => $this->_getMockData(
array(
'user/john' => array(),
'user/john/Calendar' => array(
'a' => array(
'/shared/vendor/kolab/folder-type' => 'event.default',
'/shared/comment' => 'DESCRIPTION',
'/shared/vendor/horde/share-params' => base64_encode(serialize(array('share_name' => 'internal_id'))),
),
),
)
),
);
}
private function _getCompleteData()
{
return array(
'username' => 'john',
'data' => $this->_getMockData(
array(
'user/john' => null,
)
),
);
}
private function _getComplexNamespaceData()
{
return array(
'username' => 'john',
'data' => $this->_getMockData(
array(
'user/john' => null,
)
),
'namespaces' => array(
array(
'type' => Horde_Kolab_Storage_Folder_Namespace::PERSONAL,
'name' => 'INBOX/',
'delimiter' => '/',
'add' => true,
),
array(
'type' => Horde_Kolab_Storage_Folder_Namespace::PERSONAL,
'name' => 'SECOND/',
'delimiter' => '/',
'add' => true,
),
)
);
}
private function _getPermissionData()
{
return array(
'username' => 'john',
'data' => $this->_getMockData(
array(
'user/john' => array(),
'user/john/Calendar' => array(
't' => 'event.default',
'p' => array('john' => 'alrid'),
),
'user/john/Listable' => array(
't' => 'event',
'p' => array('john' => 'l'),
),
)
),
);
}
private function _getHierarchyData()
{
return array(
'username' => 'john',
'data' => $this->_getMockData(
array(
'user/john' => array(),
'user/john/Calendar' => array('t' => 'event.default'),
'user/john/Calendar/Private' => null,
'user/john/Calendar/Private/Family' => array('t' => 'event'),
'user/john/Calendar/Private/Family/Cooking' => array('t' => 'event'),
'user/john/Calendar/Private/Family/Party' => array('t' => 'event'),
'user/john/Work' => array('t' => 'event'),
)
),
);
}
private function _getDriver($app = 'mnemo')
{
return new Horde_Share_Kolab(
$app, 'john', new Horde_Perms_Null(), new Horde_Share_Stub_Group()
);
}
private function _getMockData($elements)
{
$result = array();
foreach ($elements as $path => $element) {
if (!isset($element['p'])) {
$folder = array('permissions' => array('anyone' => 'alrid'));
} else {
$folder = array('permissions' => $element['p']);
}
if (isset($element['a'])) {
$folder['annotations'] = $element['a'];
}
if (isset($element['t'])) {
$folder['annotations'] = array(
'/shared/vendor/kolab/folder-type' => $element['t'],
);
}
$result[$path] = $folder;
}
return $result;
}
private function _getId($owner, $name)
{
return base64_encode(serialize(array($owner, $name)));
}
private function _decodeId($id)
{
return unserialize(base64_decode($id));
}
}
|