testBrowseUtil.php
5.1 KB
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
<?php
require_once(dirname(__FILE__) . '/../test.php');
require_once(KT_LIB_DIR . '/foldermanagement/folderutil.inc.php');
require_once(KT_LIB_DIR . '/import/fsimportstorage.inc.php');
require_once(KT_LIB_DIR . '/import/bulkimport.inc.php');
class BrowseUtilTestCase extends KTUnitTestCase {
function setup() {
$oRootFolder =& Folder::get(1);
$this->oUser = User::get(1);
$sName = 'BrowseUtilTest' . strftime('%Y%m%d%H%M%S');
$this->oFolder =& KTFolderUtil::add($oRootFolder, $sName, $this->oUser);
}
function tearDown() {
$aOptions = array('ignore_permissions' => true);
KTFolderUtil::delete($this->oFolder, $this->oUser, 'test case', $aOptions);
}
function testFolderOrDocument() {
$oFolder =& KTFolderUtil::add($this->oFolder, 'testFolderOrDocument', $this->oUser);
$this->assertNotError($oFolder);
if(PEAR::isError($oFolder)) return;
$oDocument =& KTDocumentUtil::add($oFolder, 'testFolderOrDocument.txt', $this->oUser, array());
$this->assertNotError($oDocument);
if(PEAR::isError($oDocument)) return;
$sPath = "/Root Folder/" . $this->oFolder->getName() . "/testFolderOrDocument/";
$aReturn =& KTBrowseUtil::folderOrDocument($sPath . 'testFolderOrDocument.txt');
$this->assertEqual($aReturn[0], $oFolder->getID());
$this->assertEqual($aReturn[1], $oDocument->getID());
$this->assertEqual($aReturn[2], NULL);
$bReturn =& KTBrowseUtil::folderOrDocument($sPath . 'testFolderOrDocument.txt/ktcore.delete');
$this->assertEqual($bReturn, false);
$aReturn =& KTBrowseUtil::folderOrDocument($sPath . 'testFolderOrDocument.txt/ktcore.delete', true);
$this->assertEqual($aReturn[0], $oFolder->getID());
$this->assertEqual($aReturn[1], $oDocument->getID());
$this->assertEqual($aReturn[2], 'ktcore.delete');
$aReturn =& KTBrowseUtil::folderOrDocument($sPath);
$this->assertEqual($aReturn[0], $oFolder->getID());
$this->assertEqual($aReturn[1], NULL);
$this->assertEqual($aReturn[2], NULL);
$bReturn =& KTBrowseUtil::folderOrDocument($sPath . 'ktcore.delete');
$this->assertEqual($bReturn, false);
$aReturn =& KTBrowseUtil::folderOrDocument($sPath . 'ktcore.delete', true);
$this->assertEqual($aReturn[0], $oFolder->getID());
$this->assertEqual($aReturn[1], NULL);
$this->assertEqual($aReturn[2], 'ktcore.delete');
}
function _getId($sPath) {
return (int)substr($sPath, strrpos($sPath, '=') + 1);
}
function testBreadcrumbsForFolder() {
$oFolder =& KTFolderUtil::add($this->oFolder, 'testBreadcrumbsForFolder', $this->oUser);
$aBreadcrumbs =& KTBrowseUtil::breadcrumbsForFolder($oFolder, array('final'=>true));
$this->assertEqual($this->_getId($aBreadcrumbs[0]['url']), 1);
$this->assertEqual($aBreadcrumbs[0]['name'], 'Folders');
$this->assertEqual($this->_getId($aBreadcrumbs[1]['url']), $this->oFolder->getId());
$this->assertEqual($aBreadcrumbs[1]['name'], $this->oFolder->getName());
$this->assertNull($aBreadcrumbs[2]['url']);
$this->assertEqual($aBreadcrumbs[2]['name'], $oFolder->getName());
$aBreadcrumbs =& KTBrowseUtil::breadcrumbsForFolder($oFolder, array('final'=>false));
$this->assertEqual($this->_getId($aBreadcrumbs[0]['url']), 1);
$this->assertEqual($aBreadcrumbs[0]['name'], 'Folders');
$this->assertEqual($this->_getId($aBreadcrumbs[1]['url']), $this->oFolder->getId());
$this->assertEqual($aBreadcrumbs[1]['name'], $this->oFolder->getName());
$this->assertEqual($this->_getId($aBreadcrumbs[2]['url']), $oFolder->getId());
$this->assertEqual($aBreadcrumbs[2]['name'], $oFolder->getName());
}
function testBreadcrumbsForDocument() {
$oFolder =& KTFolderUtil::add($this->oFolder, 'testBreadcrumbsForDocument', $this->oUser);
$oDocument =& KTDocumentUtil::add($oFolder, 'testBreadcrumbsForDocument.txt', $this->oUser, array());
$aBreadcrumbs =& KTBrowseUtil::breadcrumbsForDocument($oDocument, array('final'=>true));
$this->assertEqual($this->_getId($aBreadcrumbs[0]['url']), 1);
$this->assertEqual($aBreadcrumbs[0]['name'], 'Folders');
$this->assertEqual($this->_getId($aBreadcrumbs[1]['url']), $this->oFolder->getId());
$this->assertEqual($aBreadcrumbs[1]['name'], $this->oFolder->getName());
$this->assertEqual($this->_getId($aBreadcrumbs[2]['url']), $oFolder->getId());
$this->assertEqual($aBreadcrumbs[2]['name'], $oFolder->getName());
$this->assertNull($aBreadcrumbs[3]['url']);
$this->assertEqual($aBreadcrumbs[3]['name'], $oDocument->getName());
$aBreadcrumbs =& KTBrowseUtil::breadcrumbsForDocument($oDocument, array('final' => false));
$this->assertEqual($this->_getId($aBreadcrumbs[0]['url']), 1);
$this->assertEqual($aBreadcrumbs[0]['name'], 'Folders');
$this->assertEqual($this->_getId($aBreadcrumbs[1]['url']), $this->oFolder->getId());
$this->assertEqual($aBreadcrumbs[1]['name'], $this->oFolder->getName());
$this->assertEqual($this->_getId($aBreadcrumbs[2]['url']), $oFolder->getId());
$this->assertEqual($aBreadcrumbs[2]['name'], $oFolder->getName());
$this->assertEqual($this->_getId($aBreadcrumbs[3]['url']), $oDocument->getId());
$this->assertEqual($aBreadcrumbs[3]['name'], $oDocument->getName());
}
// lots of set up. tbd.
function testInAdminMode() {
}
}