Skip to content
Extraits de code Groupes Projets
Valider 29e9ed9f rédigé par Thomas Steur's avatar Thomas Steur Validation de GitHub
Parcourir les fichiers

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
parent 59ba07cb
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -698,6 +698,7 @@ class DataTable implements DataTableInterface, \IteratorAggregate, \ArrayAccess ...@@ -698,6 +698,7 @@ class DataTable implements DataTableInterface, \IteratorAggregate, \ArrayAccess
*/ */
public function rebuildIndex() public function rebuildIndex()
{ {
$this->rowsIndexByLabel = array();
$this->rebuildIndexContinuously = true; $this->rebuildIndexContinuously = true;
foreach ($this->rows as $id => $row) { foreach ($this->rows as $id => $row) {
......
...@@ -107,6 +107,35 @@ class DataTableTest extends \PHPUnit_Framework_TestCase ...@@ -107,6 +107,35 @@ class DataTableTest extends \PHPUnit_Framework_TestCase
$this->assertEquals($table2->getRowFromIdSubDataTable($idTable3), $table2->getLastRow()); $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() public function test_clone_shouldIncreasesTableId()
{ {
$table = new DataTable; $table = new DataTable;
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter