Skip to content

Commit

Permalink
Fixed bug in ArrayHelper::searchColumn() when using assoc arrays. closes
Browse files Browse the repository at this point in the history
  • Loading branch information
nadar committed Mar 27, 2019
1 parent 366ae9c commit e99684e
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
3 changes: 2 additions & 1 deletion core/CHANGELOG.md
Expand Up @@ -6,8 +6,9 @@ All notable changes to this project will be documented in this file. This projec

### Fixed

+ [#1911](https://github.com/luyadev/luya/issues/1911) Fixed bug in ArrayHelper::searchColumn() when using assoc arrays.
+ [#1910](https://github.com/luyadev/luya/issues/1910) Fixed resized callback in lazyload js
+ [#1909](https://github.com/luyadev/luya/issues/1909) Fix issued with wrong delimiter defintion in StringHelper::highlightWord() function.
+ [#1909](https://github.com/luyadev/luya/issues/1909) Fixed issued with wrong delimiter defintion in StringHelper::highlightWord() function.

## 1.0.15 (19. February 2019)

Expand Down
1 change: 1 addition & 0 deletions core/helpers/ArrayHelper.php
Expand Up @@ -187,6 +187,7 @@ public static function search(array $array, $searchText, $sensitive = false)
*/
public static function searchColumn(array $array, $column, $search)
{
$array = array_values($array); // align array keys
$columns = array_column($array, $column);
$key = array_search($search, $columns);
return ($key !== false) ? $array[$key] : false;
Expand Down
25 changes: 25 additions & 0 deletions tests/core/helpers/ArrayHelperTest.php
Expand Up @@ -149,6 +149,31 @@ public function testSearchColumns()

$this->assertSame([], ArrayHelper::searchColumns($array, 'foo', 'NOTFOUNDATALL'));
}

public function testSearchColumnsAndColumnWithAssocKeys()
{
$numbers = [
10 => ['column' => 'a'],
20 => ['column' => 'b'],
];

$assoc = [
"one" => ['column' => 'c'],
"two" => ['column' => 'd'],
];

$this->assertSame([
20 => ['column' => 'b'],
], ArrayHelper::searchColumns($numbers, 'column', 'b'));

$this->assertSame([
"two" => ['column' => 'd'],
], ArrayHelper::searchColumns($assoc, 'column', 'd'));

$this->assertSame(['column' => 'b'], ArrayHelper::searchColumn($numbers, 'column', 'b'));

$this->assertSame(['column' => 'd'], ArrayHelper::searchColumn($assoc, 'column', 'd'));
}

public function testGenerateRange()
{
Expand Down

0 comments on commit e99684e

Please sign in to comment.