ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
ilAssQuestionSkillAssignmentRegistryTest.php
Go to the documentation of this file.
1 <?php
2 
23 {
24  public const TEST_KEY = 'phpunit_tst';
25 
29  protected $storage = array();
30 
34  public function setUp(): void
35  {
36  parent::setUp();
37 
38  $this->storage = array();
39  }
40 
48  public function testSkillAssignmentsCanBetStoredAndFetchedBySerializationStrategy($value, $chunkSize, callable $preCallback, callable $postCallback): void
49  {
50  require_once 'Services/Administration/classes/class.ilSetting.php';
51  $settingsMock = $this->getMockBuilder('ilSetting')->disableOriginalConstructor()->onlyMethods(array('set', 'get', 'delete'))->getMock();
52 
53  $settingsMock->expects($this->any())->method('set')->will(
54  $this->returnCallback(function ($key, $value) {
55  $this->storage[$key] = $value;
56  })
57  );
58 
59  $settingsMock->expects($this->any())->method('get')->will(
60  $this->returnCallback(function ($key, $value) {
61  return $this->storage[$key] ?? $value;
62  })
63  );
64 
65  $settingsMock->expects($this->any())->method('delete')->will(
66  $this->returnCallback(function ($key, $value) {
67  if (isset($this->storage[$key])) {
68  unset($this->storage[$key]);
69  }
70  })
71  );
72 
73  $valueToTest = $preCallback($value);
74 
75  $registry = new \ilAssQuestionSkillAssignmentRegistry($settingsMock);
76  $registry->setChunkSize($chunkSize);
77  $registry->setStringifiedImports(self::TEST_KEY, $valueToTest);
78  $actual = $registry->getStringifiedImports(self::TEST_KEY);
79 
80  $this->assertEquals($valueToTest, $actual);
81  $this->assertEquals($value, $postCallback($actual));
82  }
83 
88  {
89  require_once 'Services/Administration/classes/class.ilSetting.php';
90  $settingsMock = $this->getMockBuilder('ilSetting')->disableOriginalConstructor()->onlyMethods(array('set', 'get', 'delete'))->getMock();
91 
92  try {
93  $registry = new \ilAssQuestionSkillAssignmentRegistry($settingsMock);
94  $registry->setChunkSize("a");
95  $this->fail("Failed asserting that exception of type \"InvalidArgumentException\" is thrown.");
96  } catch (\InvalidArgumentException $e) {
97  }
98 
99  try {
100  $registry = new \ilAssQuestionSkillAssignmentRegistry($settingsMock);
101  $registry->setChunkSize(-5);
102  $this->fail("Failed asserting that exception of type \"InvalidArgumentException\" is thrown.");
103  } catch (\InvalidArgumentException $e) {
104  }
105  }
106 
112  protected function getTestData(callable $pre, callable $post): array
113  {
114  $data = [];
115 
116  require_once 'Modules/TestQuestionPool/classes/questions/class.ilAssQuestionSkillAssignmentImportList.php';
117  require_once 'Modules/TestQuestionPool/classes/questions/class.ilAssQuestionSkillAssignmentImport.php';
118  require_once 'Modules/TestQuestionPool/classes/class.ilAssQuestionSkillAssignment.php';
119  $assignmentList = new \ilAssQuestionSkillAssignmentImportList();
120 
121  for ($i = 0; $i < 5; $i++) {
122  $assignment = new \ilAssQuestionSkillAssignmentImport();
124  $assignment->setImportSkillTitle('phpunit' . $i);
125  $assignment->setImportSkillPath('phpunit' . $i);
126  $random = new \ilRandom();
127  $assignment->setSkillPoints($random->int(0, PHP_INT_MAX));
128  $assignment->setImportQuestionId($random->int(0, PHP_INT_MAX));
129  $assignment->setImportSkillBaseId($random->int(0, PHP_INT_MAX));
130  $assignment->setImportSkillTrefId($random->int(0, PHP_INT_MAX));
131 
132  $assignmentList->addAssignment($assignment);
133  }
134 
135  $rawData = array(
136  array("This is a Test", 2),
137  array(array("üäöÖÜÄÖß"), 2),
138  array("This is a Test with a huge chunk size", 10000),
139  array($assignmentList, 7)
140  );
141 
142  foreach ($rawData as $rawItem) {
143  $data[] = array(
144  $rawItem[0], $rawItem[1], $pre, $post
145  );
146  }
147 
148  return $data;
149  }
150 
154  public function serializedData(): array
155  {
156  $pre = function ($value) {
157  return \serialize($value);
158  };
159 
160  $post = function ($value) {
161  return \unserialize($value);
162  };
163 
164  return $this->getTestData($pre, $post);
165  }
166 }
Class assBaseTestCase.
testSkillAssignmentsCanBetStoredAndFetchedBySerializationStrategy($value, $chunkSize, callable $preCallback, callable $postCallback)
serializedData
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
string $key
Consumer key/client ID value.
Definition: System.php:193
$post
Definition: ltitoken.php:49
$i
Definition: metadata.php:41