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());
66 #[\PHPUnit\Framework\Attributes\DataProvider('types')] 67 public function testWithTypes(?
string $type,
bool $permitted, ?
string $requires_permission): void
69 $database = $this->getMockBuilder(ilDBInterface::class)->disableOriginalConstructor()->getMock();
70 $access = $this->getMockBuilder(ilAccessHandler::class)->getMock();
71 $statement = $this->getMockBuilder(ilDBStatement::class)->disableOriginalConstructor()->getMock();
72 $incident = $this->getMockBuilder(Incident::class)->disableOriginalConstructor()->getMock();
76 $references_of = $this->
expectCall(383, [987], $ref_called);
77 $type_of = $this->
expectCall(987, $type, $type_called);
79 $database->expects(self::once())->method(
'queryF')->with(
'SELECT obj_fi FROM qpl_questions WHERE question_id = %s', [
ilDBConstants::T_INTEGER], [383])->willReturn($statement);
80 $database->expects(self::once())->method(
'fetchAssoc')->with($statement)->willReturn([
'obj_fi' =>
'383']);
82 $incident->expects(self::once())->method(
'any')->willReturnCallback(
function (callable $call_me, array $ref_ids):
bool {
83 $this->assertEquals([987], $ref_ids);
87 if (
null === $requires_permission) {
88 $access->expects(self::never())->method(
'checkAccess');
90 $access->expects(self::once())->method(
'checkAccess')->with($requires_permission,
'', 987)->willReturn($permitted);
95 $result = $instance->isPermitted(
'http://my-ilias/assessment/qst_preview/123/383/fileuploads/my-file.pdf');
96 $this->assertTrue($result->isOk());
97 $this->assertSame($permitted, $result->value());
99 $this->assertSame(1, $ref_called);
100 $this->assertSame(1, $type_called);
103 public static function types(): array
106 'Type qpl with access rights.' => [
'qpl',
false,
'read'],
107 'Type qpl without access rights.' => [
'qpl',
true,
'read'],
108 'Type tst with access rights.' => [
'tst',
false,
'write'],
109 'Type tst without access rights.' => [
'tst',
true,
'write'],
110 'Type crs will never has access rights.' => [
'crs',
false,
null],
111 'Unknown types will never have access rights.' => [
null,
false,
null],
117 return function ($value) use ($expected, $return, &$called) {
118 $this->assertSame($expected, $value);
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
testWithTypes(?string $type, bool $permitted, ?string $requires_permission)
expectCall($expected, $return, &$called)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...