builder = $this->makeBuilder(array());
DataTable\Manager::getInstance()->deleteAll();
}
public function tearDown(): void
{
DataTable\Manager::getInstance()->deleteAll();
}
public function testRenderSuccessShouldIncludeMessage()
{
$response = $this->builder->renderSuccess('ok');
$this->assertEquals('
', $response);
}
public function testRenderExceptionShouldIncludeTheMessageAndNotExceptionMessage()
{
$response = $this->builder->renderException("The error message", new \Exception('The other message'));
$this->assertEquals('
', $response);
}
public function testRenderObjectShouldReturAnError()
{
$response = $this->builder->renderObject(new \stdClass());
$this->assertEquals('
', $response);
}
public function testRenderResourceShouldReturAnError()
{
$response = $this->builder->renderResource(new \stdClass());
$this->assertEquals('
', $response);
}
public function testRenderScalarShouldReturnABooleanAsIntegerWrappedInResult()
{
$response = $this->builder->renderScalar(true);
$this->assertEquals('
1', $response);
}
public function testRenderScalarShouldReturnAnIntegerWrappedInResult()
{
$response = $this->builder->renderScalar(5);
$this->assertEquals('
5', $response);
}
public function testRenderScalarShouldReturnAStringWrappedInValue()
{
$response = $this->builder->renderScalar('The Output');
$this->assertEquals('
The Output', $response);
}
public function testRenderScalarShouldNotRemoveLineBreaks()
{
$response = $this->builder->renderScalar('The\nOutput');
$this->assertEquals('
The\nOutput', $response);
}
public function testRenderDataTableShouldRenderABasicDataTable()
{
$dataTable = new DataTable();
$dataTable->addRowFromSimpleArray(array('nb_visits' => 5, 'nb_random' => 10));
$response = $this->builder->renderDataTable($dataTable);
$this->assertEquals('
5
10
', $response);
}
public function testRenderDataTableShouldRenderSubtables()
{
$subtable = new DataTable();
$subtable->addRowFromSimpleArray(array('nb_visits' => 2, 'nb_random' => 6));
$dataTable = new DataTable();
$dataTable->addRowFromSimpleArray(array('nb_visits' => 5, 'nb_random' => 10));
$dataTable->getFirstRow()->setSubtable($subtable);
$response = $this->builder->renderDataTable($dataTable);
$this->assertEquals('
5
10
1
', $response);
}
public function testRenderDataTableShouldRenderDataTableMaps()
{
$map = new DataTable\Map();
$dataTable = new DataTable();
$dataTable->addRowFromSimpleArray(array('nb_visits' => 5, 'nb_random' => 10));
$dataTable2 = new DataTable();
$dataTable2->addRowFromSimpleArray(array('nb_visits' => 3, 'nb_random' => 6));
$map->addTable($dataTable, 'table1');
$map->addTable($dataTable2, 'table2');
$response = $this->builder->renderDataTable($map);
$this->assertEquals('
5
10
3
6
', $response);
}
public function testRenderDataTableShouldRenderSimpleDataTable()
{
$dataTable = new DataTable\Simple();
$dataTable->addRowsFromArray(array('nb_visits' => 3, 'nb_random' => 6));
$response = $this->builder->renderDataTable($dataTable);
$this->assertEquals('
3
6
', $response);
}
public function testRenderArrayShouldConvertSimpleArrayToJson()
{
$input = array(1, 2, 5, 'string', 10);
$response = $this->builder->renderArray($input);
$this->assertEquals('
1
2
5
string
10
', $response);
}
public function testRenderArrayShouldRenderAnEmptyArray()
{
$response = $this->builder->renderArray(array());
$this->assertEquals('
', $response);
}
public function testRenderArrayShouldConvertAssociativeArrayToJson()
{
$input = array('nb_visits' => 6, 'nb_random' => 8);
$response = $this->builder->renderArray($input);
$this->assertEquals('
6
8
', $response);
}
public function testRenderArrayShouldConvertsIndexedAssociativeArrayToJson()
{
$input = array(
array('nb_visits' => 6, 'nb_random' => 8),
array('nb_visits' => 3, 'nb_random' => 4),
);
$response = $this->builder->renderArray($input);
$this->assertEquals('
6
8
3
4
', $response);
}
public function testRenderArrayShouldConvertMultiDimensionalStandardArrayToJson()
{
$input = array("firstElement",
array(
"firstElement",
"secondElement",
),
"thirdElement");
$actual = $this->builder->renderArray($input);
$this->assertEquals('
firstElement
firstElement
secondElement
thirdElement
', $actual);
}
public function testRenderArrayShouldConvertMultiDimensionalAssociativeArrayToJson()
{
$input = array(
"firstElement" => "isFirst",
"secondElement" => array(
"firstElement" => "isFirst",
"secondElement" => "isSecond",
),
"thirdElement" => "isThird");
$actual = $this->builder->renderArray($input);
$this->assertEquals('
isFirst
isFirst
isSecond
isThird
', $actual);
}
public function testRenderArrayShouldConvertMultiDimensionalIndexArrayToJson()
{
$input = array(array("firstElement",
array(
"firstElement",
"secondElement",
),
"thirdElement"));
$actual = $this->builder->renderArray($input);
$this->assertEquals('
firstElement
firstElement
secondElement
thirdElement
', $actual);
}
public function testRenderArrayShouldConvertMultiDimensionalMixedArrayToJson()
{
$input = array(
"firstElement" => "isFirst",
array(
"firstElement",
"secondElement",
),
"thirdElement" => array(
"firstElement" => "isFirst",
"secondElement" => "isSecond",
),
);
$actual = $this->builder->renderArray($input);
$this->assertEquals('
isFirst
firstElement
secondElement
isFirst
isSecond
', $actual);
}
private function makeBuilder($request)
{
return new Xml($request);
}
}