ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
ilMailBaseTestCase.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
24 
25 abstract class ilMailBaseTestCase extends TestCase
26 {
27  private ?Container $dic = null;
28 
29  protected function brutallyTrimHTML(string $html): string
30  {
31  $html = str_replace(["\n", "\r", "\t"], '', $html);
32  $html = preg_replace('# {2,}#', ' ', $html);
33  $html = preg_replace('/<!--(.|\s)*?-->/', '', $html);
34  $html = preg_replace("/>(\s+)</", '><', $html);
35  $html = str_replace([' >', ' <'], ['>', '<'], $html);
36 
37  return trim($html);
38  }
39 
40  protected function setUp(): void
41  {
42  if (!defined('ANONYMOUS_USER_ID')) {
43  define('ANONYMOUS_USER_ID', 13);
44  }
45 
46  global $DIC;
47 
48  $this->dic = is_object($DIC) ? clone $DIC : $DIC;
49 
50  $DIC = new Container();
51  $DIC['legalDocuments'] = fn() => $this->getMockBuilder(Conductor::class)->disableOriginalConstructor()->getMock();
52 
53  parent::setUp();
54  }
55 
56  protected function tearDown(): void
57  {
58  global $DIC;
59 
60  $DIC = $this->dic;
61 
62  parent::tearDown();
63  }
64 
65  protected function setGlobalVariable(string $name, $value): void
66  {
67  global $DIC;
68 
69  $GLOBALS[$name] = $value;
70 
71 
72  unset($DIC[$name]);
73  $DIC[$name] = static fn(Container $c) => $GLOBALS[$name];
74  }
75 }
brutallyTrimHTML(string $html)
$c
Definition: deliver.php:25
Customizing of pimple-DIC for ILIAS.
Definition: Container.php:35
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
setGlobalVariable(string $name, $value)
$GLOBALS["DIC"]
Definition: wac.php:53
global $DIC
Definition: shib_login.php:26