CWIS Developer Documentation

- Home
- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

FolderFactory--Test.php
Go to the documentation of this file.
1 <?PHP
2 class FolderFactory_Test extends PHPUnit_Framework_TestCase
3 {
4 const TYPE_NAME = "XX-Test-XX";
5 const OWNER_ID = -10;
6
7 function testFactory()
8 {
9 # create a factory tied to a specified owner
10 $Factory = new FolderFactory( self::OWNER_ID );
11
12 # verify that they currently have no folders
13 $this->assertSame(0, $Factory->GetFolderCount() );
14
15 # create a folder for them and verify that the count incrases
16 $Factory->CreateFolder(self::TYPE_NAME, "Test Folder 1", self::OWNER_ID);
17 $this->assertSame(1, $Factory->GetFolderCount() );
18
19 # create a second folder, verify that goes up as well
20 $Factory->CreateFolder(self::TYPE_NAME, "Test Folder 2", self::OWNER_ID);
21 $this->assertSame(2, $Factory->GetFolderCount());
22
23 # get our folder by name
24 $Folder = $Factory->GetFolderByNormalizedName("testfolder1");
25 $this->assertTrue($Folder instanceof Folder);
26
27 # get our folder using GetFolders with a name argument
28 $MatchingFolders = $Factory->GetFolders(
29 self::TYPE_NAME, self::OWNER_ID, "Test Folder 1");
30 $this->assertSame(1, count($MatchingFolders) );
31 $this->assertSame(current($MatchingFolders)->Id(), $Folder->Id() );
32
33 # get our folder using GetFolders with a count argument
34 $MatchingFolders = $Factory->GetFolders(
35 self::TYPE_NAME, self::OWNER_ID, NULL, 0, 1);
36 $this->assertSame(1, count($MatchingFolders) );
37 $this->assertSame(current($MatchingFolders)->Id(), $Folder->Id() );
38
39 # delete this folder
40 $Folder->Delete();
41
42 # verify that the folder is now gone
43 $Folder = $Factory->GetFolderByNormalizedName("testfolder1");
44 $this->assertNull($Folder);
45
46 # get our remaining test folder, give it an item
47 $Folder = $Factory->GetFolderByNormalizedName("testfolder2");
48 $Folder->AppendItem(1);
49
50 # search for that folder using GetFoldersContainingItem
51 $MatchingFolders = $Factory->GetFoldersContainingItem(1, self::TYPE_NAME);
52 $this->assertSame(1, count($MatchingFolders) );
53 $this->assertSame(current($MatchingFolders)->Id(), $Folder->Id() );
54
55 # clean up our remaining test folder
56 $Folder->Delete();
57 $this->assertSame(0, $Factory->GetFolderCount() );
58 }
59
63 static function setUpBeforeClass()
64 {
65 $DB = new Database();
66 $DB->Query("DELETE FROM Folders WHERE OwnerId = ".self::OWNER_ID);
67 $DB->Query("DELETE FROM FolderContentTypes WHERE "
68 ."TypeName='".self::TYPE_NAME."' ");
69 }
70
74 static function tearDownAfterClass()
75 {
76 $DB = new Database();
77 $DB->Query("DELETE FROM Folders WHERE OwnerId = ".self::OWNER_ID);
78 $DB->Query("DELETE FROM FolderContentTypes WHERE "
79 ."TypeName='".self::TYPE_NAME."' ");
80 }
81 }
Database
SQL database abstraction object with smart query caching.
Definition: Database.php:22
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
FolderFactory_Test\tearDownAfterClass
static tearDownAfterClass()
Destroy tables created for testing.
Definition: FolderFactory--Test.php:74
PHP
PHP
Definition: RSSClient--Test.php:12
FolderFactory_Test\OWNER_ID
const OWNER_ID
Definition: FolderFactory--Test.php:5
FolderFactory_Test\testFactory
testFactory()
Definition: FolderFactory--Test.php:7
FolderFactory_Test
Definition: FolderFactory--Test.php:2
FolderFactory_Test\TYPE_NAME
const TYPE_NAME
Definition: FolderFactory--Test.php:4
FolderFactory_Test\setUpBeforeClass
static setUpBeforeClass()
Destroy tables created for testing.
Definition: FolderFactory--Test.php:63