CWIS Developer Documentation

- Home
- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

File--Test.php
Go to the documentation of this file.
1 <?PHP
2 class File_Test extends PHPUnit\Framework\TestCase
3 {
8 function testCreate()
9 {
10 $File = File::Create("invalid/path", "testFile");
11 $this->assertSame(File::FILESTAT_DOESNOTEXIST, $File);
12
13 $File = File::Create("objects/tests/files/ZeroLengthFile.txt");
14 $this->assertSame(File::FILESTAT_ZEROLENGTH, $File);
15
16 $File = File::Create("objects/tests/files/ValidFile.txt");
17 $this->assertInstanceOf('File', $File);
18
19 $StoredFilePath = $File->GetNameOfStoredFile();
20
21 $this->assertSame(file_get_contents("objects/tests/files/ValidFile.txt"),
22 file_get_contents($StoredFilePath));
23
24 $File->Destroy();
25 $this->assertFileNotExists($StoredFilePath);
26 }
27
28 function testCreateCopy()
29 {
30 $File = File::Create("objects/tests/files/ValidFile.txt");
31 $Copy = $File->CreateCopy();
32 $this->assertSame($Copy->Name(), $File->Name());
33 $this->assertSame(file_get_contents($Copy->GetNameOfStoredFile()),
34 file_get_contents("objects/tests/files/ValidFile.txt"));
35 $Copy->Destroy();
36 $File->Destroy();
37 }
38
39 function testGetLength()
40 {
41 $File = File::Create("objects/tests/files/ValidFile.txt");
42 $this->assertSame($File->GetLength(), '21');
43 $File->Destroy();
44 }
45
46 function testGetType()
47 {
48 $File = File::Create("objects/tests/files/ValidFile.txt");
49 $this->assertSame($File->GetType(), 'text/plain');
50 $File->Destroy();
51 }
52
53 function testComment()
54 {
55 $File = File::Create("objects/tests/files/ValidFile.txt");
56 $File->Comment("abc123");
57 $this->assertSame($File->Comment(), "abc123");
58 $File->Destroy();
59 }
60
61 function testFieldId()
62 {
63 $File = File::Create("objects/tests/files/ValidFile.txt");
64 $File->FieldId(PHP_INT_MAX);
65 $this->assertSame($File->FieldId(), PHP_INT_MAX);
66 $File->Destroy();
67 }
68
69 function testResourceId()
70 {
71 $File = File::Create("objects/tests/files/ValidFile.txt");
72 $File->ResourceId(PHP_INT_MAX);
73 $this->assertSame($File->ResourceId(), PHP_INT_MAX);
74 $File->Destroy();
75 }
76
77 function testGetMimeType()
78 {
79 $File = File::Create("objects/tests/files/ValidFile.txt");
80 $this->assertSame($File->GetMimeType(), "text/plain");
81 $File->Destroy();
82 }
83
84 function testGetLink()
85 {
86 $File = File::Create("objects/tests/files/ValidFile.txt");
87
88 $GLOBALS["G_PluginManager"]->PluginEnabled("CleanURLs", FALSE);
89 $this->assertSame($File->GetLink(), "index.php?P=DownloadFile&Id=".$File->Id());
90
91 $GLOBALS["G_PluginManager"]->PluginEnabled("CleanURLs", TRUE);
92 $this->assertSame($File->GetLink(), "downloads/".$File->Id()."/ValidFile.txt");
93
94 $File->Destroy();
95 }
96
97 function testGetStorageDirectory()
98 {
99 $File = File::Create("objects/tests/files/ValidFile.txt");
100 $this->assertSame($File->GetStorageDirectory(), "local/data/files");
101 $File->Destroy();
102 }
103 }
File\FILESTAT_ZEROLENGTH
const FILESTAT_ZEROLENGTH
Definition: File.php:22
File_Test\testGetLink
testGetLink()
Definition: File--Test.php:84
File\FILESTAT_DOESNOTEXIST
const FILESTAT_DOESNOTEXIST
Definition: File.php:23
File_Test\testComment
testComment()
Definition: File--Test.php:53
File\Create
static Create($SourceFile, $DesiredFileName=NULL)
Create a new File object using an existing file.
Definition: File.php:34
File_Test\testFieldId
testFieldId()
Definition: File--Test.php:61
File_Test\testGetStorageDirectory
testGetStorageDirectory()
Definition: File--Test.php:97
File_Test\testCreate
testCreate()
Verify that files can be created and return the proper error/success codes.
Definition: File--Test.php:8
PHP
PHP
Definition: RSSClient--Test.php:12
File_Test\testResourceId
testResourceId()
Definition: File--Test.php:69
File_Test\testGetType
testGetType()
Definition: File--Test.php:46
File_Test
Definition: File--Test.php:2
File_Test\testCreateCopy
testCreateCopy()
Definition: File--Test.php:28
File_Test\testGetMimeType
testGetMimeType()
Definition: File--Test.php:77
File_Test\testGetLength
testGetLength()
Definition: File--Test.php:39