ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
ClientIdReadObjectiveTest.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 2019 Richard Klees <richard.klees@concepts-and-training.de> Extended GPL, see docs/LICENSE */
4 
6 
7 use ILIAS\Setup;
10 
12 {
13  public function setUp() : void
14  {
15  $this->o = new class extends ClientIdReadObjective {
16  public function _getDataDirectoryPath()
17  {
18  return $this->getDataDirectoryPath();
19  }
20  };
21  }
22 
23  public function testGetHash() : void
24  {
25  $this->assertIsString($this->o->getHash());
26  }
27 
28  public function testGetLabel() : void
29  {
30  $this->assertIsString($this->o->getLabel());
31  }
32 
33  public function testIsNotable() : void
34  {
35  $this->assertFalse($this->o->isNotable());
36  }
37 
38  public function testGetPreconditions() : void
39  {
40  $env = $this->createMock(Setup\Environment::class);
41 
42  $pre = $this->o->getPreconditions($env);
43  $this->assertEquals([], $pre);
44  }
45 
46  public function testAchieve() : void
47  {
48  $env = $this->createMock(Setup\Environment::class);
49 
50  $mock = $this->getMockBuilder(ClientIdReadObjective::class)
51  ->setMethods(["getDataDirectoryPath", "scanDirectory", "isDirectory"])
52  ->getMock();
53 
54  $DATA_DIR = "/foo/bar/data";
55  $SOME_DIR = "clientid";
56  $SOME_FILE = "some_file";
57  $SCAN_RESULT = [".", "..", $SOME_DIR, $SOME_FILE];
58 
59  $mock
60  ->expects($this->once())
61  ->method("getDataDirectoryPath")
62  ->willReturn($DATA_DIR);
63 
64  $mock
65  ->expects($this->once())
66  ->method("scanDirectory")
67  ->with($DATA_DIR)
68  ->willReturn($SCAN_RESULT);
69 
70  $mock
71  ->expects($this->exactly(2))
72  ->method("isDirectory")
73  ->withConsecutive([$DATA_DIR . "/" . $SOME_DIR], [$DATA_DIR . "/" . $SOME_FILE])
74  ->will($this->onConsecutiveCalls(true, false));
75 
76  $env
77  ->expects($this->once())
78  ->method("withResource")
79  ->with(Setup\Environment::RESOURCE_CLIENT_ID, $SOME_DIR)
80  ->willReturn($env);
81 
82  $res = $mock->achieve($env);
83  $this->assertSame($env, $res);
84  }
85 
86  public function testGetDataDirectoryPath()
87  {
88  $base = dirname(__DIR__, 3);
89  $this->assertEquals($base . "/data", $this->o->_getDataDirectoryPath());
90  }
91 }
foreach($_POST as $key=> $value) $res
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$base
Definition: index.php:4