Merge branch '2.0' into 2.0-console

This commit is contained in:
mark_story 2010-10-23 19:19:04 -04:00
commit 0b2a6acc64
6 changed files with 83 additions and 70 deletions

View file

@ -151,8 +151,8 @@ if (!function_exists('sortByKey')) {
function h($text, $double = true, $charset = null) {
if (is_array($text)) {
$texts = array();
foreach ($text as $t) {
$texts[] = h($t, $double, $charset);
foreach ($text as $k => $t) {
$texts[$k] = h($t, $double, $charset);
}
return $texts;
}

View file

@ -315,8 +315,9 @@ class RssHelper extends AppHelper {
if (!empty($namespace)) {
$xml .= ' xmlns:"' . $namespace . '"';
}
$bareName = $name;
if (strpos($name, ':') !== false) {
list($prefix, ) = explode(':', $name, 2);
list($prefix, $bareName) = explode(':', $name, 2);
switch ($prefix) {
case 'atom':
$xml .= ' xmlns:atom="http://www.w3.org/2005/Atom"';
@ -327,15 +328,17 @@ class RssHelper extends AppHelper {
$content = '<![CDATA[' . $content . ']]>';
}
$xml .= '>' . $content . '</' . $name. '>';
$elem = Xml::build($xml);
$elem = Xml::build($xml, array('return' => 'domdocument'));
$nodes = $elem->getElementsByTagName($bareName);
foreach ($attrib as $key => $value) {
$elem->addAttribute($key, $value);
$nodes->item(0)->setAttribute($key, $value);
}
foreach ($children as $child) {
$elem->addChild($child);
foreach ($children as $k => $child) {
$child = $elem->createElement($name, $child);
$nodes->item(0)->appendChild($child);
}
$xml = $elem->asXML();
$xml = $elem->saveXml();
$xml = trim(substr($xml, strpos($xml, '?>') + 2));
return $xml;
}

View file

@ -88,14 +88,14 @@ class Xml {
return self::fromArray((array)$input, $options);
} elseif (strpos($input, '<') !== false) {
if ($options['return'] === 'simplexml' || $options['return'] === 'simplexmlelement') {
return new SimpleXMLElement($input);
return new SimpleXMLElement($input, LIBXML_NOCDATA);
}
$dom = new DOMDocument();
$dom->loadXML($input);
return $dom;
} elseif (file_exists($input) || strpos($input, 'http://') === 0 || strpos($input, 'https://') === 0) {
if ($options['return'] === 'simplexml' || $options['return'] === 'simplexmlelement') {
return new SimpleXMLElement($input, null, true);
return new SimpleXMLElement($input, LIBXML_NOCDATA, true);
}
$dom = new DOMDocument();
$dom->load($input);

View file

@ -228,6 +228,14 @@ class BasicsTest extends CakeTestCase {
'&nbsp;'
);
$this->assertEqual($expected, $result);
$arr = array('f' => '<foo>', 'n' => '&nbsp;');
$result = h($arr, false);
$expected = array(
'f' => '&lt;foo&gt;',
'n' => '&nbsp;'
);
$this->assertEqual($expected, $result);
}
/**

View file

@ -35,7 +35,7 @@ class RssHelperTest extends CakeTestCase {
* @return void
*/
function setUp() {
$controller = null;
parent::setUp();
$this->View = new View($controller);
$this->Rss = new RssHelper($this->View);
}
@ -47,6 +47,7 @@ class RssHelperTest extends CakeTestCase {
* @return void
*/
function tearDown() {
parent::tearDown();
unset($this->Rss);
}
@ -65,15 +66,6 @@ class RssHelperTest extends CakeTestCase {
);
$this->assertTags($result, $expected);
$result = $this->Rss->document(array('contrived' => 'parameter'));
$expected = array(
'rss' => array(
'version' => '2.0'
),
'<parameter'
);
$this->assertTags($result, $expected);
$result = $this->Rss->document(null, 'content');
$expected = array(
'rss' => array(
@ -173,6 +165,7 @@ class RssHelperTest extends CakeTestCase {
);
$this->assertTags($result, $expected);
}
function testChannelElementAttributes() {
$attrib = array();
$elements = array(
@ -288,15 +281,9 @@ class RssHelperTest extends CakeTestCase {
$this->assertTags($result, $expected);
$item = array(
'title' => array(
'value' => 'My Title',
'cdata' => true,
),
'title' => 'My Title',
'link' => 'http://www.example.com/1',
'description' => array(
'value' => 'descriptive words',
'cdata' => true,
),
'description' => 'descriptive words',
'pubDate' => '2008-05-31 12:00:00',
'guid' => 'http://www.example.com/1'
);
@ -305,13 +292,13 @@ class RssHelperTest extends CakeTestCase {
$expected = array(
'<item',
'<title',
'<![CDATA[My Title]]',
'My Title',
'/title',
'<link',
'http://www.example.com/1',
'/link',
'<description',
'<![CDATA[descriptive words]]',
'descriptive words',
'/description',
'<pubDate',
date('r', strtotime('2008-05-31 12:00:00')),
@ -324,21 +311,57 @@ class RssHelperTest extends CakeTestCase {
$this->assertTags($result, $expected);
$item = array(
'title' => array(
'value' => 'My Title & more',
'cdata' => true
)
'title' => 'My Title & more'
);
$result = $this->Rss->item(null, $item);
$expected = array(
'<item',
'<title', 'My Title &amp; more', '/title',
'/item'
);
$this->assertTags($result, $expected);
$item = array(
'title' => 'Foo bar',
'link' => array(
'url' => 'http://example.com/foo?a=1&b=2',
'convertEntities' => false
),
'description' => array(
'value' => 'descriptive words',
'cdata' => true,
),
'pubDate' => '2008-05-31 12:00:00'
);
$result = $this->Rss->item(null, $item);
$expected = array(
'<item',
'<title',
'<![CDATA[My Title &amp; more]]',
'Foo bar',
'/title',
'<link',
'http://example.com/foo?a=1&amp;b=2',
'/link',
'<description',
'<![CDATA[descriptive words]]',
'/description',
'<pubDate',
date('r', strtotime('2008-05-31 12:00:00')),
'/pubDate',
'<guid',
'http://example.com/foo?a=1&amp;b=2',
'/guid',
'/item'
);
$this->assertTags($result, $expected);
}
/**
* test item() with cdata blocks.
*
* @return void
*/
function testItemCdata() {
$item = array(
'title' => array(
'value' => 'My Title & more',
@ -360,7 +383,7 @@ class RssHelperTest extends CakeTestCase {
'category' => array(
'value' => 'CakePHP',
'cdata' => true,
'domain' => 'http://www.cakephp.org'
'domain' => 'http://www.cakephp.org',
)
);
$result = $this->Rss->item(null, $item);
@ -454,40 +477,6 @@ class RssHelperTest extends CakeTestCase {
'/item'
);
$this->assertTags($result, $expected);
$item = array(
'title' => 'Foo bar',
'link' => array(
'url' => 'http://example.com/foo?a=1&b=2',
'convertEntities' => false
),
'description' => array(
'value' => 'descriptive words',
'cdata' => true,
),
'pubDate' => '2008-05-31 12:00:00'
);
$result = $this->Rss->item(null, $item);
$expected = array(
'<item',
'<title',
'Foo bar',
'/title',
'<link',
'http://example.com/foo?a=1&amp;b=2',
'/link',
'<description',
'<![CDATA[descriptive words]]',
'/description',
'<pubDate',
date('r', strtotime('2008-05-31 12:00:00')),
'/pubDate',
'<guid',
'http://example.com/foo?a=1&amp;b=2',
'/guid',
'/item'
);
$this->assertTags($result, $expected);
}
/**

View file

@ -797,6 +797,19 @@ class XmlTest extends CakeTestCase {
$this->assertEqual(str_replace(array("\r", "\n"), '', $xmlResponse->asXML()), $expected);
}
/**
* test that CDATA blocks don't get screwed up by SimpleXml
*
* @return void
*/
function testCdata() {
$xml = '<' . '?xml version="1.0" encoding="UTF-8"?>' .
'<people><name><![CDATA[ Mark ]]></name></people>';
$result = Xml::build($xml);
$this->assertEquals(' Mark ', (string)$result->name);
}
/**
* data provider for toArray() failures
*