ILIAS  trunk Revision v11.0_alpha-2662-g519ff7d528f
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 49 of file ilModulesFileTest.php.

References $DIC, and null.

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

◆ tearDown()

ilModulesFileTest::tearDown ( )
protected

Definition at line 86 of file ilModulesFileTest.php.

References $DIC, and $dic_backup.

86  : void
87  {
88  global $DIC;
89  $DIC = $this->dic_backup;
90  }
global $DIC
Definition: shib_login.php:26

◆ testAppendStream()

ilModulesFileTest::testAppendStream ( )

Definition at line 94 of file ilModulesFileTest.php.

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

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