ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
ilContactGUITest.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
32 use ILIAS\UI\Component\MessageBox\Factory as MessageBoxFactory;
34 
35 require_once __DIR__ . '/../../LegalDocuments/tests/ContainerMock.php';
36 
38 {
39  use ContainerMock;
40 
41  private ?Container $old_dic = null;
42  private array $container = [];
43 
44  public function setUp(): void
45  {
46  $this->container = [
47  'ilDB' => $this->mock(ilDBInterface::class),
48  'tpl' => $this->mock(ilGlobalTemplateInterface::class),
49  'ilCtrl' => $this->mock(ilCtrlInterface::class),
50  'lng' => $this->mock(ilLanguage::class),
51  'ilTabs' => $this->mock(ilTabsGUI::class),
52  'ilHelp' => $this->mock(ilHelpGUI::class),
53  'ilToolbar' => $this->mock(ilToolbarGUI::class),
54  'ilUser' => $this->mock(ilObjUser::class),
55  'ilErr' => $this->mock(ilErrorHandling::class),
56  'rbacsystem' => $this->mock(ilRbacSystem::class),
57  'ui.renderer' => $this->mock(Renderer::class),
58  'ui.factory' => $this->mock(UIFactory::class),
59  'query' => $this->mock(ArrayBasedRequestWrapper::class),
60  'static_url' => $this->mock(StaticURL::class),
61  'ilObjDataCache' => $this->mock(ilObjectDataCache::class),
62  ];
63  $this->old_dic = $GLOBALS['DIC'] ?? null;
64  $GLOBALS['DIC'] = $this->mockTree(Container::class, [
65  'database' => $this->container['ilDB'],
66  'ui' => ['renderer' => $this->container['ui.renderer'], 'factory' => $this->container['ui.factory']],
67  'http' => ['wrapper' => ['query' => $this->container['query']]],
68  ]);
69  $GLOBALS['DIC']->method('offsetGet')->willReturnCallback(fn($k) => $this->container[$k]);
70  }
71 
72  public function tearDown(): void
73  {
74  $GLOBALS['DIC'] = $this->old_dic;
75  }
76 
77  public function testConstruct(): void
78  {
79  if (!defined('ILIAS_LOG_ENABLED')) {
80  define('ILIAS_LOG_ENABLED', false);
81  }
82 
83  $this->assertInstanceOf(ilContactGUI::class, new ilContactGUI((new class () extends ilFormatMail {
84  public function __construct()
85  {
86  }
87  })::class));
88  }
89 
90  public function testShowContacts(): void
91  {
92  $this->setMailRefId(123);
93  $this->setBuddySystem($this->mockMethod(ilBuddySystem::class, 'isEnabled', [], true));
94 
95  if (!defined('ILIAS_HTTP_PATH')) {
96  define('ILIAS_HTTP_PATH', 'http://ilias.de/');
97  }
98  if (!defined('CLIENT_ID')) {
99  define('CLIENT_ID', 'dummy');
100  }
101 
102  $query_params = [
103  'inv_room_ref_id' => 9,
104  'inv_usr_ids' => [56],
105  ];
106 
107  $this->container['query']->expects(self::exactly(2))->method('retrieve')->willReturnCallback(fn(string $key) => $query_params[$key]);
108 
109  $this->container['query']->method('has')->willReturnCallback(fn($key) => isset($query_params[$key]));
110 
111  $relations_table_class = get_class(new class () extends RelationsTable {
112  public static array $components;
113  public function __construct()
114  {
115  }
116 
117  public function build(array $multi_actions, string $target_url, callable $action): array
118  {
119  return self::$components;
120  }
121  });
122 
123  $relations_table_class::$components = [$this->mock(Component::class)];
124 
125  $ul = $this->mock(Unordered::class);
126  $message_box = $this->mock(MessageBox::class);
127  $message_box->expects(self::once())->method('withButtons')->willReturn($message_box);
128 
129 
130  $this->container['ui.factory']->method('messageBox')->willReturn($this->mockTree(MessageBoxFactory::class, ['success' => $message_box]));
131  $this->container['ui.factory']->method('listing')->willReturn($this->mockTree(Listing::class, ['unordered' => $ul]));
132 
133  $render_params = [null, 'bar' => $ul, 'foo' => [$message_box, ...$relations_table_class::$components]];
134  $this->container['ui.renderer']->expects(self::exactly(2))->method('render')->willReturnCallback(function ($arg) use (&$render_params) {
135  $this->assertSame(next($render_params), $arg);
136  return key($render_params);
137  });
138  $this->container['tpl']->expects(self::once())->method('setContent')->with('foo');
139 
140  $gui = new ilContactGUI(get_class(new class () extends ilFormatMail {
141  public function __construct()
142  {
143  }
144  }), $relations_table_class);
145 
146  (new ReflectionMethod($gui, 'showContacts'))->invoke($gui);
147 
148  $this->setBuddySystem(null);
149  $this->setMailRefId(null);
150  }
151 
152  private function setBuddySystem(?ilBuddySystem $system): void
153  {
154  $p = new ReflectionProperty(ilBuddySystem::class, 'instance');
155  $p->setValue(null, $system);
156  }
157 
158  private function setMailRefId(?int $mail_ref): void
159  {
160  $p = new ReflectionProperty(ilMailGlobalServices::class, 'global_mail_services_cache');
161  $array = $p->getValue();
162  $array[ilMailGlobalServices::CACHE_TYPE_REF_ID] = $mail_ref;
163  $p->setValue(null, $array);
164  }
165 }
This is how a factory for Message Boxes looks like.
Definition: Factory.php:26
setBuddySystem(?ilBuddySystem $system)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setMailRefId(?int $mail_ref)
Customizing of pimple-DIC for ILIAS.
Definition: Container.php:35
$components
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
$GLOBALS["DIC"]
Definition: wac.php:53
This is how a factory for listings looks like.
Definition: Factory.php:26
__construct(Container $dic, ilPlugin $plugin)