ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
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  $settingsMock = $this->getMockBuilder('ilSetting')->disableOriginalConstructor()->onlyMethods(array('set', 'get', 'delete'))->getMock();
51 
52  $settingsMock->expects($this->any())->method('set')->will(
53  $this->returnCallback(function ($key, $value) {
54  $this->storage[$key] = $value;
55  })
56  );
57 
58  $settingsMock->expects($this->any())->method('get')->will(
59  $this->returnCallback(function ($key, $value) {
60  return $this->storage[$key] ?? $value;
61  })
62  );
63 
64  $settingsMock->expects($this->any())->method('delete')->will(
65  $this->returnCallback(function ($key, $value) {
66  if (isset($this->storage[$key])) {
67  unset($this->storage[$key]);
68  }
69  })
70  );
71 
72  $valueToTest = $preCallback($value);
73 
74  $registry = new \ilAssQuestionSkillAssignmentRegistry($settingsMock);
75  $registry->setChunkSize($chunkSize);
76  $registry->setStringifiedImports(self::TEST_KEY, $valueToTest);
77  $actual = $registry->getStringifiedImports(self::TEST_KEY);
78 
79  $this->assertEquals($valueToTest, $actual);
80  $this->assertEquals($value, $postCallback($actual));
81  }
82 
87  {
88  $settingsMock = $this->getMockBuilder('ilSetting')->disableOriginalConstructor()->onlyMethods(array('set', 'get', 'delete'))->getMock();
89 
90  try {
91  $registry = new \ilAssQuestionSkillAssignmentRegistry($settingsMock);
92  $registry->setChunkSize("a");
93  $this->fail("Failed asserting that exception of type \"InvalidArgumentException\" is thrown.");
94  } catch (\InvalidArgumentException $e) {
95  }
96 
97  try {
98  $registry = new \ilAssQuestionSkillAssignmentRegistry($settingsMock);
99  $registry->setChunkSize(-5);
100  $this->fail("Failed asserting that exception of type \"InvalidArgumentException\" is thrown.");
101  } catch (\InvalidArgumentException $e) {
102  }
103  }
104 
110  protected function getTestData(callable $pre, callable $post): array
111  {
112  $data = [];
113 
114  $assignmentList = new \ilAssQuestionSkillAssignmentImportList();
115 
116  for ($i = 0; $i < 5; $i++) {
117  $assignment = new \ilAssQuestionSkillAssignmentImport();
119  $assignment->setImportSkillTitle('phpunit' . $i);
120  $assignment->setImportSkillPath('phpunit' . $i);
121  $random = new \ilRandom();
122  $assignment->setSkillPoints($random->int(0, PHP_INT_MAX));
123  $assignment->setImportQuestionId($random->int(0, PHP_INT_MAX));
124  $assignment->setImportSkillBaseId($random->int(0, PHP_INT_MAX));
125  $assignment->setImportSkillTrefId($random->int(0, PHP_INT_MAX));
126 
127  $assignmentList->addAssignment($assignment);
128  }
129 
130  $rawData = array(
131  array("This is a Test", 2),
132  array(array("üäöÖÜÄÖß"), 2),
133  array("This is a Test with a huge chunk size", 10000),
134  array($assignmentList, 7)
135  );
136 
137  foreach ($rawData as $rawItem) {
138  $data[] = array(
139  $rawItem[0], $rawItem[1], $pre, $post
140  );
141  }
142 
143  return $data;
144  }
145 
149  public function serializedData(): array
150  {
151  $pre = function ($value) {
152  return \serialize($value);
153  };
154 
155  $post = function ($value) {
156  return \unserialize($value);
157  };
158 
159  return $this->getTestData($pre, $post);
160  }
161 }
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