Skip to content

Commit

Permalink
Fixing creating empty nodes for all PHP 'false' values. Closes #14.
Browse files Browse the repository at this point in the history
  • Loading branch information
maciej.majewski committed Aug 23, 2012
1 parent 90a91c8 commit 321b13f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
2 changes: 1 addition & 1 deletion classes/CFPropertyList/CFType.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function setValue($value) {
public function toXML(DOMDocument $doc, $nodeName) {
$node = $doc->createElement($nodeName);

if($this->value != '') {
if($this->value !== '') {
$text = $doc->createTextNode($this->value);
$node->appendChild($text);
}
Expand Down
31 changes: 31 additions & 0 deletions tests/EmptyElementsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace CFPropertyList;

error_reporting(E_ALL | E_STRICT);
ini_set('display_errors', 'on');

if (!defined('LIBDIR')) {
define('LIBDIR', __DIR__ . '/../classes/CFPropertyList');
}

require_once(LIBDIR . '/CFPropertyList.php');

class EmptyElementsTest extends \PHPUnit_Framework_TestCase {
public function testWriteFile() {
$expected = '<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0"><dict><key>string</key><string/><key>number</key><integer>0</integer><key>double</key><real>0</real></dict></plist>
';

$plist = new CFPropertyList();
$dict = new CFDictionary();

$dict->add('string', new CFString(''));
$dict->add('number', new CFNumber(0));
$dict->add('double', new CFNumber(0.0));

$plist->add($dict);
$this->assertEquals($expected, $plist->toXML());
}
}

0 comments on commit 321b13f

Please sign in to comment.