From 7557d07622d8759d5566c5d5c7fa7fc0bc126c80 Mon Sep 17 00:00:00 2001 From: Cameron Date: Fri, 22 Jan 2021 15:43:57 -0800 Subject: [PATCH] Rewrote getTemplate test and added example theme template override (bootstrap3) of plugin template (gallery) --- e107_handlers/e107_class.php | 6 +- e107_tests/tests/unit/e107Test.php | 92 +++++---- .../templates/gallery/gallery_template.php | 195 ++++++++++++++++++ .../bootstrap3/templates/menu_template.php | 1 - 4 files changed, 256 insertions(+), 38 deletions(-) create mode 100644 e107_themes/bootstrap3/templates/gallery/gallery_template.php diff --git a/e107_handlers/e107_class.php b/e107_handlers/e107_class.php index 759052191..cbb0ba266 100644 --- a/e107_handlers/e107_class.php +++ b/e107_handlers/e107_class.php @@ -3196,7 +3196,7 @@ class e107 * * @param string $plug_name if null getCoreTemplate method will be called * @param string $id - file prefix, e.g. calendar for calendar_template.php - * @param string|null $key + * @param string|null $key $YOURTEMPLATE_TEMPLATE[$key] * @param boolean $override see {@link getThemeInfo()} * @param boolean $merge merge theme with plugin templates, default is false * @param boolean $info retrieve template info only @@ -3208,10 +3208,12 @@ class e107 { return self::getCoreTemplate($id, $key, $override, $merge, $info); } + if($id == null || $id === true) // loads {$plug_name}/templates/{$plug_name}_template.php and an array ${PLUG_NAME}_TEMPLATE { $id = $plug_name; } + $reg_path = 'plugin/'.$plug_name.'/templates/'.$id; $reg_path .= ($override) ? '/ext' : ''; @@ -3494,7 +3496,7 @@ class e107 return $ret; } - return ($ret && is_array($ret) && isset($ret[$key]) ? $ret[$key] : false); + return ($ret && is_array($ret) && isset($ret[$key])) ? $ret[$key] : false; } /** diff --git a/e107_tests/tests/unit/e107Test.php b/e107_tests/tests/unit/e107Test.php index c5db9e7d8..3d39dd397 100644 --- a/e107_tests/tests/unit/e107Test.php +++ b/e107_tests/tests/unit/e107Test.php @@ -812,48 +812,70 @@ class e107Test extends \Codeception\Test\Unit } */ + public function testGetTemplateOverride() + { + // Loads e107_themes/bootstrap3/templates/gallery/gallery_template.php + $template = e107::getTemplate('gallery', null, null, true, false); // true & false default, loads theme (override true) + $this->assertEquals("My Gallery", $template['list']['caption']); + + // Duplicate to load registry + $template2 = e107::getTemplate('gallery', null, null, true, false); // true & false default, loads theme (override true) + $this->assertEquals("My Gallery", $template2['list']['caption']); + + $this->assertSame($template, $template2); + + } + + + public function testGetTemplateOverrideMerge() + { + // Loads e107_plugins/gallery/templates/gallery_template.php then overwrites it with e107_themes/bootstrap3/templates/gallery/gallery_template.php + $template = e107::getTemplate('gallery', null, null, true, true); // theme override is enabled, and theme merge is enabled. + $this->assertArrayHasKey('merged-example', $template); + $this->assertEquals("My Gallery", $template['list']['caption']); // ie. from the original + $this->assertNotEmpty($template['merged-example']); + + // duplicate to load registry + $template2 = e107::getTemplate('gallery', null, null, true, true); // theme override is enabled, and theme merge is enabled. + $this->assertArrayHasKey('merged-example', $template2); + $this->assertEquals("My Gallery", $template2['list']['caption']); // ie. from the original + $this->assertNotEmpty($template2['merged-example']); + + $this->assertSame($template, $template2); + + } + + public function testGetTemplateMerge() + { + + // // ie. should be from plugin template, not theme. + $template = e107::getTemplate('gallery', null, null, false, true); // theme override is disabled, theme merge is enabled. + $this->assertEquals("Gallery", $template['list']['caption']); + $this->assertArrayNotHasKey('merged-example', $template); + + // duplicate to load registry. + $template2 = e107::getTemplate('gallery', null, null, false, true); // theme override is disabled, theme merge is enabled. + $this->assertEquals("Gallery", $template2['list']['caption']); + $this->assertArrayNotHasKey('merged-example', $template2); + + $this->assertSame($template, $template2); + + } /** - * This test checks getTemplate() use on loading between the core download plugin template and the _blank theme download template + * This test checks getTemplate() with no merging or override. */ public function testGetTemplate() { - // clear all template related registry entries. - // $cleared = $this->clearRelatedRegistry('templates/download'); - return null; // FIXME - getTemplate() registry issue. - // cached with bootstrap3 theme template. - //FIXME Remove 'false' from the line below to see Undefined 'header' issue with registry. - $template = e107::getTemplate('download', null, null, false); // theme override is enabled by default. - - // e107::getConfig()->set('sitetheme', '_blank'); - e107::plugLan('download', 'front', true); - - // FIXME getTemplate registry doesn't handle the theme change correctly. - -/* - $template = e107::getTemplate('download', null, null); // theme override is enabled by default. - $this->assertEquals('{DOWNLOAD_BREADCRUMB} Custom', $template['header']); // ie. should be from _blank theme download template (override of plugin). - $footer = empty($template['footer']); // theme overrides everything, since merge is not enabled. theme does not contain 'footer'. - $this->assertTrue($footer);*/ - - $template = e107::getTemplate('download', null, null, false); // theme override is disabled. - $this->assertEquals("{DOWNLOAD_BREADCRUMB}", $template['header']); // ie. should be from plugin template, not theme. - $this->assertEquals('', $template['footer']); // main plugin template is active, since override is false. 'footer' is set. -/* - $template = e107::getTemplate('download', null, null, true, true); // theme override is enabled, and theme merge is enabled. - $this->assertEquals("{DOWNLOAD_BREADCRUMB} Custom", $template['header']); //from theme - $this->assertEquals("", $template['footer']); // 'footer' missing from theme, so plugin template used. ie. arrays have been merged. -*/ - - $template = e107::getTemplate('download', null, null, false, true); // theme override is disabled, theme merge is enabled. - $this->assertEquals("{DOWNLOAD_BREADCRUMB}", $template['header']); // ie. should be from plugin template, not theme. - // $this->assertEquals("test", $template['other']); // 'test' is missing from plugin template, but merge is enabled. Not an override of plugin template key so merge is okay. - // FIXME above.. - // var_dump($template['other']); - - // e107::getConfig()->set('sitetheme', 'bootstrap3'); + // Loads e107_plugins/gallery/templates/gallery_template.php + $template = e107::getTemplate('gallery', null, null, false, false); // theme override is disabled. + $this->assertEquals("Gallery", $template['list']['caption']); + // Duplicate to load registry. + $template2 = e107::getTemplate('gallery', null, null, false, false); // theme override is disabled. + $this->assertEquals("Gallery", $template2['list']['caption']); + $this->assertSame($template, $template2); } /* diff --git a/e107_themes/bootstrap3/templates/gallery/gallery_template.php b/e107_themes/bootstrap3/templates/gallery/gallery_template.php new file mode 100644 index 000000000..00ab92545 --- /dev/null +++ b/e107_themes/bootstrap3/templates/gallery/gallery_template.php @@ -0,0 +1,195 @@ + +'; + +$GALLERY_TEMPLATE['list']['item'] = ' +
+
+ {GALLERY_THUMB=w=300&h=200} +
{GALLERY_CAPTION}
+
+
+'; + +$GALLERY_TEMPLATE['list']['end'] = ' + +
+ + +
+'; + +// Bootstrap3 Compatible. +$GALLERY_TEMPLATE['cat']['caption'] = LAN_PLUGIN_GALLERY_TITLE; + +$GALLERY_TEMPLATE['cat']['start'] = '{GALLERY_BREADCRUMB} + +'; + +// {GALLERY_SLIDESHOW=X} X = Gallery Category. Default: 1 (ie. 'gallery_1') Overrides preference in admin. +// {GALLERY_SLIDES=X} X = number of items per slide. +// {GALLERY_JUMPER=space} will remove numbers and just leave spaces. + +$GALLERY_TEMPLATE['slideshow_wrapper'] = ' + + + +'; + +$GALLERY_TEMPLATE['slideshow_slide_item'] = '{GALLERY_THUMB: w=150&h=120}'; + +$GALLERY_TEMPLATE['prettyphoto']['content'] = ' +
+
 
