ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
ilAssQuestionSkillAssignmentRegistryTest Class Reference

Class ilAssQuestionSkillAssignmentRegistryTest. More...

+ Inheritance diagram for ilAssQuestionSkillAssignmentRegistryTest:
+ Collaboration diagram for ilAssQuestionSkillAssignmentRegistryTest:

Public Member Functions

 setUp ()
 
 testSkillAssignmentsCanBetStoredAndFetchedBySerializationStrategy ($value, $chunkSize, callable $preCallback, callable $postCallback)
 serializedData More...
 
 testInvalidChunkSizeWillRaiseException ()
 
 serializedData ()
 

Data Fields

const TEST_KEY = 'phpunit_tst'
 

Protected Member Functions

 getTestData (callable $pre, callable $post)
 

Protected Attributes

 $storage = array()
 

Detailed Description

Member Function Documentation

◆ getTestData()

ilAssQuestionSkillAssignmentRegistryTest::getTestData ( callable  $pre,
callable  $post 
)
protected
Parameters
callable$pre
callable$post
Returns
array

Definition at line 99 of file ilAssQuestionSkillAssignmentRegistryTest.php.

References $data, $i, array, and ilAssQuestionSkillAssignment\EVAL_MODE_BY_QUESTION_SOLUTION.

Referenced by serializedData().

100  {
101  $data = [];
102 
103  require_once 'Modules/TestQuestionPool/classes/questions/class.ilAssQuestionSkillAssignmentImportList.php';
104  require_once 'Modules/TestQuestionPool/classes/questions/class.ilAssQuestionSkillAssignmentImport.php';
105  require_once 'Modules/TestQuestionPool/classes/class.ilAssQuestionSkillAssignment.php';
106  $assignmentList = new \ilAssQuestionSkillAssignmentImportList();
107 
108  for ($i = 0; $i < 5; $i++) {
109  $assignment = new \ilAssQuestionSkillAssignmentImport();
111  $assignment->setImportSkillTitle('phpunit' . $i);
112  $assignment->setImportSkillPath('phpunit' . $i);
113  $random = new \ilRandom();
114  $assignment->setSkillPoints($random->int(0, PHP_INT_MAX));
115  $assignment->setImportQuestionId($random->int(0, PHP_INT_MAX));
116  $assignment->setImportSkillBaseId($random->int(0, PHP_INT_MAX));
117  $assignment->setImportSkillTrefId($random->int(0, PHP_INT_MAX));
118 
119  $assignmentList->addAssignment($assignment);
120  }
121 
122  $rawData = array(
123  array("This is a Test", 2),
124  array(array("üäöÖÜÄÖß"), 2),
125  array("This is a Test with a huge chunk size", 10000),
126  array($assignmentList, 7)
127  );
128 
129  foreach ($rawData as $rawItem) {
130  $data[] = array(
131  $rawItem[0], $rawItem[1], $pre, $post
132  );
133  }
134 
135  return $data;
136  }
$post
Definition: post.php:34
Create styles array
The data for the language used.
$i
Definition: disco.tpl.php:19
+ Here is the caller graph for this function:

◆ serializedData()

ilAssQuestionSkillAssignmentRegistryTest::serializedData ( )
Returns
array

Definition at line 141 of file ilAssQuestionSkillAssignmentRegistryTest.php.

References $post, and getTestData().

142  {
143  $pre = function ($value) {
144  return \serialize($value);
145  };
146 
147  $post = function ($value) {
148  return \unserialize($value);
149  };
150 
151  return $this->getTestData($pre, $post);
152  }
$post
Definition: post.php:34
+ Here is the call graph for this function:

◆ setUp()

ilAssQuestionSkillAssignmentRegistryTest::setUp ( )

Definition at line 21 of file ilAssQuestionSkillAssignmentRegistryTest.php.

References array.

22  {
23  parent::setUp();
24 
25  $this->storage = array();
26  }
Create styles array
The data for the language used.

◆ testInvalidChunkSizeWillRaiseException()

ilAssQuestionSkillAssignmentRegistryTest::testInvalidChunkSizeWillRaiseException ( )

Definition at line 74 of file ilAssQuestionSkillAssignmentRegistryTest.php.

References array.

75  {
76  require_once 'Services/Administration/classes/class.ilSetting.php';
77  $settingsMock = $this->getMockBuilder('ilSetting')->disableOriginalConstructor()->setMethods(array('set', 'get', 'delete'))->getMock();
78 
79  try {
80  $registry = new \ilAssQuestionSkillAssignmentRegistry($settingsMock);
81  $registry->setChunkSize("a");
82  $this->fail("Failed asserting that exception of type \"InvalidArgumentException\" is thrown.");
83  } catch (\InvalidArgumentException $e) {
84  }
85 
86  try {
87  $registry = new \ilAssQuestionSkillAssignmentRegistry($settingsMock);
88  $registry->setChunkSize(-5);
89  $this->fail("Failed asserting that exception of type \"InvalidArgumentException\" is thrown.");
90  } catch (\InvalidArgumentException $e) {
91  }
92  }
Create styles array
The data for the language used.

◆ testSkillAssignmentsCanBetStoredAndFetchedBySerializationStrategy()

ilAssQuestionSkillAssignmentRegistryTest::testSkillAssignmentsCanBetStoredAndFetchedBySerializationStrategy (   $value,
  $chunkSize,
callable  $preCallback,
callable  $postCallback 
)

serializedData

Parameters
$value
$chunkSize
callable$preCallback
callable$postCallback

Definition at line 35 of file ilAssQuestionSkillAssignmentRegistryTest.php.

References $key, and array.

36  {
37  require_once 'Services/Administration/classes/class.ilSetting.php';
38  $settingsMock = $this->getMockBuilder('ilSetting')->disableOriginalConstructor()->setMethods(array('set', 'get', 'delete'))->getMock();
39 
40  $settingsMock->expects($this->any())->method('set')->will(
41  $this->returnCallback(function ($key, $value) {
42  $this->storage[$key] = $value;
43  })
44  );
45 
46  $settingsMock->expects($this->any())->method('get')->will(
47  $this->returnCallback(function ($key, $value) {
48  return isset($this->storage[$key]) ? $this->storage[$key] : $value;
49  })
50  );
51 
52  $settingsMock->expects($this->any())->method('delete')->will(
53  $this->returnCallback(function ($key, $value) {
54  if (isset($this->storage[$key])) {
55  unset($this->storage[$key]);
56  }
57  })
58  );
59 
60  $valueToTest = $preCallback($value);
61 
62  $registry = new \ilAssQuestionSkillAssignmentRegistry($settingsMock);
63  $registry->setChunkSize($chunkSize);
64  $registry->setStringifiedImports(self::TEST_KEY, $valueToTest);
65  $actual = $registry->getStringifiedImports(self::TEST_KEY);
66 
67  $this->assertEquals($valueToTest, $actual);
68  $this->assertEquals($value, $postCallback($actual));
69  }
Create styles array
The data for the language used.
$key
Definition: croninfo.php:18

Field Documentation

◆ $storage

ilAssQuestionSkillAssignmentRegistryTest::$storage = array()
protected

Definition at line 16 of file ilAssQuestionSkillAssignmentRegistryTest.php.

◆ TEST_KEY

const ilAssQuestionSkillAssignmentRegistryTest::TEST_KEY = 'phpunit_tst'

Definition at line 11 of file ilAssQuestionSkillAssignmentRegistryTest.php.


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