public function setUp()
 {
     $GLOBALS['Language'] = new MockBaseLanguage($this);
     // Mock instanciation
     $controller = new MockDocman_SOAPController();
     $controller->feedback = new MockFeedback();
     $version = new MockDocman_Version();
     $version->setReturnValue('getNumber', 0);
     $this->itemFactory = new MockDocman_ItemFactory();
     $folderFactory = new MockDocman_FolderFactory();
     $this->fileStorage = new MockDocman_FileStorage();
     // Item MD5 Map: id => md5sum
     $this->MD5Map = array(128000 => '99999999999999999999999999999999');
     foreach ($this->MD5Map as $itemId => $md5) {
         $file = new MockDocman_File();
         $file->setReturnValue('getID', $itemId);
         $file->setReturnValue('getCurrentVersion', $version);
         $this->itemFactory->setReturnValue('getItemFromDb', $file, array($itemId));
         $this->itemFactory->setReturnValue('getItemTypeForItem', PLUGIN_DOCMAN_ITEM_TYPE_FILE, array($file));
         $this->fileStorage->setReturnValue('getFileMD5sum', $md5);
     }
     $user = mock('PFUser');
     $user->setReturnValue('getId', 9);
     $userManager = new MockUserManager();
     $userManager->setReturnValue('getUserById', $user);
     $userManager->setReturnValue('getUserByUserName', $user);
     $userManager->setReturnValue('getCurrentUser', $user);
     $controller->setReturnValue('getUser', $user);
     $versionFactory = new MockDocman_VersionFactory();
     $versionFactory->setReturnValue('getAllVersionForItem', array($version));
     $this->lockFactory = new MockDocman_LockFactory();
     $this->permissionManager = new MockPermissionsManager();
     $this->docmanPermissionsManager = new MockDocman_PermissionsManager();
     $this->docmanPermissionsManager->setReturnValue('getLockFactory', $this->lockFactory);
     // Partial mock of Docman_SOAPActions
     $this->action = new Docman_SOAPActions_Test();
     $this->action->setReturnValue('_getItemFactory', $this->itemFactory);
     $this->action->setReturnValue('_getFolderFactory', $folderFactory);
     $this->action->setReturnValue('_checkOwnerChange', 101, array('*', '*'));
     $this->action->setReturnValue('_getUserManagerInstance', $userManager);
     $this->action->setReturnValue('_getVersionFactory', $versionFactory);
     $this->action->setReturnValue('_getPermissionsManagerInstance', $this->permissionManager);
     $this->action->setReturnValue('_getDocmanPermissionsManagerInstance', $this->docmanPermissionsManager);
     $this->action->setReturnValue('_getEventManager', new MockEventManager());
     $this->action->setReturnValue('_getFileStorage', $this->fileStorage);
     $this->action->__construct($controller);
 }
Esempio n. 2
0
 /**
  * Test when the file download succeede
  */
 function testGetSucceede()
 {
     $webDAVDocmanFile = new WebDAVDocmanFileTestVersion($this);
     $webDAVDocmanFile->setReturnValue('getSize', 1);
     $webDAVDocmanFile->setReturnValue('getMaxFileSize', 1);
     $version = new MockDocman_Version();
     $version->setReturnValue('getPath', dirname(__FILE__) . '/_fixtures/test.txt');
     $item = new MockDocman_File();
     $item->setReturnValue('getCurrentVersion', $version);
     $webDAVDocmanFile->setReturnValue('getItem', $item);
     $webDAVDocmanFile->get();
 }
Esempio n. 3
0
 function testCannotDeleteNonExistantVersion()
 {
     // Definition acceptance criteria:
     // test is complete if there is an info flash message that tells version is deleted
     $ctrl = new MockDocman_Controller($this);
     $ctrl->feedback = new MockFeedback($this);
     // Test log message
     $ctrl->feedback->expectOnce('log', array('error', '*'));
     $GLOBALS['Language']->setReturnValue('getText', 'bla');
     $GLOBALS['Language']->expectOnce('getText', array('plugin_docman', 'error_item_not_deleted_unknown_version'));
     // Setup of the test
     $actions = new Docman_ActionsTest($this);
     $ctrl->request = new MockHTTPRequest($this);
     $ctrl->request->setReturnValue('get', '102', array('group_id'));
     $ctrl->request->setReturnValue('get', '344', array('id'));
     $ctrl->request->setReturnValue('get', '1', array('version'));
     $ctrl->request->setReturnValue('valid', true);
     $actions->_controler = $ctrl;
     $item = new MockDocman_File($this);
     $item->expectNever('accept');
     $if = new MockDocman_ItemFactory($this);
     $if->setReturnValue('getItemFromDb', $item, array(344));
     $if->setReturnValue('getItemTypeForItem', PLUGIN_DOCMAN_ITEM_TYPE_FILE);
     $actions->setReturnValue('_getItemFactory', $if);
     $actions->expectOnce('_getItemFactory', array(102));
     $vf = new MockDocman_VersionFactory($this);
     $v1 = new MockDocman_Version($this);
     $v1->setReturnValue('getNumber', 0);
     $v1->setReturnValue('getLabel', 'label 4');
     $v2 = new MockDocman_Version($this);
     $v2->setReturnValue('getNumber', 2);
     $v2->setReturnValue('getLabel', 'label 5');
     $vf->setReturnValue('getAllVersionForItem', array($v1, $v2));
     $actions->setReturnValue('_getVersionFactory', $vf);
     $actions->setReturnValue('_getEventManager', new MockEventManager($this));
     // Run test
     $actions->deleteVersion();
 }
Esempio n. 4
0
 function testRestoreDeletedItemFileWithAllVersionRestoreFailure()
 {
     $itemFactory = new Docman_ItemFactoryTestRestore($this);
     $item = new MockDocman_File($this);
     $item->setReturnValue('getId', 112);
     $item->setReturnValue('getGroupId', 114);
     $itemFactory->setReturnValue('getItemTypeForItem', PLUGIN_DOCMAN_ITEM_TYPE_FILE);
     $dao = new MockDocman_ItemDao($this);
     $dao->expectNever('restore');
     $itemFactory->setReturnValue('_getItemDao', $dao);
     $v1 = new MockDocman_Version($this);
     $v2 = new MockDocman_Version($this);
     $versionFactory = new MockDocman_VersionFactory($this);
     $versionFactory->expectOnce('listVersionsToPurgeForItem', array($item));
     $versionFactory->setReturnValue('listVersionsToPurgeForItem', array($v1, $v2));
     $versionFactory->expectAt(0, 'restore', array($v1));
     $versionFactory->setReturnValueAt(0, 'restore', false);
     $versionFactory->expectAt(1, 'restore', array($v2));
     $versionFactory->setReturnValueAt(1, 'restore', false);
     $itemFactory->setReturnValue('_getVersionFactory', $versionFactory);
     // Event
     $itemFactory->expectNever('_getEventManager');
     $this->assertFalse($itemFactory->restore($item));
 }
Esempio n. 5
0
 function testRestoreOneVersion()
 {
     $filePath = dirname(__FILE__) . '/_fixtures/version.test';
     touch($filePath);
     $versionFactory = new Docman_VersionFactoryTestVersion($this);
     $dao = new MockDocman_VersionDao($this);
     $versionFactory->setReturnValue('_getVersionDao', $dao);
     $dar = new MockDataAccessResult($this);
     $dar->setReturnValue('isError', false);
     $dar->setReturnValue('getRow', array('purge_date' => null, 'label' => 'Ho hisse la saucisse', 'path' => $filePath));
     $dao->expectOnce('searchDeletedVersion', array(1664, 2));
     $dao->setReturnValue('searchDeletedVersion', $dar);
     $file = new MockDocman_File($this);
     $file->setReturnValue('getGroupId', 114);
     $if = new MockDocman_ItemFactory($this);
     $if->expectOnce('getItemFromDb', array(1664, array('ignore_deleted' => true)));
     $if->setReturnValue('getItemFromDb', $file);
     $versionFactory->setReturnValue('_getItemFactory', $if);
     $user = new MockUser($this);
     $um = new MockUserManager($this);
     $um->setReturnValue('getCurrentUser', $user);
     $versionFactory->setReturnValue('_getUserManager', $um);
     $em = new MockEventManager($this);
     $em->expectOnce('processEvent', array('plugin_docman_event_restore_version', array('group_id' => 114, 'item' => $file, 'old_value' => '2 (Ho hisse la saucisse)', 'user' => $user)));
     $versionFactory->setReturnValue('_getEventManager', $em);
     $dao->expectOnce('restore', array(1664, 2));
     $dao->setReturnValue('restore', true);
     $version = new MockDocman_Version($this);
     $version->setReturnValue('getNumber', 2);
     $version->setReturnValue('getItemId', 1664);
     $this->assertTrue($versionFactory->restore($version));
     unlink($filePath);
 }