public function ExportDataTests::testInputOutput in Loft Data Grids 6.2
Same name and namespace in other branches
- 7.2 vendor/aklump/loft_data_grids/tests/simpletest/export_data_test.php \AKlump\LoftDataGrids\ExportDataTests::testInputOutput()
File
- vendor/
aklump/ loft_data_grids/ tests_simpletest/ export_data_test.php, line 121 - Tests for the ExportData object
Class
Namespace
AKlump\LoftDataGridsCode
public function testInputOutput() {
$this->control = new \stdClass();
$this->control->page = 'sheet1';
$this->control->data = array(
array(
'hair' => 'blond',
'eyes' => 'green',
'pants' => 'jeans',
),
array(
'hair' => 'brown',
'eyes' => 'blue',
),
);
/**
* Assert get() returns an empty array after construction
*/
$_control_group = 'ExportData::get';
// Desired test result
$control = array();
// The test and result
$object = new ExportData($this->control->page);
$return = $object
->get();
$result = $return;
$this
->assertIdentical($control, $result, "Assert get() returns an empty array after construction", $_control_group);
// Assert after added two rows of data, get returns the correct expected array
$control = array(
'sheet1' => array(
0 => array(
'hair' => 'blond',
'eyes' => 'green',
'pants' => 'jeans',
),
1 => array(
'hair' => 'brown',
'eyes' => 'blue',
),
),
);
foreach ($this->control->data as $row) {
foreach ($row as $key => $value) {
$object
->add($key, $value);
}
$object
->next();
}
$result = $object
->get();
$this
->assertIdentical($control, $result, "Assert after added two rows of data, get returns the correct expected array", $_control_group);
// Assert getPointer returns the expected value
$control = 2;
$result = $object
->getPointer();
$this
->assertIdentical($control, $result, "Assert getPointer returns the expected value", $_control_group);
// Assert getCurrent will return empty array on new line
$control = array();
$result = $object
->getCurrent();
$this
->assertIdentical($control, $result, "Assert getCurrent will return empty array on new line", $_control_group);
// Assert getCurrent after setting back to prev rows returns the row as expected
$control = array(
'hair' => 'brown',
'eyes' => 'blue',
);
$object
->setPointer(1);
$result = $object
->getCurrent();
$this
->assertIdentical($control, $result, "Assert getCurrent after setting back to prev rows returns the row as expected", $_control_group);
// Assert getCurrent with an argument returns expected value
$control = 'blue';
$result = $object
->getCurrent('eyes');
$this
->assertIdentical($control, $result, "Assert getCurrent with an argument returns expected value", $_control_group);
// Assert normalize works correctly for a single page
$control = array(
'sheet1' => array(
0 => array(
'hair' => 'blond',
'eyes' => 'green',
'pants' => 'jeans',
),
1 => array(
'hair' => 'brown',
'eyes' => 'blue',
'pants' => '—',
),
),
);
// The test and result
$return = $object
->normalize('—');
$result = $object
->get();
$this
->assertIdentical($control, $result, "Assert normalize works correctly for a single page", $_control_group);
// Assert find with min arguments returns pointer and key value in array
$control = array(
1 => array(
'eyes' => 'blue',
),
);
$result = $object
->find('blue');
$this
->assertIdentical($control, $result, "Assert find with min arguments works correctly", $_control_group);
// Assert find with key argument returns correctly
$control = array(
1 => array(
'eyes' => 'blue',
),
);
$result = $object
->find('blue', 'eyes');
$this
->assertIdentical($control, $result, "Assert find with key argument", $_control_group);
// Assert find with key argument that does not contain the value returns empty array
$control = array();
$result = $object
->find('hair', 'eyes');
$this
->assertIdentical($control, $result, "Assert find with key argument", $_control_group);
// Assert setPointer with a NULL value moves the pointer to the end
$control = 2;
$object
->setPointer();
$result = $object
->getPointer();
$this
->assertIdentical($control, $result, "Assert setPointer with a NULL value moves the pointer to the end", $_control_group);
// Assert find with 1 argument does not return multiple records when possible, only one and it's the earliest
$control = array(
1 => array(
'eyes' => 'blue',
),
);
$object
->add('eyes', 'blue');
$object
->add('pants', 'blue');
$result = $object
->find('blue');
$this
->assertIdentical($control, $result, "Assert find with 1 argument does not return multiple records when possible, only one and it's the most recent", $_control_group);
// Assert find asking for 1 record but searching descending returns the most recent record
$control = array(
2 => array(
'eyes' => 'blue',
'pants' => 'blue',
),
);
$result = $object
->find('blue', NULL, 1, 1);
$this
->assertIdentical($control, $result, "Assert find asking for 1 record but searching descending returns the most recent record", $_control_group);
// Assert find asking for 1 record with key but searching descending returns the most recent record
$control = array(
2 => array(
'eyes' => 'blue',
),
);
$result = $object
->find('blue', 'eyes', 1, 1);
$this
->assertIdentical($control, $result, "Assert find asking for 1 record but searching descending returns the most recent record", $_control_group);
// Assert find asking for all records with key but searching descending returns what we expect
$control = array(
2 => array(
'eyes' => 'blue',
),
1 => array(
'eyes' => 'blue',
),
);
$result = $object
->find('blue', 'eyes', 0, 1);
$this
->assertIdentical($control, $result, "Assert find asking for all records with key but searching descending returns what we expect", $_control_group);
// END ASSERT
}