Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
chlulei committed Aug 13, 2024
1 parent c5001cc commit 9841658
Show file tree
Hide file tree
Showing 6 changed files with 409 additions and 91 deletions.
5 changes: 3 additions & 2 deletions components/ILIAS/Dashboard/classes/class.ilDashboardGUI.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,9 @@ public function __construct()
$this->ctrl->saveParameter($this, ['view']);

$test = new ilMyExportTest();
$test->storeIterativeFromString();
$test->deleteAllResources();
#$test->storeIterativeFromString();
$exp_db = new ilMyExportDBTest();
$exp_db->deleteAllResources();
}

public function executeCommand(): void
Expand Down
8 changes: 8 additions & 0 deletions components/ILIAS/Export/classes/class.ilExportGUI.php
Original file line number Diff line number Diff line change
Expand Up @@ -469,9 +469,17 @@ protected function saveItemSelection(): void
// Export container
$cexp = new ilExportContainer($eo);
$cexp->exportObject($this->obj->getType(), $this->obj->getId());

$test_exp = new ilMyExportObjectTest();
$rid = $test_exp->exportObject($this->obj->getType(), $this->obj->getId());
#$test_exp->download($rid);
} else {
$exp = new ilExport();
$exp->exportObject($this->obj->getType(), $this->obj->getId());

$test_exp = new ilMyExportObjectTest();
$rid = $test_exp->exportObject($this->obj->getType(), $this->obj->getId());
#$test_exp->download($rid);
}

// Delete export options
Expand Down
118 changes: 118 additions & 0 deletions components/ILIAS/Export/classes/class.ilMyExportDBTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
<?php

use ILIAS\Filesystem\Filesystems;
use ILIAS\ResourceStorage\Services as ResourcesStorageService;
use ILIAS\Filesystem\Stream\Streams;
use ILIAS\Filesystem\Util\Archive\Zip;
use ILIAS\Filesystem\Util\Archive\ZipOptions;
use ILIAS\ResourceStorage\Stakeholder\AbstractResourceStakeholder;
use ILIAS\ResourceStorage\Identification\ResourceIdentification;

class ilMyExportDBTest
{
protected const TABLE_NAME = "dummy_test2";

protected ResourcesStorageService $irss;
protected ilLogger $logger;
protected ilDBInterface $db;
protected Filesystems $filesystems;

public function __construct()
{
global $DIC;
$this->irss = $DIC->resourceStorage();
$this->logger = $DIC->logger()->root();
$this->db = $DIC->database();
$this->filesystems = $DIC->filesystem();
$this->initRidReferenceTable();
}

protected function initRidReferenceTable(): void
{
if ($this->db->tableExists(self::TABLE_NAME)) {
return;
}
$this->db->createTable(self::TABLE_NAME, [
'rid' => [
'type' => 'text',
'length' => 64,
'default' => '',
'notnull' => true
],
'obj_id' => [
'type' => 'integer',
'length' => 8,
'default' => '',
'notnull' => true
],
]);
$this->db->addPrimaryKey(self::TABLE_NAME, ["rid"]);
}

public function saveRid(int $obj_id, string $rid): void
{
$this->logger->debug("Storing resource: " . $rid);
$this->db->insert(self::TABLE_NAME, [
"rid" => ["text",$rid],
"obj_id" => ["integer",$obj_id],
]);
}

public function removeRid(string $rid): void
{
$this->logger->debug("Removing resource: " . $rid);
$this->db->manipulate("DELETE FROM " . $this->db->quoteIdentifier(self::TABLE_NAME) . " WHERE rid = " . $this->db->quote($rid));
}

public function getStakeHolder(?int $usr_id = null): AbstractResourceStakeholder
{
return new class ($usr_id) extends AbstractResourceStakeholder {
protected $lcl_usr_id;
public function __construct(?int $lcl_usr_id = null)
{
$this->lcl_usr_id = $lcl_usr_id;
}
public function getId(): string
{
return "test_export";
}
public function getOwnerOfNewResources(): int
{
return $this->lcl_usr_id ?? 6;
}
};
}

public function delete(): void
{
$res = $this->db->query("SELECT rid FROM il_resource");
$resource_id_strs = [];
while ($row = $res->fetchAssoc()) {
$resource_id_strs[] = $row['rid'];
}
foreach ($resource_id_strs as $resource_id_str) {
$rid = $this->irss->manageContainer()->find($resource_id_str);
if (!is_null($rid)) {
$this->irss->manageContainer()->remove($rid, $this->getStakeHolder());
}
$this->logger->debug("Removed Resource: " . $resource_id_str);
}
}

public function deleteAllResources(): void
{
$res = $this->db->query("SELECT rid FROM " . self::TABLE_NAME);
$resource_id_strs = [];
while ($row = $res->fetchAssoc()) {
$resource_id_strs[] = $row['rid'];
}
foreach ($resource_id_strs as $resource_id_str) {
$rid = $this->irss->manageContainer()->find($resource_id_str);
if (!is_null($rid)) {
$this->irss->manageContainer()->remove($rid, $this->getStakeHolder());
}
$this->removeRid($resource_id_str);
$this->logger->debug("Removed Resource: " . $resource_id_str);
}
}
}
Loading

0 comments on commit 9841658

Please sign in to comment.