3declare(strict_types=1);
21use PHPUnit\Framework\TestCase;
31 int $expected_parent_id = 0
36 ->expects(self::once())
38 ->with(
'il_orgu_op_contexts', [
39 'id' => [
'integer', $this->next_id],
40 'context' => [
'text', $this->context],
41 'parent_context_id' => [
'integer', $expected_parent_id]
44 ->expects(self::once())
46 ->with(
'il_orgu_op_contexts')
47 ->willReturn($this->next_id);
50 $env = $this->createMock(Environment::class);
52 ->method(
'getResource')
53 ->with(Environment::RESOURCE_DATABASE)
60 int $existing_context_id,
63 ?
string $parent_context =
null
69 ->setConstructorArgs([$context_name, $parent_context])
70 ->onlyMethods([
'getContextId'])
74 ->method(
'getContextId')
76 [$this->isInstanceOf(ilDBInterface::class), $context_name],
77 [$this->isInstanceOf(ilDBInterface::class), $parent_context]
79 ->willReturnOnConsecutiveCalls($existing_context_id, $parent_id);
86 $obj1 = $this->getMockObjective(0, 0, $this->context);
87 $obj2 = $this->getMockObjective(0, 0,
'other context');
88 $this->assertNotEquals(
96 $env = $this->createMock(Environment::class);
97 $obj = $this->getMockObjective(0, 0, $this->context);
98 $this->assertContainsOnlyInstancesOf(
99 ilDatabaseInitializedObjective::class,
100 $obj->getPreconditions($env)
106 $env = $this->getMockEnviroment(
false);
108 $obj = $this->getMockObjective(
113 $this->assertTrue($obj->isApplicable($env));
115 $obj = $this->getMockObjective(
120 $this->assertNotTrue($obj->isApplicable($env));
122 $obj = $this->getMockObjective(
128 $this->assertTrue($obj->isApplicable($env));
130 $obj = $this->getMockObjective(
136 $this->assertNotTrue($obj->isApplicable($env));
141 $env = $this->getMockEnviroment(
false);
143 $obj = $this->getMockObjective(
149 $this->expectException(Exception::class);
150 $obj->isApplicable($env);
155 $env = $this->getMockEnviroment(
true, 13);
156 $obj = $this->getMockObjective(
getMockEnviroment(bool $expect_insert, int $expected_parent_id=0)
testIsApplicableInvalidParentException()
getMockObjective(int $existing_context_id, int $parent_id, string $context_name, ?string $parent_context=null)
An environment holds resources to be used in the setup process.