ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
ilModulesFileTest Class Reference
+ Inheritance diagram for ilModulesFileTest:
+ Collaboration diagram for ilModulesFileTest:

Public Member Functions

 testAppendStream ()
 disabled More...
 

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 31 of file ilModulesFileTest.php.

Member Function Documentation

◆ setUp()

ilModulesFileTest::setUp ( )
protected

Definition at line 44 of file ilModulesFileTest.php.

References $DIC.

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

◆ tearDown()

ilModulesFileTest::tearDown ( )
protected

Definition at line 81 of file ilModulesFileTest.php.

References $DIC, and $dic_backup.

81  : void
82  {
83  global $DIC;
84  $DIC = $this->dic_backup;
85  }
ILIAS DI Container $dic_backup
global $DIC
Definition: shib_login.php:25

◆ testAppendStream()

ilModulesFileTest::testAppendStream ( )

disabled

Definition at line 91 of file ilModulesFileTest.php.

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

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

Field Documentation

◆ $db_mock

ilModulesFileTest::$db_mock
protected

Definition at line 41 of file ilModulesFileTest.php.

◆ $dic_backup

ILIAS DI Container ilModulesFileTest::$dic_backup = null
private

Definition at line 33 of file ilModulesFileTest.php.

Referenced by tearDown().

◆ $manager_mock

ilModulesFileTest::$manager_mock
protected

Definition at line 42 of file ilModulesFileTest.php.

◆ $storage_mock

ilModulesFileTest::$storage_mock
protected

Definition at line 37 of file ilModulesFileTest.php.


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