Open Journal Systems  3.3.0
JSONTest.php
1 <?php
2 
17 import('lib.pkp.tests.PKPTestCase');
18 import('lib.pkp.classes.core.JSONMessage');
19 
20 class JSONTest extends PKPTestCase {
24  public function testGetString() {
25  // Create a test object.
26  $testObject = new stdClass();
27  $testObject->someInt = 5;
28  $testObject->someFloat = 5.5;
29  $json = new JSONMessage($status = true, $content = 'test content',
30  $elementId = '0', $additionalAttributes = array('testObj' => $testObject));
31  $json->setEvent('someEvent', array('eventDataKey' => array('item1', 'item2')));
32 
33  // Render the JSON message.
34  $expectedString = '{"status":true,"content":"test content",'.
35  '"elementId":"0","events":[{"name":"someEvent","data":{"eventDataKey":["item1","item2"]}}],'.
36  '"testObj":{"someInt":5,"someFloat":5.5}}';
37  self::assertEquals($expectedString, $json->getString());
38  }
39 }
40 
JSONTest
Tests for the JSON class.
Definition: JSONTest.php:20
PKPTestCase
Class that implements functionality common to all PKP unit test cases.
Definition: PKPTestCase.inc.php:27
JSONMessage
Class to represent a JSON (Javascript Object Notation) message.
Definition: JSONMessage.inc.php:18
JSONTest\testGetString
testGetString()
Definition: JSONTest.php:24