ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
ilModulesFileTest Class Reference
+ Inheritance diagram for ilModulesFileTest:
+ Collaboration diagram for ilModulesFileTest:

Public Member Functions

 testAppendStream ()
 

Protected Member Functions

 setUp ()
 
 tearDown ()
 

Protected Attributes

MockObject $storage_mock = null
 
MockObject $db_mock = null
 
MockObject $manager_mock
 

Private Attributes

Container $dic_backup = null
 

Detailed Description

Definition at line 36 of file ilModulesFileTest.php.

Member Function Documentation

◆ setUp()

ilModulesFileTest::setUp ( )
protected

Definition at line 52 of file ilModulesFileTest.php.

52 : void
53 {
54 global $DIC;
55 $this->dic_backup = is_object($DIC) ? clone $DIC : null;
56
57 $DIC = new Container();
58 $DIC['resource_storage'] = $this->storage_mock = $this->createMock(Services::class);
59 $this->manager_mock = $this->createMock(Manager::class);
60 $DIC['ilUser'] = $this->createMock(ilObjUser::class);
61 $DIC['ilUser']->method('getPref')->willReturn('en');
62 $DIC['ilDB'] = $this->db_mock = $this->createMock(ilDBInterface::class);
63 $DIC['upload'] = $this->createMock(FileUpload::class);
64 $DIC['ilias'] = $this->createMock(ILIAS::class);
65 $DIC['objDefinition'] = $this->createMock(ilObjectDefinition::class);
66 $DIC['ilLog'] = $this->createMock(ilLogger::class);
67 $DIC['ilErr'] = $this->createMock(ilErrorHandling::class);
68 $DIC['tree'] = $this->createMock(ilTree::class);
69 $DIC['tpl'] = $this->createMock(ilGlobalTemplateInterface::class);
70 $DIC['ilClientIniFile'] = $this->createMock(ilIniFile::class);
71 $DIC['ilAccess'] = $this->createMock(ilAccess::class);
72 $DIC['ilObjDataCache'] = $this->createMock(ilObjectDataCache::class);
73 $DIC['ilAppEventHandler'] = $this->createMock(ilAppEventHandler::class);
74 $DIC['lng'] = $this->createMock(ilLanguage::class);
75 $DIC['ilCtrl'] = $this->createMock(ilCtrlInterface::class);
76 $DIC['refinery'] = $this->createMock(Factory::class);
77 $DIC['http'] = $this->createMock(\ILIAS\HTTP\Services::class);
78 $DIC['object.customicons.factory'] = $this->createMock(IconFactory::class);
79 /* $DIC['ilCtrl'] = $this->getMockBuilder(ilCtrl::class)
80 ->disableOriginalConstructor()
81 ->disableArgumentCloning()
82 ->getMock();*/
83
84 if (!defined('ILIAS_LOG_ENABLED')) {
85 define('ILIAS_LOG_ENABLED', false);
86 }
87 }
Customizing of pimple-DIC for ILIAS.
Definition: Container.php:38
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.
global $DIC
Definition: shib_login.php:26

References $DIC.

◆ tearDown()

ilModulesFileTest::tearDown ( )
protected

Definition at line 89 of file ilModulesFileTest.php.

89 : void
90 {
91 global $DIC;
93 }

References $DIC, and $dic_backup.

◆ testAppendStream()

ilModulesFileTest::testAppendStream ( )

Definition at line 97 of file ilModulesFileTest.php.

97 : void
98 {
99 $this->markTestSkipped('Failed for some unknown reason.');
100
101 // DB mock
102 $title = 'Revision One';
103 $file_stream = Streams::ofString('Test Content');
104
105 $this->storage_mock
106 ->method('manage')
107 ->willReturn($this->manager_mock);
108
109 $this->db_mock
110 ->method('query')
111 ->willReturnCallback(function ($query): MockObject {
112 $mock_object = $this->createMock(ilDBStatement::class);
113 $mock_object->method('fetchAssoc')->willReturn([$query]);
114
115 return $mock_object;
116 });
117
118 $this->db_mock
119 ->method('fetchAssoc')
120 ->willReturnCallback(function (ilDBStatement $statement): ?array {
121 $row = $statement->fetchAssoc();
122 $query = '';
123 if ($row !== null) {
124 $query = end($row);
125 }
126 if (str_contains($query, 'last_update')) {
127 return [
128 'last_update' => '',
129 'create_date' => ''
130 ];
131 }
132
133 return null;
134 });
135
136 // Create File Object with disabled news notification
137 $file = $this->getMockBuilder(ilObjFile::class)
138 ->onlyMethods(['update'])
139 ->getMock();
140 $file->method('update');
141
142 $r = new ReflectionClass(ilObjFile::class);
143 $property = $r->getProperty('just_notified');
144 $property->setValue($file, true);
145 $file->setMode(ilObjFile::MODE_FILELIST);
146 $this->db_mock
147 ->method('fetchAssoc')
148 ->willReturn(
149 [
150 'last_update' => '',
151 'create_date' => ''
152 ]
153 );
154 $file->create();
155
156 // identification
157 $rid = new ResourceIdentification('the_identification');
158
159 $consecutive = [
160 ['-', null],
161 ['the_identification', $rid],
162 ['the_identification', $rid],
163 ];
164 $this->manager_mock
165 ->method('find')
166 ->willReturnCallback(
167 function (string $id) use (&$consecutive): ?ResourceIdentification {
168 $expected = array_shift($consecutive);
169 [$eid, $ret] = $consecutive;
170 $this->assertEquals($eid, $id);
171 return $ret;
172 }
173 );
174
175 $this->manager_mock->expects($this->once())
176 ->method('stream')
177 ->with($file_stream, new ilObjFileStakeholder(0), $title)
178 ->willReturn($rid);
179
180 $revision = new FileRevision($rid);
181 $revision->setVersionNumber(1);
182 $revision->setTitle($title);
183 $resource = new StorableFileResource($rid);
184 $resource->addRevision($revision);
185
186 $this->manager_mock->expects($this->once())
187 ->method('getCurrentRevision')
188 ->with($rid)
189 ->willReturn($revision);
190
191 $this->manager_mock->expects($this->atLeastOnce())
192 ->method('getResource')
193 ->with($rid)
194 ->willReturn($resource);
195
196 $revision_number = $file->appendStream($file_stream, $title);
197 $this->assertEquals(1, $revision_number);
198 $this->assertEquals(1, $file->getVersion());
199 $this->assertEquals($title, $file->getTitle());
200 }
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
Class ilObjFileStakeholder.
const MODE_FILELIST
Interface ilDBStatement.

References $id, ilDBStatement\fetchAssoc(), and ilObjFile\MODE_FILELIST.

+ Here is the call graph for this function:

Field Documentation

◆ $db_mock

MockObject ilModulesFileTest::$db_mock = null
protected

Definition at line 46 of file ilModulesFileTest.php.

◆ $dic_backup

Container ilModulesFileTest::$dic_backup = null
private

Definition at line 38 of file ilModulesFileTest.php.

Referenced by tearDown().

◆ $manager_mock

MockObject ilModulesFileTest::$manager_mock
protected

Definition at line 50 of file ilModulesFileTest.php.

◆ $storage_mock

MockObject ilModulesFileTest::$storage_mock = null
protected

Definition at line 42 of file ilModulesFileTest.php.


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