ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
ilTemplateTest.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
23 class ilTemplateTest extends TestCase
24 {
26  protected string $il_root;
27 
28  public function setUp(): void
29  {
30  $this->il_template = new class () extends ilTemplate {
31  protected string $style = 'delos';
32  protected string $skin = 'default';
33  protected bool $file_exists = true;
34  public function __construct()
35  {
36  }
37  public function _getTemplatePath(string $a_tplname, ?string $a_in_module = null): string
38  {
39  return $this->getTemplatePath($a_tplname, $a_in_module);
40  }
41  protected function getCurrentStyle(): ?string
42  {
43  return $this->style;
44  }
45  public function withStyle(string $style)
46  {
47  $clone = clone $this;
48  $clone->style = $style;
49  return $clone;
50  }
51  public function withSkin(string $skin)
52  {
53  $clone = clone $this;
54  $clone->skin = $skin;
55  return $clone;
56  }
57  protected function getCurrentSkin(): ?string
58  {
59  return $this->skin;
60  }
61  protected function fileExistsInSkin(string $path): bool
62  {
63  return $this->file_exists;
64  }
65  public function withFileExists(bool $file_exists)
66  {
67  $clone = clone $this;
68  $clone->file_exists = $file_exists;
69  return $clone;
70  }
71  };
72  $this->il_root = realpath(__DIR__ . '/../../../../');
73 
74  }
75 
76 
77  public static function templatePathDataProvider(): array
78  {
79  $il_root = realpath(__DIR__ . '/../../../../');
80  return [
81  'standard component template' => [
82  'skin' => 'default', 'style' => 'delos', 'file_exists' => true,
83  'tpl_filename' => 'tpl.appointment_panel.html',
84  'component' => 'components/ILIAS/Calendar',
85  'expected' => $il_root . '/components/ILIAS/Calendar/templates/default/tpl.appointment_panel.html'
86  ],
87  'plugin template' => [
88  'skin' => 'default', 'style' => 'delos', 'file_exists' => true,
89  'tpl_filename' => 'tpl.test.html',
90  //ilPlugin::getDirectory() will return something like this:
91  'component' => $il_root . '/components/ILIAS/Component/classes/../../../../public/Customizing/global/plugins/Services/UIComponent/UserInterfaceHook/EditorAsMode',
92  'expected' => $il_root . '/components/ILIAS/Component/classes/../../../../public/Customizing/global/plugins/Services/UIComponent/UserInterfaceHook/EditorAsMode/templates/default/tpl.test.html',
93  ],
94  'plugin template_file_no_component' => [
95  'skin' => 'default', 'style' => 'delos', 'file_exists' => true,
96  'tpl_filename' => $il_root . '/components/ILIAS/Component/classes/../../../../public/Customizing/global/plugins/Services/User/UDFDefinition/CascadingSelect/templates/tpl.prop_cascading_select.html',
97  'component' => '',
98  'expected' => $il_root . '/components/ILIAS/Component/classes/../../../../public/Customizing/global/plugins/Services/User/UDFDefinition/CascadingSelect/templates/tpl.prop_cascading_select.html',
99  ],
100  'custom skin' => [
101  'skin' => 'mySkin', 'style' => 'myStyle', 'file_exists' => true,
102  'tpl_filename' => 'tpl.external_settings.html',
103  'component' => 'components/ILIAS/Administration',
104  'expected' => $il_root . '/public/Customizing/skin/mySkin/myStyle/components/ILIAS/Administration/tpl.external_settings.html',
105  ],
106  'custom skin, unaltered file' => [
107  'skin' => 'mySkin', 'style' => 'myStyle', 'file_exists' => false,
108  'tpl_filename' => 'tpl.external_settings.html',
109  'component' => 'components/ILIAS/Administration',
110  'expected' => $il_root . '/components/ILIAS/Administration/templates/default/tpl.external_settings.html',
111  ],
112  'ui template' => [
113  'skin' => 'default', 'style' => 'delos', 'file_exists' => true,
114  'tpl_filename' => 'components/ILIAS/UI/src/templates/default/Input/tpl.standard.html',
115  'component' => '',
116  'expected' => $il_root . '/components/ILIAS/UI/src/templates/default/Input/tpl.standard.html',
117  ],
118  'ui template from skin' => [
119  'skin' => 'mySkin', 'style' => 'myStyle', 'file_exists' => true,
120  'tpl_filename' => 'components/ILIAS/UI/src/templates/default/Input/tpl.standard.html',
121  'component' => '',
122  'expected' => $il_root . '/public/Customizing/skin/mySkin/myStyle/UI/Input/tpl.standard.html',
123  ],
124  'ui template from skin, unaltered' => [
125  'skin' => 'mySkin', 'style' => 'myStyle', 'file_exists' => false,
126  'tpl_filename' => 'components/ILIAS/UI/src/templates/default/Input/tpl.standard.html',
127  'component' => '',
128  'expected' => $il_root . '/components/ILIAS/UI/src/templates/default/Input/tpl.standard.html',
129  ],
130  'trailing slash' => [
131  'skin' => 'default', 'style' => 'delos', 'file_exists' => true,
132  'tpl_filename' => 'tpl.test.html',
133  'component' => 'components/ILIAS/Test/',
134  'expected' => $il_root . '/components/ILIAS/Test/templates/default/tpl.test.html',
135  ],
136 
137  ];
138  }
139 
140  #[\PHPUnit\Framework\Attributes\DataProvider('templatePathDataProvider')]
141  public function testGetTemplatePath(
142  string $skin,
143  string $style,
144  bool $file_exists,
145  string $tpl_filename,
146  string $component,
147  string $expected
148  ): void {
149  $path = $this->il_template
150  ->withSkin($skin)
151  ->withStyle($style)
152  ->withFileExists($file_exists)
153  ->_getTemplatePath($tpl_filename, $component);
154 
155  $this->assertEquals($expected, $path);
156  }
157 
158 }
testGetTemplatePath(string $skin, string $style, bool $file_exists, string $tpl_filename, string $component, string $expected)
static templatePathDataProvider()
$path
Definition: ltiservices.php:29
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
ilTemplate $il_template
__construct(Container $dic, ilPlugin $plugin)