ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
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.

Referenced by testAchieve(), testIsApplicable(), and testIsApplicableInvalidParentException().

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:27
+ Here is the caller graph for this function:

◆ 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.

Referenced by testAchieve(), testGetHash(), testGetPreconditions(), testIsApplicable(), and testIsApplicableInvalidParentException().

65  $obj = $this
66  ->getMockBuilder(
67  ilOrgUnitOperationContextRegisteredObjective::class
68  )
69  ->setConstructorArgs([$context_name, $parent_context])
70  ->onlyMethods(['getContextId'])
71  ->getMock();
72 
73  $obj
74  ->method('getContextId')
75  ->withConsecutive(
76  [$this->isInstanceOf(ilDBInterface::class), $context_name],
77  [$this->isInstanceOf(ilDBInterface::class), $parent_context]
78  )
79  ->willReturnOnConsecutiveCalls($existing_context_id, $parent_id);
80 
81  return $obj;
82  }
+ Here is the caller graph for this function:

◆ testAchieve()

ilOrgUnitOperationContextRegisteredObjectiveTest::testAchieve ( )

Definition at line 153 of file ilOrgUnitOperationContextRegisteredObjectiveTest.php.

References getMockEnviroment(), and getMockObjective().

153  : void
154  {
155  $env = $this->getMockEnviroment(true, 13);
156  $obj = $this->getMockObjective(
157  0,
158  13,
159  $this->context,
160  'parent'
161  );
162  $obj->achieve($env);
163  }
getMockObjective(int $existing_context_id, int $parent_id, string $context_name, ?string $parent_context=null)
+ Here is the call graph for this function:

◆ testGetHash()

ilOrgUnitOperationContextRegisteredObjectiveTest::testGetHash ( )
protected

Definition at line 84 of file ilOrgUnitOperationContextRegisteredObjectiveTest.php.

References getMockObjective().

84  : void
85  {
86  $obj1 = $this->getMockObjective(0, 0, $this->context);
87  $obj2 = $this->getMockObjective(0, 0, 'other context');
88  $this->assertNotEquals(
89  $obj1->getHash(),
90  $obj2->getHash()
91  );
92  }
getMockObjective(int $existing_context_id, int $parent_id, string $context_name, ?string $parent_context=null)
+ Here is the call graph for this function:

◆ testGetPreconditions()

ilOrgUnitOperationContextRegisteredObjectiveTest::testGetPreconditions ( )
protected

Definition at line 94 of file ilOrgUnitOperationContextRegisteredObjectiveTest.php.

References getMockObjective().

94  : void
95  {
96  $env = $this->createMock(Environment::class);
97  $obj = $this->getMockObjective(0, 0, $this->context);
98  $this->assertContainsOnlyInstancesOf(
99  ilDatabaseInitializedObjective::class,
100  $obj->getPreconditions($env)
101  );
102  }
getMockObjective(int $existing_context_id, int $parent_id, string $context_name, ?string $parent_context=null)
+ Here is the call graph for this function:

◆ testIsApplicable()

ilOrgUnitOperationContextRegisteredObjectiveTest::testIsApplicable ( )

Definition at line 104 of file ilOrgUnitOperationContextRegisteredObjectiveTest.php.

References getMockEnviroment(), and getMockObjective().

104  : void
105  {
106  $env = $this->getMockEnviroment(false);
107 
108  $obj = $this->getMockObjective(
109  0,
110  0,
111  $this->context
112  );
113  $this->assertTrue($obj->isApplicable($env));
114 
115  $obj = $this->getMockObjective(
116  7,
117  0,
118  $this->context
119  );
120  $this->assertNotTrue($obj->isApplicable($env));
121 
122  $obj = $this->getMockObjective(
123  0,
124  9,
125  $this->context,
126  'parent'
127  );
128  $this->assertTrue($obj->isApplicable($env));
129 
130  $obj = $this->getMockObjective(
131  7,
132  9,
133  $this->context,
134  'parent'
135  );
136  $this->assertNotTrue($obj->isApplicable($env));
137  }
getMockObjective(int $existing_context_id, int $parent_id, string $context_name, ?string $parent_context=null)
+ Here is the call graph for this function:

◆ testIsApplicableInvalidParentException()

ilOrgUnitOperationContextRegisteredObjectiveTest::testIsApplicableInvalidParentException ( )

Definition at line 139 of file ilOrgUnitOperationContextRegisteredObjectiveTest.php.

References getMockEnviroment(), and getMockObjective().

139  : void
140  {
141  $env = $this->getMockEnviroment(false);
142 
143  $obj = $this->getMockObjective(
144  0,
145  0,
146  $this->context,
147  'parent'
148  );
149  $this->expectException(Exception::class);
150  $obj->isApplicable($env);
151  }
getMockObjective(int $existing_context_id, int $parent_id, string $context_name, ?string $parent_context=null)
+ Here is the call graph for this function:

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: