예제 #1
0
 /**
  * testUpdateFolderCache
  */
 public function testUpdateFolderCache()
 {
     $result = $this->_json->updateFolderCache($this->_account->getId(), '');
     // create folders directly on imap server
     $this->_imap->createFolder('test', $this->_testFolderName, $this->_account->delimiter);
     $this->_imap->createFolder('testsub', $this->_testFolderName . $this->_account->delimiter . 'test', $this->_account->delimiter);
     // if something goes wrong, we need to delete these folders in tearDown
     $this->_createdFolders[] = $this->_testFolderName . $this->_account->delimiter . 'test' . $this->_account->delimiter . 'testsub';
     $this->_createdFolders[] = $this->_testFolderName . $this->_account->delimiter . 'test';
     // update cache and check if folder is found
     $result = $this->_json->updateFolderCache($this->_account->getId(), $this->_testFolderName);
     $testfolder = $result[0];
     //print_r($testfolder);
     $this->assertGreaterThan(0, count($result));
     $this->assertEquals($this->_testFolderName . $this->_account->delimiter . 'test', $testfolder['globalname']);
     $this->assertEquals(TRUE, (bool) $testfolder['has_children'], 'should have children');
     // delete subfolder directly on imap server
     $this->_imap->removeFolder($this->_testFolderName . $this->_account->delimiter . 'test' . $this->_account->delimiter . 'testsub');
     array_shift($this->_createdFolders);
     // check if has_children got updated and folder is removed from cache
     $this->_json->updateFolderCache($this->_account->getId(), '');
     $testfolder = $this->_getFolder($this->_testFolderName . $this->_account->delimiter . 'test');
     $this->assertEquals(FALSE, (bool) $testfolder['has_children'], 'should have no children');
     $this->setExpectedException('Tinebase_Exception_NotFound');
     $testfoldersub = $this->_getFolder($this->_testFolderName . $this->_account->delimiter . 'test' . $this->_account->delimiter . 'testsub');
     $this->_imap->removeFolder($this->_testFolderName . $this->_account->delimiter . 'test');
     array_shift($this->_createdFolders);
     // try to update message cache of nonexistant folder
     $this->setExpectedException('Felamimail_Exception_IMAPFolderNotFound');
     $removedTestfolder = $this->_json->updateMessageCache($testfolder['id'], 1);
     // update cache and check if folder is deleted
     $result = $this->_json->updateFolderCache($this->_account->getId(), $this->_testFolderName);
     $this->assertEquals(0, count($result));
 }
 /**
  * Tears down the fixture
  * This method is called after a test is executed.
  *
  * @access protected
  */
 protected function tearDown()
 {
     if (count($this->_createdFolders) > 0) {
         foreach ($this->_createdFolders as $folderName) {
             //echo "delete $folderName\n";
             try {
                 $this->_imap->removeFolder(Expressomail_Model_Folder::encodeFolderName($folderName));
             } catch (Zend_Mail_Storage_Exception $zmse) {
                 // already deleted
             }
         }
         //No necessary with Expressomail
         //           Expressomail_Controller_Cache_Folder::getInstance()->clear($this->_account);
     }
     if (!empty($this->_foldersToClear)) {
         foreach ($this->_foldersToClear as $folderName) {
             // delete test messages from given folders on imap server (search by special header)
             $this->_imap->selectFolder($folderName);
             $result = $this->_imap->search(array('HEADER X-Tine20TestMessage jsontest'));
             //print_r($result);
             foreach ($result as $messageUid) {
                 $this->_imap->removeMessage($messageUid);
             }
             // clear message cache
             $folder = Expressomail_Controller_Folder::getInstance()->getByBackendAndGlobalName($this->_account->getId(), $folderName);
             //No necessary with Expressomail
             //              Expressomail_Controller_Cache_Message::getInstance()->clear($folder);
         }
     }
     // sieve cleanup
     if ($this->_testSieveScriptName !== NULL) {
         Expressomail_Controller_Sieve::getInstance()->setScriptName($this->_testSieveScriptName);
         try {
             Expressomail_Controller_Sieve::getInstance()->deleteScript($this->_account->getId());
         } catch (Zend_Mail_Protocol_Exception $zmpe) {
             // do not delete script if active
         }
         Expressomail_Controller_Account::getInstance()->setVacationActive($this->_account, $this->_oldSieveVacationActiveState);
         if ($this->_oldSieveData !== NULL) {
             $this->_oldSieveData->save();
         }
     }
     if ($this->_oldActiveSieveScriptName !== NULL) {
         Expressomail_Controller_Sieve::getInstance()->setScriptName($this->_oldActiveSieveScriptName);
         Expressomail_Controller_Sieve::getInstance()->activateScript($this->_account->getId());
     }
     // vfs cleanup
     foreach ($this->_pathsToDelete as $path) {
         $webdavRoot = new Sabre_DAV_ObjectTree(new Tinebase_WebDav_Root());
         //echo "delete $path";
         $webdavRoot->delete($path);
     }
 }
 /**
  * test folder status of deleted folder
  *
  * @see 0007134: getFolderStatus should ignore non-existent folders
  */
 public function testGetFolderStatusOfDeletedFolder()
 {
     $this->testCreateFolders();
     // remove one of the created folders
     $removedFolder = $this->_createdFolders[0];
     $this->_imap->removeFolder(Felamimail_Model_Folder::encodeFolderName($removedFolder));
     $status = $this->_json->getFolderStatus(array(array('field' => 'account_id', 'operator' => 'equals', 'value' => $this->_account->getId())));
     $this->assertGreaterThan(2, count($status), 'Expected more than 2 folders that need an update: ' . print_r($status, TRUE));
     foreach ($status as $folder) {
         if ($folder['globalname'] == $removedFolder) {
             $this->fail('removed folder should not appear in status array!');
         }
     }
 }