ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ExternalConditionObjectiveTest.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 ExternalConditionObjectiveTest extends TestCase
28{
29 protected string $label_t;
31 protected string $label_f;
33
34 public function setUp(): void
35 {
36 $this->label_t = "condition_true";
38 $this->label_t,
39 function (Setup\Environment $e) {
40 return true;
41 }
42 );
43 $this->label_f = "condition_false";
45 $this->label_f,
46 function (Setup\Environment $e) {
47 return false;
48 }
49 );
50 }
51
52 public function testGetHash(): void
53 {
54 $this->assertIsString($this->t->getHash());
55 }
56
58 {
59 $this->assertNotEquals($this->t->getHash(), $this->f->getHash());
60 }
61
62 public function testGetLabel(): void
63 {
64 $this->assertIsString($this->f->getLabel());
65 $this->assertEquals($this->label_f, $this->f->getLabel());
66 $this->assertEquals($this->label_t, $this->t->getLabel());
67 }
68
69 public function testIsNotable(): void
70 {
71 $this->assertTrue($this->f->isNotable());
72 }
73
74 public function testGetPreconditions(): void
75 {
76 $env = $this->createMock(Setup\Environment::class);
77
78 $pre = $this->f->getPreconditions($env);
79 $this->assertEquals([], $pre);
80 }
81
82 public function testAchieveFalse(): void
83 {
84 $this->expectException(Setup\UnachievableException::class);
85 $env = $this->createMock(Setup\Environment::class);
86 $this->f->achieve($env);
87 }
88
89 public function testAchieveTrue(): void
90 {
91 $env = $this->createMock(Setup\Environment::class);
92 $res = $this->t->achieve($env);
93 $this->assertEquals($env, $res);
94 }
95
96 public function testNotExecutable(): void
97 {
98 $env = $this->createMock(Setup\Environment::class);
99
100 $throws_not_executable = new Condition\ExternalConditionObjective(
101 "Not executable",
102 function (Setup\Environment $e) {
103 return false;
104 },
105 null,
106 true
107 );
108
109 $this->expectException(Setup\NotExecutableException::class);
110 $throws_not_executable->achieve($env);
111 }
112
113 public function testUnachievable(): void
114 {
115 $env = $this->createMock(Setup\Environment::class);
116
117 $throws_unachievable = new Condition\ExternalConditionObjective(
118 "Unachievable",
119 function (Setup\Environment $e) {
120 return false;
121 },
122 null,
123 false
124 );
125
126 $this->expectException(Setup\UnachievableException::class);
127 $throws_unachievable->achieve($env);
128 }
129}
A condition that can't be met by ILIAS itself needs to be met by some external means.
return true
An environment holds resources to be used in the setup process.
Definition: Environment.php:28
$res
Definition: ltiservices.php:69
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...