ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ilOrgUnitOperationContextRegisteredObjectiveTest Class Reference
+ Inheritance diagram for ilOrgUnitOperationContextRegisteredObjectiveTest:
+ Collaboration diagram for ilOrgUnitOperationContextRegisteredObjectiveTest:

Public Member Functions

 testIsApplicable ()
 
 testIsApplicableInvalidParentException ()
 
 testAchieve ()
 

Protected Member Functions

 getMockEnviroment (bool $expect_insert, int $expected_parent_id=0)
 
 getMockObjective (int $existing_context_id, int $parent_id, string $context_name, ?string $parent_context=null)
 
 testGetHash ()
 
 testGetPreconditions ()
 

Protected Attributes

int $next_id = 3
 
string $context = 'first context'
 

Detailed Description

Member Function Documentation

◆ getMockEnviroment()

ilOrgUnitOperationContextRegisteredObjectiveTest::getMockEnviroment ( bool  $expect_insert,
int  $expected_parent_id = 0 
)
protected

Definition at line 29 of file ilOrgUnitOperationContextRegisteredObjectiveTest.php.

32 : Environment {
33 $db = $this->createMock(ilDBInterface::class);
34 if ($expect_insert) {
35 $db
36 ->expects(self::once())
37 ->method('insert')
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]
42 ]);
43 $db
44 ->expects(self::once())
45 ->method('nextId')
46 ->with('il_orgu_op_contexts')
47 ->willReturn($this->next_id);
48 }
49
50 $env = $this->createMock(Environment::class);
51 $env
52 ->method('getResource')
53 ->with(Environment::RESOURCE_DATABASE)
54 ->willReturn($db);
55
56 return $env;
57 }
An environment holds resources to be used in the setup process.
Definition: Environment.php:28

◆ getMockObjective()

ilOrgUnitOperationContextRegisteredObjectiveTest::getMockObjective ( int  $existing_context_id,
int  $parent_id,
string  $context_name,
?string  $parent_context = null 
)
protected

Definition at line 59 of file ilOrgUnitOperationContextRegisteredObjectiveTest.php.

65 $obj = $this
66 ->getMockBuilder(
67 ilOrgUnitOperationContextRegisteredObjective::class
68 )
69 ->setConstructorArgs([$context_name, $parent_context])
70 ->onlyMethods(['getContextId'])
71 ->getMock();
72
73 $consecutive = [
74 [$context_name, $existing_context_id],
75 [$parent_context, $parent_id]
76 ];
77
78 $obj
79 ->method('getContextId')
80 ->willReturnCallback(
81 function ($db, $context) use (&$consecutive) {
82 list($econtext, $ret) = array_shift($consecutive);
83 $this->assertInstanceOf(ilDBInterface::class, $db);
84 $this->assertEquals($econtext, $context);
85 return $ret;
86 }
87 );
88
89 return $obj;
90 }

References $context.

◆ testAchieve()

ilOrgUnitOperationContextRegisteredObjectiveTest::testAchieve ( )

Definition at line 161 of file ilOrgUnitOperationContextRegisteredObjectiveTest.php.

161 : void
162 {
163 $env = $this->getMockEnviroment(true, 13);
164 $obj = $this->getMockObjective(
165 0,
166 13,
167 $this->context,
168 'parent'
169 );
170 $obj->achieve($env);
171 }
getMockObjective(int $existing_context_id, int $parent_id, string $context_name, ?string $parent_context=null)

◆ testGetHash()

ilOrgUnitOperationContextRegisteredObjectiveTest::testGetHash ( )
protected

Definition at line 92 of file ilOrgUnitOperationContextRegisteredObjectiveTest.php.

92 : void
93 {
94 $obj1 = $this->getMockObjective(0, 0, $this->context);
95 $obj2 = $this->getMockObjective(0, 0, 'other context');
96 $this->assertNotEquals(
97 $obj1->getHash(),
98 $obj2->getHash()
99 );
100 }

◆ testGetPreconditions()

ilOrgUnitOperationContextRegisteredObjectiveTest::testGetPreconditions ( )
protected

Definition at line 102 of file ilOrgUnitOperationContextRegisteredObjectiveTest.php.

102 : void
103 {
104 $env = $this->createMock(Environment::class);
105 $obj = $this->getMockObjective(0, 0, $this->context);
106 $this->assertContainsOnlyInstancesOf(
107 ilDatabaseInitializedObjective::class,
108 $obj->getPreconditions($env)
109 );
110 }

◆ testIsApplicable()

ilOrgUnitOperationContextRegisteredObjectiveTest::testIsApplicable ( )

Definition at line 112 of file ilOrgUnitOperationContextRegisteredObjectiveTest.php.

112 : void
113 {
114 $env = $this->getMockEnviroment(false);
115
116 $obj = $this->getMockObjective(
117 0,
118 0,
119 $this->context
120 );
121 $this->assertTrue($obj->isApplicable($env));
122
123 $obj = $this->getMockObjective(
124 7,
125 0,
126 $this->context
127 );
128 $this->assertNotTrue($obj->isApplicable($env));
129
130 $obj = $this->getMockObjective(
131 0,
132 9,
133 $this->context,
134 'parent'
135 );
136 $this->assertTrue($obj->isApplicable($env));
137
138 $obj = $this->getMockObjective(
139 7,
140 9,
141 $this->context,
142 'parent'
143 );
144 $this->assertNotTrue($obj->isApplicable($env));
145 }

◆ testIsApplicableInvalidParentException()

ilOrgUnitOperationContextRegisteredObjectiveTest::testIsApplicableInvalidParentException ( )

Definition at line 147 of file ilOrgUnitOperationContextRegisteredObjectiveTest.php.

147 : void
148 {
149 $env = $this->getMockEnviroment(false);
150
151 $obj = $this->getMockObjective(
152 0,
153 0,
154 $this->context,
155 'parent'
156 );
157 $this->expectException(Exception::class);
158 $obj->isApplicable($env);
159 }

Field Documentation

◆ $context

string ilOrgUnitOperationContextRegisteredObjectiveTest::$context = 'first context'
protected

◆ $next_id

int ilOrgUnitOperationContextRegisteredObjectiveTest::$next_id = 3
protected

The documentation for this class was generated from the following file: