diff options
Diffstat (limited to 'tests/PHPUnit/Unit/DataTable/Renderer/JSONTest.php')
-rw-r--r-- | tests/PHPUnit/Unit/DataTable/Renderer/JSONTest.php | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/tests/PHPUnit/Unit/DataTable/Renderer/JSONTest.php b/tests/PHPUnit/Unit/DataTable/Renderer/JSONTest.php index b73d49f0a6..4e0eae5431 100644 --- a/tests/PHPUnit/Unit/DataTable/Renderer/JSONTest.php +++ b/tests/PHPUnit/Unit/DataTable/Renderer/JSONTest.php @@ -398,4 +398,56 @@ class DataTable_Renderer_JSONTest extends \PHPUnit_Framework_TestCase $this->assertEquals($expected, $render->render()); } + public function test_render_withRowsWithDataTableMetadata() + { + $dataTable = new DataTable(); + + $row = new DataTable\Row(); + $row->addColumn('nb_visits', 5); + $row->addColumn('nb_random', 10); + + $otherDataTable = new DataTable(); + $otherDataTable->addRowsFromSimpleArray([ + ['nb_visits' => 6, 'nb_random' => 7], + ['nb_visits' => 8, 'nb_random' => 9], + ]); + $row->setComparisons($otherDataTable); + + $dataTable->addRow($row); + + $render = new Json(); + $render->setTable($dataTable); + $actual = $render->render(); + + $expected = '[{"nb_visits":5,"nb_random":10,"comparisons":[{"nb_visits":6,"nb_random":7},{"nb_visits":8,"nb_random":9}]}]'; + + $this->assertEquals($expected, $actual); + } + + public function test_render_withRowsWithDataTableMetadataInSimpleTable() + { + $dataTable = new Simple(); + + $row = new DataTable\Row(); + $row->addColumn('nb_visits', 5); + $row->addColumn('nb_random', 10); + + $otherDataTable = new DataTable(); + $otherDataTable->addRowsFromSimpleArray([ + ['nb_visits' => 6, 'nb_random' => 7], + ['nb_visits' => 8, 'nb_random' => 9], + ]); + $row->setComparisons($otherDataTable); + + $dataTable->addRow($row); + + $render = new Json(); + $render->setTable($dataTable); + $actual = $render->render(); + + $expected = '{"nb_visits":5,"nb_random":10,"comparisons":[{"nb_visits":6,"nb_random":7},{"nb_visits":8,"nb_random":9}]}'; + + $this->assertEquals($expected, $actual); + } + } |