25 require_once(
"libs/composer/vendor/autoload.php");
26 require_once(
"./Services/ActiveRecord/Connector/class.arConnector.php");
27 require_once(
"./Services/ActiveRecord/Connector/class.arConnectorMap.php");
49 public function setUp()
52 $dic[Bucket::class] =
function (
$c) {
64 $a =
$factory->createInstance(PlusJob::class);
66 $b =
$factory->createInstance(PlusJob::class);
72 $c->setInput([$a, $b]);
75 $userInteraction =
$factory->createInstance(DownloadInteger::class);
76 $userInteraction->setInput([
$c]);
78 $bucket->setTask($userInteraction);
86 public function testSave()
89 $bucketConnector = Mockery::namedMock(
"bucketConnectorMock", \arConnector::class);
91 $valueConnector = Mockery::namedMock(
"valueConnectorMock", \arConnector::class);
93 $taskConnector = Mockery::namedMock(
"taskConnectorMock", \arConnector::class);
95 $valueToTaskConnector = Mockery::namedMock(
"valueToTaskConnectorMock", \arConnector::class);
103 $bucketConnector->shouldReceive(
"nextID")->once()->andReturn(1);
104 $bucketConnector->shouldReceive(
"create")->once();
107 $bucketConnector->shouldReceive(
"affectedRows")->once()->andReturn(1);
108 $bucketConnector->shouldReceive(
"update")->once()->andReturn(
true);
111 for (
$i = 0;
$i < 4;
$i++) {
113 $taskConnector->shouldReceive(
"affectedRows")->once()->andReturn(0);
114 $taskConnector->shouldReceive(
"nextID")->once()->andReturn(1);
115 $taskConnector->shouldReceive(
"create")->once();
118 $taskConnector->shouldReceive(
"affectedRows")->once()->andReturn(1);
119 $taskConnector->shouldReceive(
"update")->once();
123 $valueConnector->shouldReceive(
"affectedRows")->times(7)->andReturn(0);
124 $valueConnector->shouldReceive(
"nextID")->times(7)->andReturn(1);
125 $valueConnector->shouldReceive(
"create")->times(7);
128 $valueToTaskConnector->shouldReceive(
"affectedRows")->times(7)->andReturn(0);
129 $valueToTaskConnector->shouldReceive(
"nextID")->times(7)->andReturn(1);
130 $valueToTaskConnector->shouldReceive(
"create")->times(7);
132 $this->persistence->setConnector($bucketConnector);
133 $this->persistence->saveBucketAndItsTasks($this->bucket);
139 $this->expectException(SerializationException::class);
141 $this->persistence->updateBucket($this->bucket);
144 public function testUpdateObserver()
149 $observerConnector = Mockery::namedMock(
"observerConnectorMock", \arConnector::class);
154 $observerConnector->shouldReceive(
"read")->once()->andReturn(1);
155 $observerConnector->shouldReceive(
"update")->once()->andReturn(
true);
157 $this->persistence->setConnector($observerConnector);
158 $this->persistence->updateBucket($this->bucket);
161 public function testGetObserverIdsOfUser()
164 $observerConnector = Mockery::namedMock(
"observerConnectorMock", \arConnector::class);
167 $observerConnector->shouldReceive(
"readSet")->once()->andReturn([[
"id" => 2], [
"id" => 3]]);
169 $this->persistence->setConnector($observerConnector);
170 $observer_ids = $this->persistence->getBucketIdsOfUser(5);
171 $this->assertEquals($observer_ids, [0 => 2, 1 => 3]);
174 public function testGetObserverIdsByState()
177 $observerConnector = Mockery::namedMock(
"observerConnectorMock", \arConnector::class);
180 $observerConnector->shouldReceive(
"readSet")->once()->andReturn([[
"id" => 2], [
"id" => 3]]);
182 $this->persistence->setConnector($observerConnector);
183 $observer_ids = $this->persistence->getBucketIdsByState(
State::RUNNING);
184 $this->assertEquals($observer_ids, [2 => 2, 3 => 3]);
188 public function testUserInteraction()
190 $this->setExpectedException(UserInteractionRequiredException::class);
194 $taskManager->executeTask($this->bucket->getTask(),
new MockObserver());
197 public function testContinueUserInteraction()
210 self::assertEquals($this->bucket->getCurrentTask()->getType(), $download_integer->getType());
212 $options = $download_integer->getOptions([]);
214 $dismiss = $download_integer->getRemoveOption();
216 $this->bucket->userInteraction($dismiss);
222 public function testContinueUserInteraction2()
228 $c = $this->bucket->getTask();
230 $x =
$factory->createInstance(PlusJob::class);
232 $x->setInput([
$c, 1]);
235 $this->bucket->setTask(
$x);
248 self::assertEquals($this->bucket->getCurrentTask()->getType(), $download_integer->getType());
250 $options = $download_integer->getOptions([]);
252 $dismiss = $download_integer->getRemoveOption();
254 $this->bucket->userInteraction($dismiss);
259 self::assertEquals(5,
$result->getValue());
static register(ActiveRecord $ar, arConnector $connector)
testCannotUpdateUnknownBucket()
Customizing of pimple-DIC for ILIAS.
Class NonPersistingObserver.
Class BackgroundTaskTest.