ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
ClientIdReadObjectiveTest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
22 
23 use ILIAS\Setup;
26 
27 class 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  $mock
89  ->expects($this->exactly(2))
90  ->method("isDirectory")
91  ->withConsecutive([$DATA_DIR . "/" . $SOME_DIR], [$DATA_DIR . "/" . $SOME_FILE])
92  ->will($this->onConsecutiveCalls(true, false));
93 
94  $env
95  ->expects($this->once())
96  ->method("withResource")
97  ->with(Setup\Environment::RESOURCE_CLIENT_ID, $SOME_DIR)
98  ->willReturn($env);
99 
100  $res = $mock->achieve($env);
101  $this->assertSame($env, $res);
102  }
103 
104  public function testGetDataDirectoryPath(): void
105  {
106  $base = dirname(__DIR__, 3);
107  $this->assertEquals($base . "/data", $this->o->_getDataDirectoryPath());
108  }
109 }
$res
Definition: ltiservices.php:69
Read the client id of the installation from the data directory.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...