Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Commit

Permalink
Merge branch 'master' of git://git.zendframework.com/zf
Browse files Browse the repository at this point in the history
  • Loading branch information
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 8 deletions.
11 changes: 8 additions & 3 deletions src/Formatter/Xml.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,15 @@ public function format($event)
$elt = $dom->appendChild(new \DOMElement($this->_rootElement));

foreach ($dataToInsert as $key => $value) {
if($key == "message") {
$value = htmlspecialchars($value, ENT_COMPAT, $enc);
if (empty($value)
|| is_scalar($value)
|| (is_object($value) && method_exists($value,'__toString'))
) {
if($key == "message") {
$value = htmlspecialchars($value, ENT_COMPAT, $enc);
}
$elt->appendChild(new \DOMElement($key, (string)$value));
}
$elt->appendChild(new \DOMElement($key, $value));
}

$xml = $dom->saveXML();
Expand Down
45 changes: 44 additions & 1 deletion test/Formatter/XmlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@

namespace ZendTest\Log\Formatter;

use \Zend\Log\Formatter\Xml as XmlFormatter;
use ZendTest\Log\TestAsset\SerializableObject,
\Zend\Log\Formatter\Xml as XmlFormatter;

/**
* @category Zend
Expand Down Expand Up @@ -127,4 +128,46 @@ public function testFactory()
$formatter = XmlFormatter::factory($options);
$this->assertInstanceOf('Zend\Log\Formatter\Xml', $formatter);
}

/**
* @group ZF-11161
*/
public function testNonScalarValuesAreExcludedFromFormattedString()
{
$options = array(
'rootElement' => 'log'
);
$event = array(
'message' => 'tottakai',
'priority' => 4,
'context' => array('test'=>'one'),
'reference' => new XmlFormatter()
);
$expected = '<log><message>tottakai</message><priority>4</priority></log>';

$formatter = XmlFormatter::factory($options);
$output = $formatter->format($event);
$this->assertContains($expected, $output);
}

/**
* @group ZF-11161
*/
public function testObjectsWithStringSerializationAreIncludedInFormattedString()
{
$options = array(
'rootElement' => 'log'
);
$event = array(
'message' => 'tottakai',
'priority' => 4,
'context' => array('test'=>'one'),
'reference' => new SerializableObject()
);
$expected = '<log><message>tottakai</message><priority>4</priority><reference>ZendTest\Log\TestAsset\SerializableObject</reference></log>';

$formatter = XmlFormatter::factory($options);
$output = $formatter->format($event);
$this->assertContains($expected, $output);
}
}
10 changes: 10 additions & 0 deletions test/TestAsset/SerializableObject.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php
namespace ZendTest\Log\TestAsset;

class SerializableObject
{
public function __toString()
{
return __CLASS__;
}
}
14 changes: 11 additions & 3 deletions test/Writer/FirebugTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,15 @@ class FirebugTest extends \PHPUnit_Framework_TestCase
protected $_writer = null;
protected $_logger = null;

/**
* Stores the original set timezone
* @var string
*/
private $_originaltimezone;

public function setUp()
{
$this->_originaltimezone = date_default_timezone_get();
date_default_timezone_set('America/Los_Angeles');

// Reset front controller to reset registered plugins and
Expand Down Expand Up @@ -74,6 +81,7 @@ public function tearDown()
{
Channel\HttpHeaders::destroyInstance();
FirePhp::destroyInstance();
date_default_timezone_set($this->_originaltimezone);
}

/**
Expand Down Expand Up @@ -206,9 +214,9 @@ public function testAdvancedLogging()
$table = array(
'Summary line for the table',
array(
array('Column 1', 'Column 2'),
array('Row 1 c 1',' Row 1 c 2'),
array('Row 2 c 1',' Row 2 c 2')
array('Column 1', 'Column 2'),
array('Row 1 c 1',' Row 1 c 2'),
array('Row 2 c 1',' Row 2 c 2')
)
);

Expand Down
2 changes: 1 addition & 1 deletion test/_files/layout.phtml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php echo $this->broker('layout')->direct()->events;
<?php echo $this->plugin('layout')->direct()->events;

0 comments on commit 1e2b768

Please sign in to comment.