dbxapp 4.1.3
CMS, Shop, Workflows und modulare Geschäftsanwendungen
Loading...
Searching...
No Matches
dbxTPL_design_slots_test.php
Go to the documentation of this file.
1<?php
2
3class dbxObj {}
4
6 public string $root;
7 public array $registered = array();
8 public array $system = array('dbx_design' => 'demo', 'dbx_activ_design' => 'demo');
9
10 public function get_base_dir(): string { return rtrim($this->root, '/\\') . DIRECTORY_SEPARATOR; }
11 public function get_base_url(): string { return 'https://localhost/dbxapp/'; }
12 public function get_system_var(string $key, $default = '', ...$rest) { return $this->system[$key] ?? $default; }
13 public function get_request_var(string $key, $default = '', ...$rest) { return $default; }
14 public function get_skin(): string { return 'blau'; }
15 public function get_skin_css(): string { return 'skin-blau.css'; }
16 public function get_skin_class(): string { return 'skin-blau'; }
17 public function os_path(string $path): string { return str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $path); }
18 public function register_editor_file(string $kind, string $file): void { $this->registered[] = array($kind, $file); }
19}
20
22 static $api;
24 return $api;
25}
26
27$root = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'dbx-tpl-slots-' . bin2hex(random_bytes(5));
28dbx()->root = $root;
29$htm = $root . DIRECTORY_SEPARATOR . 'dbx' . DIRECTORY_SEPARATOR . 'design' . DIRECTORY_SEPARATOR . 'demo' . DIRECTORY_SEPARATOR . 'htm';
30mkdir($htm, 0777, true);
31file_put_contents($htm . '/logo.htm', '<img src="../img/logo.png" data-design="{dbx:design}">');
32file_put_contents($htm . '/branding.htm', '<strong>Demo</strong>');
33file_put_contents($htm . '/footer.htm', '<footer>{dbx:color}</footer>');
34
35require_once dirname(__DIR__) . '/dbxTPL.class.php';
36$tpl = new dbxTPL();
37$out = $tpl->replace_design_slots('[dbx:logo]|[dbx:branding]|[dbx:footer]', 'demo');
38
39$expected = '<img src="dbx/design/demo/img/logo.png" data-design="demo">|<strong>Demo</strong>|<footer>blau</footer>';
40if ($out !== $expected) {
41 fwrite(STDERR, "FAIL: Design-Slots wurden nicht richtig eingesetzt.\n$out\n");
42 exit(1);
43}
44$missing = $tpl->replace_design_slots('A[dbx:logo]B[dbx:footer]C', 'missing');
45if ($missing !== 'ABC') {
46 fwrite(STDERR, "FAIL: Fehlende Fragmente wurden nicht leer aufgeloest.\n");
47 exit(2);
48}
49file_put_contents($htm . '/branding.htm', '<strong>Demo</strong>[dbx:content][dbx:footer]');
50$guarded = $tpl->replace_design_slots('[dbx:branding]', 'demo');
51if ($guarded !== '<strong>Demo</strong>') {
52 fwrite(STDERR, "FAIL: Verschachtelte Design-/Content-Slots wurden nicht abgefangen.\n");
53 exit(3);
54}
55
56foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($root, FilesystemIterator::SKIP_DOTS), RecursiveIteratorIterator::CHILD_FIRST) as $file) {
57 $file->isDir() ? rmdir($file->getPathname()) : unlink($file->getPathname());
58}
59rmdir($root);
60echo "OK dbxTPL design slots\n";
Gemeinsame Basisklasse fuer dbXapp-System-, Modul- und Include-Objekte.
Definition dbxKernel.php:63
get_system_var(string $key, $default='',... $rest)
get_request_var(string $key, $default='',... $rest)
register_editor_file(string $kind, string $file)
foreach( $iterator as $file) if(! $groups) $expected
$api system['dbx_permalink']
if($web->content_permalink_redirect_target() !=='') $tpl
if($out !==$expected) $missing
exit
Definition index.php:146