19 declare(strict_types=1);
    36         $database = $this->getMockBuilder(ilDBInterface::class)->disableOriginalConstructor()->getMock();
    37         $access = $this->getMockBuilder(ilAccessHandler::class)->getMock();
    43         $database = $this->getMockBuilder(ilDBInterface::class)->disableOriginalConstructor()->getMock();
    44         $access = $this->getMockBuilder(ilAccessHandler::class)->getMock();
    47         $result = $instance->isPermitted(
'/data/some/path/file.pdf');
    48         $this->assertFalse($result->isOk());
    53         $database = $this->getMockBuilder(ilDBInterface::class)->disableOriginalConstructor()->getMock();
    54         $access = $this->getMockBuilder(ilAccessHandler::class)->getMock();
    55         $statement = $this->getMockBuilder(ilDBStatement::class)->disableOriginalConstructor()->getMock();
    57         $database->expects(self::once())->method(
'queryF')->with(
'SELECT obj_fi FROM qpl_questions WHERE question_id = %s', [
ilDBConstants::T_INTEGER], [383])->willReturn($statement);
    58         $database->expects(self::once())->method(
'fetchAssoc')->with($statement)->willReturn(null);
    61         $result = $instance->isPermitted(
'http://my-ilias/assessment/qst_preview/123/383/fileuploads/my-file.pdf');
    62         $this->assertTrue($result->isOk());
    63         $this->assertFalse($result->value());
    69     public function testWithTypes(?
string $type, 
bool $permitted, ?
string $requires_permission): void
    71         $database = $this->getMockBuilder(ilDBInterface::class)->disableOriginalConstructor()->getMock();
    72         $access = $this->getMockBuilder(ilAccessHandler::class)->getMock();
    73         $statement = $this->getMockBuilder(ilDBStatement::class)->disableOriginalConstructor()->getMock();
    74         $incident = $this->getMockBuilder(Incident::class)->disableOriginalConstructor()->getMock();
    78         $references_of = $this->
expectCall(383, [987], $ref_called);
    79         $type_of = $this->
expectCall(987, $type, $type_called);
    81         $database->expects(self::once())->method(
'queryF')->with(
'SELECT obj_fi FROM qpl_questions WHERE question_id = %s', [
ilDBConstants::T_INTEGER], [383])->willReturn($statement);
    82         $database->expects(self::once())->method(
'fetchAssoc')->with($statement)->willReturn([
'obj_fi' => 
'383']);
    84         $incident->expects(self::once())->method(
'any')->willReturnCallback(
function (callable $call_me, array $ref_ids): 
bool {
    85             $this->assertEquals([987], $ref_ids);
    89         if (null === $requires_permission) {
    90             $access->expects(self::never())->method(
'checkAccess');
    92             $access->expects(self::once())->method(
'checkAccess')->with($requires_permission, 
'', 987)->willReturn($permitted);
    97         $result = $instance->isPermitted(
'http://my-ilias/assessment/qst_preview/123/383/fileuploads/my-file.pdf');
    98         $this->assertTrue($result->isOk());
    99         $this->assertSame($permitted, $result->value());
   101         $this->assertSame(1, $ref_called);
   102         $this->assertSame(1, $type_called);
   105     public static function types(): array
   108             'Type qpl with access rights.' => [
'qpl', 
false, 
'read'],
   109             'Type qpl without access rights.' => [
'qpl', 
true, 
'read'],
   110             'Type tst with access rights.' => [
'tst', 
false, 
'write'],
   111             'Type tst without access rights.' => [
'tst', 
true, 
'write'],
   112             'Type crs will never has access rights.' => [
'crs', 
false, null],
   113             'Unknown types will never have access rights.' => [null, 
false, null],
   119         return function ($value) use ($expected, $return, &$called) {
   120             $this->assertSame($expected, $value);
 
testWithTypes(?string $type, bool $permitted, ?string $requires_permission)
types 
 
expectCall($expected, $return, &$called)
 
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...