ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
AccessQuestionImageTest.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
21 namespace ILIAS\Modules\Test\test;
22 
26 
28 {
29  public function testConstruct(): void
30  {
31  $readable = $this->getMockBuilder(Readable::class)->disableOriginalConstructor()->getMock();
32  $this->assertInstanceOf(AccessQuestionImage::class, new AccessQuestionImage($readable));
33  }
34 
38  public function testIsPermittedWithInvalidPath(string $path): void
39  {
40  $readable = $this->getMockBuilder(Readable::class)->disableOriginalConstructor()->getMock();
41 
42  $instance = new AccessQuestionImage($readable);
43 
44  $this->assertFalse($instance->isPermitted($path)->isOk());
45  }
46 
47  public function invalidPaths(): array
48  {
49  return [
50  ['foo'],
51  ['/assessment/12/images/foo.png'],
52  ['/assessment/12/34/images/foo/bar.png'],
53  ['/assessment/12/ab/images/foo.png'],
54  ['/assessment/ab/12/images/foo.png'],
55  ['assessment/12/34/images/foo.png'],
56  ];
57  }
58 
62  public function testIsPermittedWithValidPath(bool $is_readable): void
63  {
64  $readable = $this->getMockBuilder(Readable::class)->disableOriginalConstructor()->getMock();
65 
66  $readable->method('objectId')->with(6709)->willReturn($is_readable);
67 
68  $instance = new AccessQuestionImage($readable);
69  $result = $instance->isPermitted('/assessment/6709/389/images/foo.png');
70  $this->assertTrue($result->isOk());
71  $this->assertSame($is_readable, $result->value());
72  }
73 
74  public function isPermittedProvider(): array
75  {
76  return [
77  'With readable object path.' => [true],
78  'Without readable object path.' => [false],
79  ];
80  }
81 }
$result
testIsPermittedWithValidPath(bool $is_readable)
isPermittedProvider