Fixed yii\data\ArrayDataProvider::getKeys() return wrong when yii\data\ArrayDataProvider::$allModels contain integer key

This commit is contained in:
Klimov Paul
2015-04-14 17:07:16 +03:00
parent a8f4e8bee4
commit bb4bed4833
3 changed files with 31 additions and 1 deletions

View File

@@ -22,6 +22,7 @@ Yii Framework 2 Change Log
- Bug #8014: Fixed setting incorrect form "action" property after submitting a form using a link with "data-method" and containing "action" among "data-params" (samdark)
- Bug #8032: `yii\rbac\PhpManager::updateItem()` was unable to rename item updated (ChristopheBrun, samdark)
- Bug #8068: Fixed `yii\db\Query::count()` fails for query containing 'having' without 'group by' (klimov-paul)
- Bug #8073: Fixed `yii\data\ArrayDataProvider::getKeys()` return wrong when `yii\data\ArrayDataProvider::$allModels` contain integer key (mdmunir, klimov-paul)
- Enh #3376: Added `yii\validators\EachValidator`, which allows validation of the array attributes (klimov-paul)
- Enh #6895: Added `ignoreCategories` config option for message command to ignore categories specified (samdark)
- Enh #6975: Pressing arrows while focused in inputs of Active Form with `validateOnType` enabled no longer triggers validation (slinstj)

View File

@@ -82,7 +82,7 @@ class ArrayDataProvider extends BaseDataProvider
$pagination->totalCount = $this->getTotalCount();
if ($pagination->getPageSize() > 0) {
$models = array_slice($models, $pagination->getOffset(), $pagination->getLimit());
$models = array_slice($models, $pagination->getOffset(), $pagination->getLimit(), true);
}
}

View File

@@ -150,4 +150,33 @@ class ArrayDataProviderTest extends TestCase
$this->assertEquals($sortedProjects, $dataProvider->getModels());
}
public function testGetKeys()
{
$pagination = ['pageSize' => 2];
$simpleArray = [
['name' => 'zero'],
['name' => 'one'],
['name' => 'tow'],
];
$dataProvider = new ArrayDataProvider(['allModels' => $simpleArray, 'pagination' => $pagination]);
$this->assertEquals([0, 1], $dataProvider->getKeys());
$namedArray = [
'key1' => ['name' => 'zero'],
'key2' => ['name' => 'one'],
'key3' => ['name' => 'two'],
];
$dataProvider = new ArrayDataProvider(['allModels' => $namedArray, 'pagination' => $pagination]);
$this->assertEquals(['key1', 'key2'], $dataProvider->getKeys());
$mixedArray = [
'key1' => ['name' => 'zero'],
9 => ['name' => 'one'],
'key3' => ['name' => 'two'],
];
$dataProvider = new ArrayDataProvider(['allModels' => $mixedArray, 'pagination' => $pagination]);
$this->assertEquals(['key1', 9], $dataProvider->getKeys());
}
}