This repository has been archived on 2026-07-19. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
espocrm-base/tests/Espo/Utils/JSONTest.php
T
Taras Machyshyn 417576fd5e change instance
2013-11-01 13:49:54 +02:00

58 lines
1.3 KiB
PHP
Executable File

<?php
namespace Espo\Tests\Utils;
require_once('bootstrap.php');
use Espo\Utils as Utils;
class JSONTest extends \PHPUnit_Framework_TestCase
{
protected $fixture;
protected function setUp()
{
$this->fixture = new Utils\JSON();
}
protected function tearDown()
{
$this->fixture = NULL;
}
function testEncode()
{
$testVal= array('testOption'=>'Test');
$this->assertEquals(json_encode($testVal), $this->fixture->encode($testVal));
}
function testDecode()
{
$testVal= array('testOption'=>'Test');
$this->assertEquals($testVal, $this->fixture->decode(json_encode($testVal), true));
$test= '{"folder":"data/logs"}';
$this->assertEquals('data/logs', $this->fixture->decode($test)->folder);
$test= '{"folder":"data\/logs"}';
$this->assertEquals('data/logs', $this->fixture->decode($test)->folder);
$test= '{"folder":"\\Entity\\Logs"}';
$this->assertEquals('\Entity\Logs', $this->fixture->decode($test)->folder);
$test= '{"folder":"\Entity\\Logs"}';
$this->assertEquals('\Entity\Logs', $this->fixture->decode($test)->folder);
}
function testIsJSON()
{
$this->assertTrue($this->fixture->isJSON('{"database":{"driver":"pdo_mysql","host":"localhost"},"devMode":true}'));
$this->assertFalse($this->fixture->isJSON('some string'));
}
}
?>