Skip to content

Commit

Permalink
LegalDocuments: Load ui factory and template later
Browse files Browse the repository at this point in the history
  • Loading branch information
lscharmer authored and mjansenDatabay committed Oct 1, 2024
1 parent 99ea744 commit 4c9c7d5
Show file tree
Hide file tree
Showing 10 changed files with 18 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function __construct()
$this->legal_documents = new ilLegalDocumentsAdministrationGUI(self::class, $config, $this->afterDocumentDeletion(...));

$this->data_protection_settings = $this->createDataProtectionSettings();
$this->ui = new UI($this->getType(), $this->container->ui()->factory(), $this->container->ui()->mainTemplate(), $this->container->language());
$this->ui = new UI($this->getType(), $this->container->ui(), $this->container->language());
}

public function getType(): string
Expand Down
2 changes: 1 addition & 1 deletion Services/LegalDocuments/classes/ConsumerToolbox/Blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public function sessionStore(): KeyValueStore

public function ui(): UI
{
return new UI($this->id, $this->container->ui()->factory(), $this->container->ui()->mainTemplate(), $this->container->language());
return new UI($this->id, $this->container->ui(), $this->container->language());
}

public function user(Settings $global_settings, UserSettings $user_settings, ilObjUser $user): User
Expand Down
8 changes: 4 additions & 4 deletions Services/LegalDocuments/classes/ConsumerToolbox/UI.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
namespace ILIAS\LegalDocuments\ConsumerToolbox;

