add unit tests for rcmail_output_html::get_template_logo

pull/6983/head
PhilW 5 years ago
parent 0ae3823853
commit 714ea7b128

@ -413,7 +413,7 @@ $config['support_url'] = '';
// show the image /images/logo_login.png for the Login screen in the Elastic skin // show the image /images/logo_login.png for the Login screen in the Elastic skin
"elastic:login" => "/images/logo_login.png", "elastic:login" => "/images/logo_login.png",
// show the image /images/logo_small.png in the Elastic skin // show the image /images/logo_small.png in the Elastic skin
"elastic[small]" => "/images/logo_small.png", "elastic:*[small]" => "/images/logo_small.png",
// show the image /images/larry.png in the Larry skin // show the image /images/larry.png in the Larry skin
"larry:*" => "/images/larry.png", "larry:*" => "/images/larry.png",
// show the image /images/logo_login.png on the login template in all skins // show the image /images/logo_login.png on the login template in all skins

@ -1353,7 +1353,7 @@ EOF;
else if ($object == 'logo') { else if ($object == 'logo') {
$attrib += array('alt' => $this->xml_command(array('', 'object', 'name="productname"'))); $attrib += array('alt' => $this->xml_command(array('', 'object', 'name="productname"')));
if (!empty($attrib['type']) && ($template_logo = $this->get_template_logo(null, $attrib['type'], true)) !== null) { if (!empty($attrib['type']) && ($template_logo = $this->get_template_logo($attrib['type'])) !== null) {
$attrib['src'] = $template_logo; $attrib['src'] = $template_logo;
} }
else if (($template_logo = $this->get_template_logo()) !== null) { else if (($template_logo = $this->get_template_logo()) !== null) {
@ -1363,7 +1363,7 @@ EOF;
// process alternative logos (eg for Elastic small screen) // process alternative logos (eg for Elastic small screen)
foreach ($attrib as $key => $value) { foreach ($attrib as $key => $value) {
if (preg_match('/data-src-(.*)/', $key, $matches)) { if (preg_match('/data-src-(.*)/', $key, $matches)) {
if (($template_logo = $this->get_template_logo(null, $matches[1], true)) !== null) { if (($template_logo = $this->get_template_logo($matches[1])) !== null) {
$attrib[$key] = $template_logo; $attrib[$key] = $template_logo;
} }
@ -1447,7 +1447,7 @@ EOF;
// special handling for favicon // special handling for favicon
if ($object == 'links' && $name == 'shortcut icon' && empty($args[$param])) { if ($object == 'links' && $name == 'shortcut icon' && empty($args[$param])) {
if ($href = $this->get_template_logo(null, 'favicon', true)) { if ($href = $this->get_template_logo('favicon')) {
$args[$param] = $href; $args[$param] = $href;
} }
else if ($href = $this->config->get('favicon', '/images/favicon.ico')) { else if ($href = $this->config->get('favicon', '/images/favicon.ico')) {
@ -2447,50 +2447,43 @@ EOF;
/** /**
* Get logo URL for current template based on skin_logo config option * Get logo URL for current template based on skin_logo config option
* *
* @param string $name Name of the logo to check for
* default is current template
* @param string $type Type of the logo to check for (e.g. 'print' or 'small') * @param string $type Type of the logo to check for (e.g. 'print' or 'small')
* default is null (no special type) * default is null (no special type)
* @param boolean $strict True if logo should only be returned for specific template
* *
* @return string image URL * @return string image URL
*/ */
protected function get_template_logo($name = null, $type = null, $strict = false) protected function get_template_logo($type = null)
{ {
$template_logo = null; $template_logo = null;
// Use current template if none provided
if (!$name) {
$name = $this->template_name;
}
$template_names = array(
$this->skin_name . ':' . $name . '[' . $type . ']',
$this->skin_name . ':' . $name,
$this->skin_name . ':*[' . $type . ']',
$this->skin_name . ':*',
$this->skin_name . '[' . $type . ']',
'*:' . $name . '[' . $type . ']',
'*:' . $name,
$name . '[' . $type . ']',
$name,
'*[' . $type . ']',
'*',
'[' . $type . ']',
);
// If no type is specified then remove those options from the list
if (empty($type)) {
$template_names = preg_grep("/\\[\]$/", $template_names, PREG_GREP_INVERT);
}
// If strict matching then remove wild card options
if ($strict) {
$template_names = preg_grep("/\*$/", $template_names, PREG_GREP_INVERT);
}
if ($logo = $this->config->get('skin_logo')) { if ($logo = $this->config->get('skin_logo')) {
if (is_array($logo)) { if (is_array($logo)) {
$template_names = array(
$this->skin_name . ':' . $this->template_name . '[' . $type . ']',
$this->skin_name . ':' . $this->template_name,
$this->skin_name . ':*[' . $type . ']',
$this->skin_name . ':[' . $type . ']',
$this->skin_name . ':*',
'*:' . $this->template_name . '[' . $type . ']',
'*:' . $this->template_name,
'*:*[' . $type . ']',
'*:[' . $type . ']',
$this->template_name . '[' . $type . ']',
$this->template_name,
'*[' . $type . ']',
'[' . $type . ']',
'*',
);
if (!empty($type)) {
// Use strict matching, remove wild card options
$template_names = preg_grep("/\*$/", $template_names, PREG_GREP_INVERT);
}
else {
// No type set so remove those options from the list
$template_names = preg_grep("/\\[\]$/", $template_names, PREG_GREP_INVERT);
}
foreach ($template_names as $key) { foreach ($template_names as $key) {
if (isset($logo[$key])) { if (isset($logo[$key])) {
$template_logo = $logo[$key]; $template_logo = $logo[$key];

@ -0,0 +1,147 @@
<?php
/**
* Test class to test rcmail_output_html class
*
* @package Tests
*/
class Rcmail_OutputHtml extends PHPUnit_Framework_TestCase
{
/**
* Test get_template_logo()
*/
function test_logo()
{
$rcmail = rcube::get_instance();
$output = new rcmail_output_html();
$reflection = new ReflectionClass('rcmail_output_html');
$set_skin = $reflection->getProperty('skin_name');
$set_template = $reflection->getProperty('template_name');
$get_template_logo = $reflection->getMethod('get_template_logo');
$set_skin->setAccessible(true);
$set_template->setAccessible(true);
$get_template_logo->setAccessible(true);
$set_skin->setValue($output, 'elastic');
$rcmail->config->set('skin_logo', 'img00');
$set_template->setValue($output, 'login');
$result = $get_template_logo->invokeArgs($output, array());
$this->assertSame('img00', $result);
$set_template->setValue($output, 'mail');
$result = $get_template_logo->invokeArgs($output, array('small'));
$this->assertSame('img00', $result);
$rcmail->config->set('skin_logo', array(
"elastic:login[small]" => "img01",
"elastic:login" => "img02",
"elastic:*[small]" => "img03",
"larry:*" => "img04",
"*:login[small]" => "img05",
"*:login" => "img06",
"*[print]" => "img07",
"*" => "img08",
));
$set_template->setValue($output, 'login');
$result = $get_template_logo->invokeArgs($output, array('small'));
$this->assertSame('img01', $result);
$set_template->setValue($output, 'login');
$result = $get_template_logo->invokeArgs($output, array());
$this->assertSame('img02', $result);
$set_template->setValue($output, 'mail');
$result = $get_template_logo->invokeArgs($output, array('small'));
$this->assertSame('img03', $result);
$set_template->setValue($output, 'mail');
$result = $get_template_logo->invokeArgs($output, array());
$this->assertSame('img08', $result);
$set_template->setValue($output, 'mail');
$result = $get_template_logo->invokeArgs($output, array('small'));
$this->assertSame('img03', $result);
$set_template->setValue($output, '_test_');
$result = $get_template_logo->invokeArgs($output, array());
$this->assertSame('img08', $result);
$set_skin->setValue($output, 'larry');
$set_template->setValue($output, 'login');
$result = $get_template_logo->invokeArgs($output, array('small'));
$this->assertSame('img05', $result);
$set_template->setValue($output, 'login');
$result = $get_template_logo->invokeArgs($output, array());
$this->assertSame('img04', $result);
$set_template->setValue($output, '_test_');
$result = $get_template_logo->invokeArgs($output, array());
$this->assertSame('img04', $result);
$set_skin->setValue($output, '_test_');
$set_template->setValue($output, 'login');
$result = $get_template_logo->invokeArgs($output, array('small'));
$this->assertSame('img05', $result);
$set_template->setValue($output, 'login');
$result = $get_template_logo->invokeArgs($output, array());
$this->assertSame('img06', $result);
$set_template->setValue($output, '_test_');
$result = $get_template_logo->invokeArgs($output, array('print'));
$this->assertSame('img07', $result);
$set_template->setValue($output, '_test_');
$result = $get_template_logo->invokeArgs($output, array());
$this->assertSame('img08', $result);
$rcmail->config->set('skin_logo', array(
"elastic:login[small]" => "img09",
"elastic:login" => "img10",
"larry:*" => "img11",
"elastic[small]" => "img12",
"login[small]" => "img13",
"login" => "img14",
"[print]" => "img15",
"*" => "img16",
));
$set_skin->setValue($output, 'elastic');
$set_template->setValue($output, 'login');
$result = $get_template_logo->invokeArgs($output, array('small'));
$this->assertSame('img09', $result);
$set_template->setValue($output, 'mail');
$result = $get_template_logo->invokeArgs($output, array('small'));
$this->assertSame(null, $result);
$set_skin->setValue($output, '_test_');
$set_template->setValue($output, 'login');
$result = $get_template_logo->invokeArgs($output, array('small'));
$this->assertSame('img13', $result);
$set_template->setValue($output, 'login');
$result = $get_template_logo->invokeArgs($output, array());
$this->assertSame('img14', $result);
$set_template->setValue($output, '_test_');
$result = $get_template_logo->invokeArgs($output, array('print'));
$this->assertSame('img15', $result);
$set_template->setValue($output, '_test_');
$result = $get_template_logo->invokeArgs($output, array('_test_'));
$this->assertSame(null, $result);
$set_template->setValue($output, '_test_');
$result = $get_template_logo->invokeArgs($output, array());
$this->assertSame('img16', $result);
}
}

@ -51,6 +51,7 @@
<file>Framework/VCard.php</file> <file>Framework/VCard.php</file>
<file>Framework/Washtml.php</file> <file>Framework/Washtml.php</file>
<file>MailFunc.php</file> <file>MailFunc.php</file>
<file>Rcmail/OutputHtml.php</file>
<file>Rcmail/Rcmail.php</file> <file>Rcmail/Rcmail.php</file>
</testsuite> </testsuite>
<testsuite name="Plugins Tests"> <testsuite name="Plugins Tests">

Loading…
Cancel
Save