ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ClientIdReadObjectiveTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
23use ILIAS\Setup;
25use PHPUnit\Framework\TestCase;
26
27class ClientIdReadObjectiveTest extends TestCase
28{
30
31 public function setUp(): void
32 {
33 $this->o = new class () extends ClientIdReadObjective {
34 public function _getDataDirectoryPath()
35 {
36 return $this->getDataDirectoryPath();
37 }
38 };
39 }
40
41 public function testGetHash(): void
42 {
43 $this->assertIsString($this->o->getHash());
44 }
45
46 public function testGetLabel(): void
47 {
48 $this->assertIsString($this->o->getLabel());
49 }
50
51 public function testIsNotable(): void
52 {
53 $this->assertFalse($this->o->isNotable());
54 }
55
56 public function testGetPreconditions(): void
57 {
58 $env = $this->createMock(Setup\Environment::class);
59
60 $pre = $this->o->getPreconditions($env);
61 $this->assertEquals([], $pre);
62 }
63
64 public function testAchieve(): void
65 {
66 $env = $this->createMock(Setup\Environment::class);
67
68 $mock = $this->getMockBuilder(ClientIdReadObjective::class)
69 ->onlyMethods(["getDataDirectoryPath", "scanDirectory", "isDirectory"])
70 ->getMock();
71
72 $DATA_DIR = "/foo/bar/data";
73 $SOME_DIR = "clientid";
74 $SOME_FILE = "some_file";
75 $SCAN_RESULT = [".", "..", $SOME_DIR, $SOME_FILE];
76
77 $mock
78 ->expects($this->once())
79 ->method("getDataDirectoryPath")
80 ->willReturn($DATA_DIR);
81
82 $mock
83 ->expects($this->once())
84 ->method("scanDirectory")
85 ->with($DATA_DIR)
86 ->willReturn($SCAN_RESULT);
87
88 $consecutive = [
89 [$DATA_DIR . "/" . $SOME_DIR, true],
90 [$DATA_DIR . "/" . $SOME_FILE, false]
91 ];
92 $mock
93 ->expects($this->exactly(2))
94 ->method("isDirectory")
95 ->willReturnCallback(
96 function ($path) use (&$consecutive): bool {
97 list($expected, $return) = array_shift($consecutive);
98 $this->assertEquals($expected, $path);
99 return $return;
100 }
101 );
102
103 $env
104 ->expects($this->once())
105 ->method("withResource")
106 ->with(Setup\Environment::RESOURCE_CLIENT_ID, $SOME_DIR)
107 ->willReturn($env);
108
109 $res = $mock->achieve($env);
110 $this->assertSame($env, $res);
111 }
112
113 public function testGetDataDirectoryPath(): void
114 {
115 $base = dirname(__DIR__, 5);
116 $this->assertEquals($base . "/public/data", $this->o->_getDataDirectoryPath());
117 }
118}
Read the client id of the installation from the data directory.
$path
Definition: ltiservices.php:30
$res
Definition: ltiservices.php:69
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...