use ILIAS\UI\Factory as UIFactory;
use ILIAS\DI\UIServices;
use ilGlobalTemplateInterface;
use ilLanguage;
use ilObjLegalDocumentsGUI;
Expand All @@ -29,20 +30,19 @@ class UI
{
public function __construct(
private readonly string $id,
private readonly UIFactory $create,
private readonly ilGlobalTemplateInterface $main_template,
private readonly UIServices $services,
private readonly ilLanguage $language
) {
}

public function create(): UIFactory
{
return $this->create;
return $this->services->factory();
}

public function mainTemplate(): ilGlobalTemplateInterface
{
return $this->main_template;
return $this->services->mainTemplate();
}

public function loadLanguageModule(string $module): void
Expand Down
3 changes: 1 addition & 2 deletions Services/LegalDocuments/classes/DefaultMappings.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ public function conditionDefinitions(): SelectionMap
{
$ui = new UI(
$this->id,
$this->container->ui()->factory(),
$this->container->ui()->mainTemplate(),
$this->container->ui(),
$this->container->language()
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public function table(object $gui, string $command, ?EditLinks $edit_links = nul
$t = new DocumentTable(
fn($criterion) => $this->toCondition($criterion)->asComponent(),
$this->document_repository,
new UI($this->id, $this->container->ui()->factory(), $this->container->ui()->mainTemplate(), $this->container->language()),
new UI($this->id, $this->container->ui(), $this->container->language()),
new DocumentModal($this->container->ui(), $this->contentAsComponent(...))
);

Expand Down
2 changes: 1 addition & 1 deletion Services/LegalDocuments/classes/Provide/ProvideHistory.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function __construct(
public function table(object $gui, string $command, string $reset_command, string $auto_complete_command): Component
{
$auto_complete_link = $this->container->ctrl()->getLinkTarget($gui, $auto_complete_command, '', true);
$ui = new UI($this->id, $this->container->ui()->factory(), $this->container->ui()->mainTemplate(), $this->container->language());
$ui = new UI($this->id, $this->container->ui(), $this->container->language());
$modal = new DocumentModal($this->container->ui(), $this->document->contentAsComponent(...));
$create = fn(string $class, ...$args) => $class === ilObjUser::class && !ilObjUser::_lookupLogin($args[0], 'login') ?
null :
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ public function __construct(
$this->container->language()->loadLanguageModule('ldoc');
$this->ui = new UI(
$this->config->legalDocuments()->id(),
$this->container->ui()->factory(),
$this->container->ui()->mainTemplate(),
$this->container->ui(),
$this->container->language()
);
$this->admin = new Administration($this->config, $this->container, $this->ui);
Expand Down
7 changes: 1 addition & 6 deletions Services/LegalDocuments/test/ConsumerToolbox/BlocksTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,7 @@ public function testGlobalStore(): void
public function testUi(): void
{
$container = $this->mock(Container::class);

$ui = $this->mock(UIServices::class);
$ui->expects(self::once())->method('factory')->willReturn($this->mock(UIFactory::class));
$ui->expects(self::once())->method('mainTemplate')->willReturn($this->mock(ilGlobalTemplateInterface::class));

$container->method('ui')->willReturn($ui);
$container->expects(self::once())->method('ui')->willReturn($this->mock(UIServices::class));
$container->expects(self::once())->method('language')->willReturn($this->mock(ilLanguage::class));

$instance = new Blocks(
Expand Down
11 changes: 6 additions & 5 deletions Services/LegalDocuments/test/ConsumerToolbox/UITest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
namespace ILIAS\LegalDocuments\test\ConsumerToolbox;

use ILIAS\LegalDocuments\test\ContainerMock;
use ILIAS\DI\UIServices;
use ILIAS\UI\Factory as UIFactory;
use PHPUnit\Framework\TestCase;
use ILIAS\LegalDocuments\ConsumerToolbox\UI;
Expand All @@ -35,27 +36,27 @@ class UITest extends TestCase

public function testConstruct(): void
{
$this->assertInstanceOf(UI::class, new UI('foo', $this->mock(UIFactory::class), $this->mock(ilGlobalTemplateInterface::class), $this->mock(ilLanguage::class)));
$this->assertInstanceOf(UI::class, new UI('foo', $this->mock(UIServices::class), $this->mock(ilLanguage::class)));
}

public function testCreate(): void
{
$ui_factory = $this->mock(UIFactory::class);
$this->assertSame($ui_factory, (new UI('foo', $ui_factory, $this->mock(ilGlobalTemplateInterface::class), $this->mock(ilLanguage::class)))->create());
$this->assertSame($ui_factory, (new UI('foo', $this->mockTree(UIServices::class, ['factory' => $ui_factory]), $this->mock(ilLanguage::class)))->create());
}

public function testMainTemplate(): void
{
$template = $this->mock(ilGlobalTemplateInterface::class);
$this->assertSame($template, (new UI('foo', $this->mock(UIFactory::class), $template, $this->mock(ilLanguage::class)))->mainTemplate());
$this->assertSame($template, (new UI('foo', $this->mockTree(UIServices::class, ['mainTemplate' => $template]), $this->mock(ilLanguage::class)))->mainTemplate());
}

public function testTxt(): void
{
$language = $this->mockMethod(ilLanguage::class, 'txt', ['ldoc_foo'], 'baz');
$language->expects(self::exactly(2))->method('exists')->withConsecutive(['bar_foo'], ['ldoc_foo'])->willReturnOnConsecutiveCalls(false, true);

$instance = new UI('bar', $this->mock(UIFactory::class), $this->mock(ilGlobalTemplateInterface::class), $language);
$instance = new UI('bar', $this->mock(UIServices::class), $language);
$this->assertSame('baz', $instance->txt('foo'));
}

Expand All @@ -64,7 +65,7 @@ public function testTxtFallback(): void
$language = $this->mockMethod(ilLanguage::class, 'txt', ['foo'], 'baz');
$language->expects(self::exactly(2))->method('exists')->withConsecutive(['bar_foo'], ['ldoc_foo'])->willReturn(false);

$instance = new UI('bar', $this->mock(UIFactory::class), $this->mock(ilGlobalTemplateInterface::class), $language);
$instance = new UI('bar', $this->mock(UIServices::class), $language);
$this->assertSame('baz', $instance->txt('foo'));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function __construct($a_id = 0, $a_id_type = self::REPOSITORY_NODE_ID, $a
}
$this->config = $config;
$this->legal_documents = new ilLegalDocumentsAdministrationGUI(self::class, $this->config, $this->afterDocumentDeletion(...));
$this->ui = new UI(Consumer::ID, $this->dic->ui()->factory(), $this->dic->ui()->mainTemplate(), $this->dic->language());
$this->ui = new UI(Consumer::ID, $this->dic->ui(), $this->dic->language());
$this->tos_settings = $this->createSettings();
}

Expand Down

0 comments on commit 4c9c7d5

Please sign in to comment.