ILIAS  release_8 Revision v8.24
ilModulesFileTest Class Reference
+ Inheritance diagram for ilModulesFileTest:
+ Collaboration diagram for ilModulesFileTest:

Public Member Functions

 testAppendStream ()
 

Protected Member Functions

 setUp ()
 
 tearDown ()
 

Protected Attributes

 $storage_mock
 
 $db_mock
 
 $manager_mock
 

Private Attributes

ILIAS DI Container $dic_backup = null
 

Detailed Description

Definition at line 32 of file ilModulesFileTest.php.

Member Function Documentation

◆ setUp()

ilModulesFileTest::setUp ( )
protected

Definition at line 45 of file ilModulesFileTest.php.

45 : void
46 {
47 global $DIC;
48 $this->dic_backup = is_object($DIC) ? clone $DIC : $DIC;
49
50 $DIC = new Container();
51 $DIC['resource_storage'] = $this->storage_mock = $this->createMock(Services::class);
52 $this->manager_mock = $this->createMock(Manager::class);
53 $DIC['ilUser'] = $this->createMock(ilObjUser::class);
54 $DIC['ilUser']->expects($this->any())->method('getPref')->willReturn('en');
55 $DIC['ilDB'] = $this->db_mock = $this->createMock(ilDBInterface::class);
56 $DIC['upload'] = $this->createMock(FileUpload::class);
57 $DIC['ilias'] = $this->createMock(ILIAS::class);
58 $DIC['objDefinition'] = $this->createMock(ilObjectDefinition::class);
59 $DIC['ilLog'] = $this->createMock(ilLogger::class);
60 $DIC['ilErr'] = $this->createMock(ilErrorHandling::class);
61 $DIC['tree'] = $this->createMock(ilTree::class);
62 $DIC['tpl'] = $this->createMock(ilGlobalTemplateInterface::class);
63 $DIC['ilClientIniFile'] = $this->createMock(ilIniFile::class);
64 $DIC['ilAccess'] = $this->createMock(ilAccess::class);
65 $DIC['ilObjDataCache'] = $this->createMock(ilObjectDataCache::class);
66 $DIC['ilAppEventHandler'] = $this->createMock(ilAppEventHandler::class);
67 $DIC['lng'] = $this->createMock(ilLanguage::class);
68 $DIC['ilCtrl'] = $this->createMock(ilCtrlInterface::class);
69 /* $DIC['ilCtrl'] = $this->getMockBuilder(ilCtrl::class)
70 ->disableOriginalConstructor()
71 ->disableArgumentCloning()
72 ->getMock();*/
73
74 if (!defined('ILIAS_LOG_ENABLED')) {
75 define('ILIAS_LOG_ENABLED', false);
76 }
77 if (!defined('DEBUG')) {
78 define('DEBUG', false);
79 }
80 }
Customizing of pimple-DIC for ILIAS.
Definition: Container.php:32
global $DIC
Definition: feed.php:28

References $DIC.

◆ tearDown()

ilModulesFileTest::tearDown ( )
protected

Definition at line 82 of file ilModulesFileTest.php.

82 : void
83 {
84 global $DIC;
86 }
ILIAS DI Container $dic_backup

References $DIC, and $dic_backup.

◆ testAppendStream()

ilModulesFileTest::testAppendStream ( )

Definition at line 88 of file ilModulesFileTest.php.

88 : void
89 {
90 $title = 'Revision One';
91 $file_stream = Streams::ofString('Test Content');
92
93 $this->storage_mock->expects($this->any())
94 ->method('manage')
95 ->willReturn($this->manager_mock);
96
97 // Create File Object with disabled news notification
98 $file = new ilObjFile();
99 $r = new ReflectionClass(ilObjFile::class);
100 $property = $r->getProperty('just_notified');
101 $property->setAccessible(true);
102 $property->setValue($file, true);
103 $file->setMode(ilObjFile::MODE_FILELIST);
104 $this->db_mock->expects($this->any())
105 ->method('fetchAssoc')
106 ->willReturn(
107 [
108 'last_update' => '',
109 'create_date' => ''
110 ]
111 );
112 $file->create();
113
114 // identification
115 $rid = new ResourceIdentification('the_identification');
116
117 $this->manager_mock->expects($this->any())
118 ->method('find')
119 ->withConsecutive(['-'], ['the_identification'], ['the_identification'])
120 ->willReturnOnConsecutiveCalls(null, $rid, $rid);
121
122 $this->manager_mock->expects($this->once())
123 ->method('stream')
124 ->with($file_stream, new ilObjFileStakeholder(0), $title)
125 ->willReturn($rid);
126
127 $revision = new FileRevision($rid);
128 $revision->setVersionNumber(1);
129 $revision->setTitle($title);
130 $resource = new StorableFileResource($rid);
131 $resource->addRevision($revision);
132
133 $this->manager_mock->expects($this->once())
134 ->method('getCurrentRevision')
135 ->with($rid)
136 ->willReturn($revision);
137
138
139 $this->manager_mock->expects($this->any())
140 ->method('getResource')
141 ->with($rid)
142 ->willReturn($resource);
143
144 $revision_number = $file->appendStream($file_stream, $title);
145 $this->assertEquals(1, $revision_number);
146 $this->assertEquals(1, $file->getVersion());
147 $this->assertEquals($title, $file->getTitle());
148 }
Class ilObjFileStakeholder.
Class ilObjFile.
const MODE_FILELIST

References ilObjFile\MODE_FILELIST.

Field Documentation

◆ $db_mock

ilModulesFileTest::$db_mock
protected

Definition at line 42 of file ilModulesFileTest.php.

◆ $dic_backup

ILIAS DI Container ilModulesFileTest::$dic_backup = null
private

Definition at line 34 of file ilModulesFileTest.php.

Referenced by tearDown().

◆ $manager_mock

ilModulesFileTest::$manager_mock
protected

Definition at line 43 of file ilModulesFileTest.php.

◆ $storage_mock

ilModulesFileTest::$storage_mock
protected

Definition at line 38 of file ilModulesFileTest.php.


The documentation for this class was generated from the following file: