CWIS Developer Documentation

- Home
- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

Folder--Test.php
Go to the documentation of this file.
1 <?PHP
2 class Folder_Test extends PHPUnit\Framework\TestCase
3 {
4 const TYPE_NAME = "XX-Test-XX";
5
10 static function tearDownAfterClass()
11 {
12 $DB = new Database();
13 $DB->Query("DELETE FROM FolderContentTypes WHERE "
14 ."TypeName='".self::TYPE_NAME."'");
15 }
16
17
18
23 function testAppendItem()
24 {
25 $Factory = new FolderFactory();
26 $TestFolder = $Factory->CreateFolder("Resource");
27
28 $TestFolder->AppendItem(1);
29 $this->CheckContents( $TestFolder, array(1) );
30
31 $TestFolder->AppendItem(2);
32 $this->CheckContents( $TestFolder, array(1,2) );
33
34 $TestFolder->Delete();
35 }
36
41 function testPrependItem()
42 {
43 $Factory = new FolderFactory();
44 $TestFolder = $Factory->CreateFolder("Resource");
45
46 $TestFolder->PrependItem(1);
47 $this->CheckContents( $TestFolder, array(1) );
48
49 $TestFolder->PrependItem(2);
50 $this->CheckContents( $TestFolder, array(2,1) );
51
52 $TestFolder->Delete();
53 }
54
61 function testInsertItemBefore()
62 {
63 $Factory = new FolderFactory();
64 $TestFolder = $Factory->CreateFolder("Resource");
65
66 # insert to empty list
67 $TestFolder->InsertItemBefore(100, 1);
68 $this->CheckContents($TestFolder, array(1) );
69
70 # insert before non-existent item
71 $TestFolder->InsertItemBefore(100, 2);
72 $this->CheckContents($TestFolder, array(2,1) );
73
74 # insert before beginning
75 $TestFolder->InsertItemBefore(2, 3);
76 $this->CheckContents($TestFolder, array(3,2,1) );
77
78 # insert before end
79 $TestFolder->InsertItemBefore(1, 4);
80 $this->CheckContents($TestFolder, array(3,2,4,1) );
81
82 # insert in the middle
83 $TestFolder->InsertItemBefore(4, 5);
84 $this->CheckContents($TestFolder, array(3,2,5,4,1) );
85
86 $TestFolder->Delete();
87 }
88
95 function testInsertItemAfter()
96 {
97 $Factory = new FolderFactory();
98 $TestFolder = $Factory->CreateFolder("Resource");
99
100 # insert to empty list
101 $TestFolder->InsertItemAfter(100, 1);
102 $this->CheckContents( $TestFolder, array(1) );
103
104 # insert before non-existent item
105 $TestFolder->InsertItemAfter(100, 2);
106 $this->CheckContents( $TestFolder, array(1,2) );
107
108 # insert after beginning
109 $TestFolder->InsertItemAfter(1, 3);
110 $this->CheckContents( $TestFolder, array(1,3,2) );
111
112 # insert after end
113 $TestFolder->InsertItemAfter(2, 4);
114 $this->CheckContents( $TestFolder, array(1,3,2,4) );
115
116 # insert in the middle
117 $TestFolder->InsertItemAfter(3, 5);
118 $this->CheckContents( $TestFolder, array(1,3,5,2,4) );
119
120 $TestFolder->Delete();
121 }
122
132 function testMixedContent()
133 {
134 $Factory = new FolderFactory();
135 $TestFolder = $Factory->CreateMixedFolder();
136
137 $TestFolder->AppendItems( array(1,2,3), self::TYPE_NAME);
138 $this->CheckContentsMixed($TestFolder, array(1,2,3) );
139
140 $TestFolder->Delete();
141 }
142
143
151 function testMiscRemaining()
152 {
153 $Factory = new FolderFactory();
154 $TestFolder = $Factory->CreateFolder("Resource");
155
156 # preload the folder wtih 1:5
157 $TestFolder->AppendItems( array(1,2,3,4,5) );
158 $this->CheckContents( $TestFolder, array(1,2,3,4,5) );
159
160 # test the offset and limit of GetItemIds()
161 $this->assertSame(
162 array(3,4,5), $TestFolder->GetItemIds(2) );
163 $this->assertSame(
164 array(3,4), $TestFolder->GetItemIds(2,2) );
165
166 # test removing items from the beginning, end, and middle of the folder
167 $TestFolder->RemoveItem(1);
168 $this->CheckContents( $TestFolder, array(2,3,4,5) );
169
170 $TestFolder->RemoveItem(5);
171 $this->CheckContents( $TestFolder, array(2,3,4) );
172
173 $TestFolder->RemoveItem(3);
174 $this->CheckContents( $TestFolder, array(2,4) );
175
176 # make sure that the FolderId is an int
177 $this->assertTrue(
178 is_int($TestFolder->Id()) );
179
180 # test the setter/getter methods for this folder
181 $TestFolder->Name("My Test Folder");
182 $this->assertSame(
183 "My Test Folder", $TestFolder->Name() );
184
185 # check the autogenerated normalized name
186 $this->assertSame(
187 "mytestfolder", $TestFolder->Normalizedname());
188
189 $TestFolder->NormalizedName("mynewname");
190 $this->assertSame(
191 "mynewname", $TestFolder->NormalizedName());
192
193 # blank the normalized name so it will reset
194 $TestFolder->NormalizedName('');
195 $this->assertSame(
196 "mytestfolder", $TestFolder->NormalizedName() );
197
198 $TestFolder->OwnerId(5);
199 $this->assertSame(
200 5, $TestFolder->OwnerId() );
201
202 $TestFolder->Note("Test folder note");
203 $this->assertSame(
204 "Test folder note", $TestFolder->Note() );
205
206 $TestFolder->IsShared(1);
207 $this->assertSame(
208 1, $TestFolder->IsShared() );
209
210 # and test folder item notes
211 $TestFolder->NoteForItem( 4, "Test Item Note");
212 $this->assertSame(
213 "Test Item Note", $TestFolder->NoteForItem( 4 ) );
214
215 # test getting an existing folder
216 $TestFolderCopy = new Folder( $TestFolder->Id() );
217
218 # verify that TestFolder and TestFolderCopy refer to the same FolderId
219 $this->assertSame(
220 $TestFolder->Id(),
221 $TestFolderCopy->Id() );
222
223 # test getting a nonexistent folder
224 try {
225 $TestFolderCopy = new Folder(PHP_INT_MAX);
226 $this->assertTrue(FALSE);
227 }
228 catch (Exception $e)
229 {
230 ; // empty on purpose
231 }
232
233 $TestFolder->Delete();
234 }
235
243 private function CheckContents($TestFolder, $TgtItemIds)
244 {
245 $this->assertSame(
246 count($TgtItemIds), $TestFolder->GetItemCount() );
247 $this->assertSame(
248 $TgtItemIds, $TestFolder->GetItemIds() );
249 }
250
258 private function CheckContentsMixed($TestFolder, $TgtItemIds)
259 {
260 $this->assertSame(
261 count($TgtItemIds), $TestFolder->GetItemCount() );
262
263 $TgtVal = array();
264 foreach ($TgtItemIds as $ItemId)
265 {
266 $TgtVal []= array( "ID"=>$ItemId, "Type"=> self::TYPE_NAME);
267 }
268
269 $this->assertSame(
270 $TgtVal, $TestFolder->GetItemIds() );
271 }
272 }
Database
SQL database abstraction object with smart query caching.
Definition: Database.php:22
Folder_Test\testPrependItem
testPrependItem()
Verify that items can be prepended and appear in the correct order.
Definition: Folder--Test.php:41
Folder_Test\testInsertItemBefore
testInsertItemBefore()
Verify that InsertItemBefore() works correctly on empty lists, when the tgt is nonexistent, and at the beginning, middle, and end of a list.
Definition: Folder--Test.php:61
Folder_Test\testAppendItem
testAppendItem()
Verify that items can be appended and appear in the corect order.
Definition: Folder--Test.php:23
FolderFactory
Factory object for Folder class, used to retrieve and manage Folders and groups of Folders...
Definition: FolderFactory.php:14
Folder
Folder object used to create and manage groups of items.
Definition: Folder.php:17
Folder_Test\testMiscRemaining
testMiscRemaining()
Test all remaining misc functions.
Definition: Folder--Test.php:151
Folder_Test\TYPE_NAME
const TYPE_NAME
Definition: Folder--Test.php:4
PHP
PHP
Definition: RSSClient--Test.php:12
Folder_Test\tearDownAfterClass
static tearDownAfterClass()
Delete XX-Test-XX folder conte type that was created for testing.
Definition: Folder--Test.php:10
Folder_Test\testInsertItemAfter
testInsertItemAfter()
Verify that InsertItemAfter() works correctly on empty lists, when the tgt is nonexistent, and at the beginning, middle, and end of a list.
Definition: Folder--Test.php:95
Folder_Test
Definition: Folder--Test.php:2
Folder_Test\testMixedContent
testMixedContent()
Test creation of a mixed content folder with AppendItems() inserting some data into it...
Definition: Folder--Test.php:132