19declare(strict_types=1);
21use PHPUnit\Framework\TestCase;
32 int $expected_context_id = 0
37 ->expects(self::once())
39 ->with(
'il_orgu_operations', [
40 'operation_id' => [
'integer', $this->next_id],
41 'operation_string' => [
'text', $this->operation],
42 'description' => [
'text', $this->description],
43 'list_order' => [
'integer', 0],
44 'context_id' => [
'integer', $expected_context_id],
47 ->expects(self::once())
49 ->with(
'il_orgu_operations')
50 ->willReturn($this->next_id);
53 $env = $this->createMock(Environment::class);
55 ->method(
'getResource')
56 ->with(Environment::RESOURCE_DATABASE)
63 bool $does_op_already_exist,
65 string $operation_name
71 ->setConstructorArgs([$operation_name, $this->description,
'context'])
72 ->onlyMethods([
'getContextId',
'doesOperationExistInContext'])
76 ->method(
'getContextId')
77 ->with($this->isInstanceOf(ilDBInterface::class),
'context')
78 ->willReturn($context_id);
80 ->method(
'doesOperationExistInContext')
81 ->with($this->isInstanceOf(ilDBInterface::class), $context_id, $operation_name)
82 ->willReturn($does_op_already_exist);
89 $obj1 = $this->getMockObjective(
true, 0, $this->operation);
90 $obj2 = $this->getMockObjective(
true, 0,
'other op');
91 $this->assertNotEquals(
99 $env = $this->createMock(Environment::class);
100 $obj = $this->getMockObjective(
true, 0, $this->operation,
'');
101 $this->assertContainsOnlyInstancesOf(
102 ilDatabaseInitializedObjective::class,
103 $obj->getPreconditions($env)
109 $env = $this->getMockEnviroment(
false);
111 $obj = $this->getMockObjective(
false, 9, $this->operation);
112 $this->assertTrue($obj->isApplicable($env));
114 $obj = $this->getMockObjective(
true, 9, $this->operation);
115 $this->assertNotTrue($obj->isApplicable($env));
120 $env = $this->getMockEnviroment(
false);
122 $obj = $this->getMockObjective(
false, 0, $this->operation);
123 $this->expectException(Exception::class);
124 $obj->isApplicable($env);
129 $env = $this->getMockEnviroment(
true, 13);
130 $obj = $this->getMockObjective(
false, 13, $this->operation);
getMockObjective(bool $does_op_already_exist, int $context_id, string $operation_name)
getMockEnviroment(bool $expect_insert, int $expected_context_id=0)
testIsApplicableInvalidContextException()
An environment holds resources to be used in the setup process.