diff options
author | Thomas Steur <tsteur@users.noreply.github.com> | 2016-12-03 23:51:18 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-12-03 23:51:18 +0300 |
commit | 29e9ed9fee668f5694f5ff136d453460b5c33b46 (patch) | |
tree | eb075114eaeb47caba7a71a7981024d19887f4a0 /tests | |
parent | 59ba07cba11cd51a49ba5a4946abee0d34c4c7a9 (diff) |
Fix a bug where Piwik returns wrong rows by label (#10947)
* Fix a bug where Piwik returns wrong rows by label
* fix typo
* added test
Diffstat (limited to 'tests')
-rw-r--r-- | tests/PHPUnit/Unit/DataTableTest.php | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/tests/PHPUnit/Unit/DataTableTest.php b/tests/PHPUnit/Unit/DataTableTest.php index b2eb143518..2fa06a5f6a 100644 --- a/tests/PHPUnit/Unit/DataTableTest.php +++ b/tests/PHPUnit/Unit/DataTableTest.php @@ -107,6 +107,35 @@ class DataTableTest extends \PHPUnit_Framework_TestCase $this->assertEquals($table2->getRowFromIdSubDataTable($idTable3), $table2->getLastRow()); } + public function test_rebuildIndex() + { + $labels = array(0 => 'abc', 1 => 'def', 2 => 'ghi', 3 => 'jkl', 4 => 'mno'); + $table = new DataTable(); + + $rows = array(); + foreach ($labels as $label) { + $row = new Row(array(Row::COLUMNS => array('label' => $label))); + $table->addRow($row); + $rows[] = $row; + } + + foreach ($labels as $label) { + $rowVerify1 = $table->getRowFromLabel($label); + $this->assertSame($label, $rowVerify1->getColumn('label')); + } + + $table->setRows(array($rows[2], $rows[3], $rows[4])); + $table->rebuildIndex();// rebuildindex would be called anyway but we force rebuilding the index just to make sure + + // verify still accessible + $rowVerify1 = $table->getRowFromLabel('ghi'); + $this->assertSame('ghi', $rowVerify1->getColumn('label')); + + // verify no longer accessible + $rowVerify3 = $table->getRowFromLabel('abc'); + $this->assertFalse($rowVerify3); + } + public function test_clone_shouldIncreasesTableId() { $table = new DataTable; |