+
+
+
+
+
+
+
+ +
+
+
+
+
+
+
+
+
+'; + +$GALLERY_TEMPLATE['prettyphoto']['gallery_item'] = ' + +'; + +$GALLERY_TEMPLATE['prettyphoto']['image_item'] = ' + +'; + +$GALLERY_TEMPLATE['prettyphoto']['flash_item'] = ' + + + + + + + +'; + +$GALLERY_TEMPLATE['prettyphoto']['quicktime_item'] = ' + + + + + + +'; + +$GALLERY_TEMPLATE['prettyphoto']['iframe_item'] = ' + +'; + +$GALLERY_TEMPLATE['prettyphoto']['inline_item'] = ' +
{content}
+'; + +$GALLERY_TEMPLATE['prettyphoto']['custom_item'] = ''; + +$GALLERY_TEMPLATE['prettyphoto']['social_item'] = ' +
+ + +
+'; + + +$GALLERY_TEMPLATE['merged-example'] = 'Example'; + + + +/* + +$GALLERY_TEMPLATE['portfolio']['start'] = '<-- start portfolio -->'; +$GALLERY_TEMPLATE['portfolio']['item'] = '{GALLERY_CAPTION=text}'; +$GALLERY_TEMPLATE['portfolio']['end'] = '<-- end portfolio -->'; + +*/ diff --git a/e107_themes/bootstrap3/templates/menu_template.php b/e107_themes/bootstrap3/templates/menu_template.php index 4b8a6af32..33bb49bc1 100644 --- a/e107_themes/bootstrap3/templates/menu_template.php +++ b/e107_themes/bootstrap3/templates/menu_template.php @@ -50,4 +50,3 @@ -?> \ No newline at end of file