1
0
mirror of https://github.com/e107inc/e107.git synced 2025-03-25 14:59:49 +01:00

XML Class import/export method tests and e107::serialize() test.

This commit is contained in:
Cameron 2018-11-15 14:24:47 -08:00
parent 99772ae134
commit 5c3e14f8d1
3 changed files with 209 additions and 24 deletions

View File

@ -1,22 +0,0 @@
<?php
/**
* e107 website system
*
* Copyright (C) 2008-2018 e107 Inc (e107.org)
* Released under the terms and conditions of the
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt)
*
*/
use PHPUnit\Framework\TestCase;
class XMLClassTest extends TestCase
{
public function testLoadDefaultXMLPreferences()
{
// $config = e_CORE."xml/default_install.xml";
// $ret = e107::getXml()->e107Import($config, 'replace', true, true); // Add core pref values
$this->assertTrue(true); // doing nothing right now.
}
}

View File

@ -107,9 +107,36 @@
{
}
*/
public function testSerialize()
{
}*/
$pref1 = array('hello'=>'world');
$result1 = $this->arrObj->serialize($pref1);
$expected1 = "array (\n 'hello' => 'world',\n)";
$this->assertEquals($expected1,$result1);
$pref2 = array();
$result2 = $this->arrObj->serialize($pref2);
$expected2 = null;
$this->assertEquals($expected2,$result2);
$pref3 = array();
$result3 = $this->arrObj->serialize($pref3,true);
$expected3 = null;
$this->assertEquals($expected3,$result3);
$pref4 = array();
$result4 = $this->arrObj->serialize($pref4,'json');
$expected4 = null;
$this->assertEquals($expected4,$result4);
$pref5 = array('hello'=>'world');
$result5 = $this->arrObj->serialize($pref5,'json');
$expected5 = "{\n \"hello\": \"world\"\n}";
$this->assertEquals($expected5,$result5);
}
}

180
tests/unit/xmlClassTest.php Normal file
View File

@ -0,0 +1,180 @@
<?php
/**
* Created by PhpStorm.
* User: Wiz
* Date: 11/15/2018
* Time: 12:01 PM
*/
class xmlClassTest extends \Codeception\Test\Unit
{
/** @var xmlClass */
private $_xml;
protected function _before()
{
try
{
$this->_xml = $this->make('xmlClass');
// $this->_xml->__construct();
}
catch (Exception $e)
{
$this->assertTrue(false, "Couldn't load xmlClass object");
}
}
/*
public function testXml_convert_to_array()
{
}
public function testLoadXMLfile()
{
}
public function testSetOptFilter()
{
}
public function testSetOptStringTags()
{
}
public function testParseXml()
{
}
public function testE107ExportValue()
{
}
public function testSetOptArrayTags()
{
}
public function testParseStringTags()
{
}
public function testGetErrors()
{
}
public function testSetOptAddRoot()
{
}
public function testE107ImportValue()
{
}
public function testGetLastErrorMessage()
{
}
public function testSetOptStripComments()
{
}
public function testGetRemoteFile()
{
}
public function testSetOptForceArray()
{
}
public function testSetOptValueKey()
{
}
*/
public function testE107ImportPrefs()
{
$file = e_CORE."xml/default_install.xml";
$checks = array('ssl_enabled', 'smtp_server', 'e_jslib_core', 'e_jslib_plugin');
$xmlArray = $this->_xml->loadXMLfile($file, 'advanced');
$arr = array();
foreach($xmlArray['prefs']['core'] as $val)
{
if(in_array($val['@attributes']['name'],$checks))
{
$arr['prefs']['core'][] = $val;
}
}
$result = $this->_xml->e107ImportPrefs($arr);
$expected = array (
'e_jslib_core' =>
array (
'prototype' => 'none',
'jquery' => 'all',
),
'e_jslib_plugin' =>
array (
),
'smtp_server' => '',
'ssl_enabled' => '0',
);
$this->assertEquals($expected,$result);
}
/*
public function testSetFeedUrl()
{
}
public function testXml2array()
{
}
*/
public function testE107Import()
{
}
/*
public function testSetUrlPrefix()
{
}
*/
public function testE107Export()
{
$ret = $this->_xml->e107Export(array('core'), null, null, array('return'=>true));
$incorrect = '<core name="e_jslib_plugin"><![CDATA[Array]]></core>';
$correct = '<core name="e_jslib_plugin"><![CDATA[array ()]]></core>';
$this->assertNotContains($incorrect, $ret);
$this->assertContains($correct, $ret);
}
}