19declare(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 [$context_name, $existing_context_id],
75 [$parent_context, $parent_id]
79 ->method(
'getContextId')
81 function ($db,
$context) use (&$consecutive) {
82 list($econtext, $ret) = array_shift($consecutive);
83 $this->assertInstanceOf(ilDBInterface::class, $db);
84 $this->assertEquals($econtext,
$context);
94 $obj1 = $this->getMockObjective(0, 0, $this->context);
95 $obj2 = $this->getMockObjective(0, 0,
'other context');
96 $this->assertNotEquals(
104 $env = $this->createMock(Environment::class);
105 $obj = $this->getMockObjective(0, 0, $this->context);
106 $this->assertContainsOnlyInstancesOf(
107 ilDatabaseInitializedObjective::class,
108 $obj->getPreconditions($env)
114 $env = $this->getMockEnviroment(
false);
116 $obj = $this->getMockObjective(
121 $this->assertTrue($obj->isApplicable($env));
123 $obj = $this->getMockObjective(
128 $this->assertNotTrue($obj->isApplicable($env));
130 $obj = $this->getMockObjective(
136 $this->assertTrue($obj->isApplicable($env));
138 $obj = $this->getMockObjective(
144 $this->assertNotTrue($obj->isApplicable($env));
149 $env = $this->getMockEnviroment(
false);
151 $obj = $this->getMockObjective(
157 $this->expectException(Exception::class);
158 $obj->isApplicable($env);
163 $env = $this->getMockEnviroment(
true, 13);
164 $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.