24 require_once(
"libs/composer/vendor/autoload.php");
25 require_once(
"./Services/ActiveRecord/Connector/class.arConnector.php");
26 require_once(
"./Services/ActiveRecord/Connector/class.arConnectorMap.php");
48 public function setUp()
51 $dic[Bucket::class] =
function ($c) {
63 $a =
$factory->createInstance(PlusJob::class);
65 $b =
$factory->createInstance(PlusJob::class);
67 $c =
$factory->createInstance(PlusJob::class);
71 $c->setInput([$a, $b]);
74 $userInteraction =
$factory->createInstance(DownloadInteger::class);
75 $userInteraction->setInput([$c]);
77 $bucket->setTask($userInteraction);
85 public function testSave()
88 $bucketConnector = Mockery::namedMock(
"bucketConnectorMock", \arConnector::class);
90 $valueConnector = Mockery::namedMock(
"valueConnectorMock", \arConnector::class);
92 $taskConnector = Mockery::namedMock(
"taskConnectorMock", \arConnector::class);
94 $valueToTaskConnector = Mockery::namedMock(
"valueToTaskConnectorMock", \arConnector::class);
102 $bucketConnector->shouldReceive(
"nextID")->once()->andReturn(1);
103 $bucketConnector->shouldReceive(
"create")->once();
106 $bucketConnector->shouldReceive(
"affectedRows")->once()->andReturn(1);
107 $bucketConnector->shouldReceive(
"update")->once()->andReturn(
true);
110 for (
$i = 0;
$i < 4;
$i++) {
112 $taskConnector->shouldReceive(
"affectedRows")->once()->andReturn(0);
113 $taskConnector->shouldReceive(
"nextID")->once()->andReturn(1);
114 $taskConnector->shouldReceive(
"create")->once();
117 $taskConnector->shouldReceive(
"affectedRows")->once()->andReturn(1);
118 $taskConnector->shouldReceive(
"update")->once();
122 $valueConnector->shouldReceive(
"affectedRows")->times(7)->andReturn(0);
123 $valueConnector->shouldReceive(
"nextID")->times(7)->andReturn(1);
124 $valueConnector->shouldReceive(
"create")->times(7);
127 $valueToTaskConnector->shouldReceive(
"affectedRows")->times(7)->andReturn(0);
128 $valueToTaskConnector->shouldReceive(
"nextID")->times(7)->andReturn(1);
129 $valueToTaskConnector->shouldReceive(
"create")->times(7);
131 $this->persistence->setConnector($bucketConnector);
132 $this->persistence->saveBucketAndItsTasks($this->bucket);
138 $this->expectException(SerializationException::class);
140 $this->persistence->updateBucket($this->bucket);
143 public function testUpdateObserver()
148 $observerConnector = Mockery::namedMock(
"observerConnectorMock", \arConnector::class);
153 $observerConnector->shouldReceive(
"read")->once()->andReturn(1);
154 $observerConnector->shouldReceive(
"update")->once()->andReturn(
true);
156 $this->persistence->setConnector($observerConnector);
157 $this->persistence->updateBucket($this->bucket);
160 public function testGetObserverIdsOfUser()
163 $observerConnector = Mockery::namedMock(
"observerConnectorMock", \arConnector::class);
166 $observerConnector->shouldReceive(
"readSet")->once()->andReturn([[
"id" => 2], [
"id" => 3]]);
168 $this->persistence->setConnector($observerConnector);
169 $observer_ids = $this->persistence->getBucketIdsOfUser(5);
170 $this->assertEquals($observer_ids, [0 => 2, 1 => 3]);
173 public function testGetObserverIdsByState()
176 $observerConnector = Mockery::namedMock(
"observerConnectorMock", \arConnector::class);
179 $observerConnector->shouldReceive(
"readSet")->once()->andReturn([[
"id" => 2], [
"id" => 3]]);
181 $this->persistence->setConnector($observerConnector);
182 $observer_ids = $this->persistence->getBucketIdsByState(
State::RUNNING);
183 $this->assertEquals($observer_ids, [2 => 2, 3 => 3]);
187 public function testUserInteraction()
189 $this->setExpectedException(UserInteractionRequiredException::class);
193 $taskManager->executeTask($this->bucket->getTask(),
new MockObserver());
196 public function testContinueUserInteraction()
209 self::assertEquals($this->bucket->getCurrentTask()->getType(), $download_integer->getType());
211 $options = $download_integer->getOptions([]);
213 $dismiss = $download_integer->getRemoveOption();
215 $this->bucket->userInteraction($dismiss);
221 public function testContinueUserInteraction2()
227 $c = $this->bucket->getTask();
229 $x =
$factory->createInstance(PlusJob::class);
231 $x->setInput([$c, 1]);
234 $this->bucket->setTask(
$x);
247 self::assertEquals($this->bucket->getCurrentTask()->getType(), $download_integer->getType());
249 $options = $download_integer->getOptions([]);
251 $dismiss = $download_integer->getRemoveOption();
253 $this->bucket->userInteraction($dismiss);
258 self::assertEquals(5,
$result->getValue());
static register(ActiveRecord $ar, arConnector $connector)
testCannotUpdateUnknownBucket()
Customizing of pimple-DIC for ILIAS.
Class NonPersistingObserver.
Class BackgroundTaskTest.
if(!isset($_REQUEST['ReturnTo'])) if(!isset($_REQUEST['AuthId'])) $options