1
0
mirror of https://github.com/e107inc/e107.git synced 2025-08-28 08:39:57 +02:00

Some tests added.

This commit is contained in:
Cameron
2020-12-20 19:41:16 -08:00
parent f950b32774
commit 0f4b3d29cb
3 changed files with 253 additions and 34 deletions

View File

@@ -0,0 +1,79 @@
<?php
class ArrayDataTest extends \Codeception\Test\Unit
{
/** @var ArrayData */
protected $ad;
protected function _before()
{
try
{
$this->ad = $this->make('ArrayData');
}
catch(Exception $e)
{
$this->assertTrue(false, $e->getMessage());
}
}
public function testReadArray()
{
// e107 var_export test.
$string = "array (
'most_members_online' => 10,
'most_guests_online' => 20,
'most_online_datestamp' => 1534279911,
'most_enabled' => true
)";
$expected = array (
'most_members_online' => 10,
'most_guests_online' => 20,
'most_online_datestamp' => 1534279911,
'most_enabled' => true
);
$result = $this->ad->ReadArray($string);
$this->assertSame($expected, $result);
// legacy Prefs test.
$string = 'a:4:{s:19:"most_members_online";i:10;s:18:"most_guests_online";i:20;s:21:"most_online_datestamp";i:1534279911;s:12:"most_enabled";b:1;}';
$actual = $this->ad->ReadArray($string);
$this->assertSame($expected, $actual);
}
public function testWriteArray()
{
// Test with addslashes enabled.
$input = array('one'=>'two', 'three'=>true);
$result = $this->ad->WriteArray($input);
$expected = 'array (
\\\'one\\\' => \\\'two\\\',
\\\'three\\\' => true,
)';
$this->assertSame($expected, $result);
// Test with addslashes disabled.
$result = $this->ad->WriteArray($input, false);
$expected = "array (
'one' => 'two',
'three' => true,
)";
$this->assertSame($expected, $result);
}
}

View File

@@ -0,0 +1,166 @@
<?php
class e_prefTest extends \Codeception\Test\Unit
{
/** @var e_pref */
protected $pref;
protected function _before()
{
try
{
$this->pref = $this->make('e_pref');
}
catch(Exception $e)
{
$this->assertTrue(false, $e->getMessage());
}
$this->pref->__construct('core');
$this->pref->load();
}
/* public function testRemoveData()
{
}
public function testClearPrefCache()
{
}
public function testValidate()
{
}
public function testReset()
{
}
public function test__construct()
{
}
public function testSetPref()
{
}
public function testLoadData()
{
}
public function testSave()
{
}
public function testGet()
{
}
public function testRemovePref()
{
}
public function testLoad()
{
}
public function testSetOptionSerialize()
{
}
public function testRemove()
{
}
public function testSetData()
{
}
public function testAddData()
{
}
public function testDelete()
{
}
public function testUpdatePref()
{
}*/
public function testGetPref()
{
$result = $this->pref->getPref();
$this->assertIsArray($result);
$this->assertArrayHasKey('maintainance_flag', $result);
}
/*
public function testSetOptionBackup()
{
}
public function testSet()
{
}
public function testUpdate()
{
}
public function testAdd()
{
}
*/
public function testAddPref()
{
$this->pref->addPref('test_preference', "my custom preference");
$result = $this->pref->get('test_preference');
$expected = "my custom preference";
$this->assertSame($expected, $result);
// test multidimentional
$this->pref->addPref('test_list/key1', "value1");
$this->pref->addPref('test_list/key2', "value2");
$result = $this->pref->get('test_list');
$expected = array (
'key1' => 'value1',
'key2' => 'value2',
);
$this->assertSame($expected, $result);
}
}