Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PSDI Army
yii2
Commits
59cb5d11
Commit
59cb5d11
authored
May 15, 2013
by
slavcopost
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add unit test
parent
ad988267
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
39 additions
and
2 deletions
+39
-2
ArrayHelperTest.php
tests/unit/framework/helpers/ArrayHelperTest.php
+39
-2
No files found.
tests/unit/framework/helpers/ArrayHelperTest.php
View file @
59cb5d11
...
@@ -3,6 +3,8 @@
...
@@ -3,6 +3,8 @@
namespace
yiiunit\framework\helpers
;
namespace
yiiunit\framework\helpers
;
use
yii\helpers\ArrayHelper
;
use
yii\helpers\ArrayHelper
;
use
yii\helpers\VarDumper
;
use
yii\web\Sort
;
class
ArrayHelperTest
extends
\yii\test\TestCase
class
ArrayHelperTest
extends
\yii\test\TestCase
{
{
...
@@ -54,16 +56,51 @@ class ArrayHelperTest extends \yii\test\TestCase
...
@@ -54,16 +56,51 @@ class ArrayHelperTest extends \yii\test\TestCase
array
(
'name'
=>
'A'
,
'age'
=>
1
),
array
(
'name'
=>
'A'
,
'age'
=>
1
),
);
);
ArrayHelper
::
multisort
(
$array
,
array
(
'name'
,
'age'
),
SORT_ASC
,
array
(
SORT_STRING
,
SORT_REGULAR
));
ArrayHelper
::
multisort
(
$array
,
array
(
'name'
,
'age'
),
false
,
array
(
SORT_STRING
,
SORT_REGULAR
));
$this
->
assertEquals
(
array
(
'name'
=>
'A'
,
'age'
=>
1
),
$array
[
0
]);
$this
->
assertEquals
(
array
(
'name'
=>
'A'
,
'age'
=>
1
),
$array
[
0
]);
$this
->
assertEquals
(
array
(
'name'
=>
'B'
,
'age'
=>
4
),
$array
[
1
]);
$this
->
assertEquals
(
array
(
'name'
=>
'B'
,
'age'
=>
4
),
$array
[
1
]);
$this
->
assertEquals
(
array
(
'name'
=>
'a'
,
'age'
=>
3
),
$array
[
2
]);
$this
->
assertEquals
(
array
(
'name'
=>
'a'
,
'age'
=>
3
),
$array
[
2
]);
$this
->
assertEquals
(
array
(
'name'
=>
'b'
,
'age'
=>
2
),
$array
[
3
]);
$this
->
assertEquals
(
array
(
'name'
=>
'b'
,
'age'
=>
2
),
$array
[
3
]);
ArrayHelper
::
multisort
(
$array
,
array
(
'name'
,
'age'
),
SORT_ASC
,
array
(
SORT_STRING
,
SORT_REGULAR
),
false
);
ArrayHelper
::
multisort
(
$array
,
array
(
'name'
,
'age'
),
false
,
array
(
SORT_STRING
,
SORT_REGULAR
),
false
);
$this
->
assertEquals
(
array
(
'name'
=>
'A'
,
'age'
=>
1
),
$array
[
0
]);
$this
->
assertEquals
(
array
(
'name'
=>
'A'
,
'age'
=>
1
),
$array
[
0
]);
$this
->
assertEquals
(
array
(
'name'
=>
'a'
,
'age'
=>
3
),
$array
[
1
]);
$this
->
assertEquals
(
array
(
'name'
=>
'a'
,
'age'
=>
3
),
$array
[
1
]);
$this
->
assertEquals
(
array
(
'name'
=>
'b'
,
'age'
=>
2
),
$array
[
2
]);
$this
->
assertEquals
(
array
(
'name'
=>
'b'
,
'age'
=>
2
),
$array
[
2
]);
$this
->
assertEquals
(
array
(
'name'
=>
'B'
,
'age'
=>
4
),
$array
[
3
]);
$this
->
assertEquals
(
array
(
'name'
=>
'B'
,
'age'
=>
4
),
$array
[
3
]);
}
}
public
function
testMultisortUseSort
()
{
// single key
$sort
=
new
Sort
();
$sort
->
attributes
=
array
(
'name'
,
'age'
);
$sort
->
defaults
=
array
(
'name'
=>
Sort
::
ASC
);
$orders
=
$sort
->
getOrders
();
$array
=
array
(
array
(
'name'
=>
'b'
,
'age'
=>
3
),
array
(
'name'
=>
'a'
,
'age'
=>
1
),
array
(
'name'
=>
'c'
,
'age'
=>
2
),
);
ArrayHelper
::
multisort
(
$array
,
array_keys
(
$orders
),
array_values
(
$orders
));
$this
->
assertEquals
(
array
(
'name'
=>
'a'
,
'age'
=>
1
),
$array
[
0
]);
$this
->
assertEquals
(
array
(
'name'
=>
'b'
,
'age'
=>
3
),
$array
[
1
]);
$this
->
assertEquals
(
array
(
'name'
=>
'c'
,
'age'
=>
2
),
$array
[
2
]);
// multiple keys
$sort
=
new
Sort
();
$sort
->
attributes
=
array
(
'name'
,
'age'
);
$sort
->
defaults
=
array
(
'name'
=>
Sort
::
ASC
,
'age'
=>
Sort
::
DESC
);
$orders
=
$sort
->
getOrders
();
$array
=
array
(
array
(
'name'
=>
'b'
,
'age'
=>
3
),
array
(
'name'
=>
'a'
,
'age'
=>
2
),
array
(
'name'
=>
'a'
,
'age'
=>
1
),
);
ArrayHelper
::
multisort
(
$array
,
array_keys
(
$orders
),
array_values
(
$orders
));
$this
->
assertEquals
(
array
(
'name'
=>
'a'
,
'age'
=>
2
),
$array
[
0
]);
$this
->
assertEquals
(
array
(
'name'
=>
'a'
,
'age'
=>
1
),
$array
[
1
]);
$this
->
assertEquals
(
array
(
'name'
=>
'b'
,
'age'
=>
3
),
$array
[
2
]);
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment