ILIAS  trunk Revision v11.0_alpha-1689-g66c127b4ae8
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
ilDidacticTemplatePatternTest.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
23 
30 {
31  protected Container $dic;
32 
33  protected function setUp(): void
34  {
35  $this->initPatternDependencies();
36  parent::setUp();
37  }
38 
39  public function testConstruct(): void
40  {
41  $include_pattern = new ilDidacticTemplateIncludeFilterPattern();
42  $this->assertInstanceOf(ilDidacticTemplateIncludeFilterPattern::class, $include_pattern);
43 
44  $exclude_pattern = new ilDidacticTemplateExcludeFilterPattern();
45  $this->assertInstanceOf(ilDidacticTemplateExcludeFilterPattern::class, $exclude_pattern);
46  }
47 
48  public function testMatches(): void
49  {
50  $include_pattern = new ilDidacticTemplateIncludeFilterPattern();
51  $include_pattern->setPatternSubType(ilDidacticTemplateFilterPattern::PATTERN_SUBTYPE_REGEX);
52  $include_pattern->setPattern('^il_crs_admin_[0-9]+$');
53  $this->assertTrue($include_pattern->valid('il_crs_admin_123'));
54 
55  $exclude_pattern = new ilDidacticTemplateExcludeFilterPattern();
56  $exclude_pattern->setPatternSubType(ilDidacticTemplateFilterPattern::PATTERN_SUBTYPE_REGEX);
57  $exclude_pattern->setPattern('il_crs_admin_[0-9]+');
58  $this->assertTrue($exclude_pattern->valid('il_grp_admin'));
59  }
60 
61  protected function setGlobalVariable(string $name, $value): void
62  {
63  global $DIC;
64 
65  $GLOBALS[$name] = $value;
66  unset($DIC[$name]);
67  $DIC[$name] = static function (\ILIAS\DI\Container $c) use ($value) {
68  return $value;
69  };
70  }
71 
72  protected function initPatternDependencies(): void
73  {
74  $this->dic = new Container();
75  $GLOBALS['DIC'] = $this->dic;
76 
77  $this->setGlobalVariable('ilDB', $this->createMock(ilDBInterface::class));
78 
79  $logger = $this->getMockBuilder(ilLogger::class)
80  ->disableOriginalConstructor()
81  ->getMock();
82 
83  $logger_factory = $this->getMockBuilder(ilLoggerFactory::class)
84  ->disableOriginalConstructor()
85  ->onlyMethods(['getComponentLogger'])
86  ->getMock();
87  $logger_factory->method('getComponentLogger')->willReturn($logger);
88  $this->setGlobalVariable('ilLoggerFactory', $logger_factory);
89  }
90 }
$c
Definition: deliver.php:25
Customizing of pimple-DIC for ILIAS.
Definition: Container.php:35
$GLOBALS["DIC"]
Definition: wac.php:53
global $DIC
Definition: shib_login.php:22
Implementation of an include filter pattern for didactic template actions.
Unit tests for class ilDidacticTemplate.
Implementation of an include filter pattern for didactic template actions.