-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
324 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
[ | ||
{ | ||
"id": "9", | ||
"imgUrl": "test.jpeg", | ||
"imgThumbnailUrl": "test-150x150.jpeg", | ||
"title": "archer" | ||
}, | ||
{ | ||
"id": "1", | ||
"imgUrl": "archer.png", | ||
"imgThumbnailUrl": "archer.png", | ||
"title": "archer" | ||
}, | ||
{ | ||
"id": "7", | ||
"imgUrl": "archer.png", | ||
"imgThumbnailUrl": "archer.png", | ||
"title": "archer" | ||
}, | ||
{ | ||
"id": "19", | ||
"imgUrl": "test.gif", | ||
"imgThumbnailUrl": "test-1024x679.jpg", | ||
"title": "test" | ||
}, | ||
{ | ||
"id": "37", | ||
"imgUrl": "test.png", | ||
"imgThumbnailUrl": "test.png", | ||
"title": "test 1" | ||
}, | ||
{ | ||
"id": "2", | ||
"imgUrl": "trailer.png", | ||
"imgThumbnailUrl": "trailer.png", | ||
"title": "trailer" | ||
}, | ||
{ | ||
"id": "25", | ||
"imgUrl": "test.png", | ||
"imgThumbnailUrl": "test.png", | ||
"title": "" | ||
}, | ||
{ | ||
"id": "10", | ||
"imgUrl": "test.png", | ||
"imgThumbnailUrl": "test.png", | ||
"title": "" | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
[ | ||
{ | ||
"id": "2", | ||
"imgUrl": "trailer.png", | ||
"imgThumbnailUrl": "trailer.png", | ||
"title": "trailer" | ||
}, | ||
{ | ||
"id": "37", | ||
"imgUrl": "test.png", | ||
"imgThumbnailUrl": "test.png", | ||
"title": "test 1" | ||
}, | ||
{ | ||
"id": "19", | ||
"imgUrl": "test.gif", | ||
"imgThumbnailUrl": "test-1024x679.jpg", | ||
"title": "test" | ||
}, | ||
{ | ||
"id": "7", | ||
"imgUrl": "archer.png", | ||
"imgThumbnailUrl": "archer.png", | ||
"title": "archer" | ||
}, | ||
{ | ||
"id": "1", | ||
"imgUrl": "archer.png", | ||
"imgThumbnailUrl": "archer.png", | ||
"title": "archer" | ||
}, | ||
{ | ||
"id": "9", | ||
"imgUrl": "test.jpeg", | ||
"imgThumbnailUrl": "test-150x150.jpeg", | ||
"title": "archer" | ||
}, | ||
{ | ||
"id": "25", | ||
"imgUrl": "test.png", | ||
"imgThumbnailUrl": "test.png", | ||
"title": "" | ||
}, | ||
{ | ||
"id": "10", | ||
"imgUrl": "test.png", | ||
"imgThumbnailUrl": "test.png", | ||
"title": "" | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
[ | ||
{ | ||
"id": "19", | ||
"imgUrl": "test.gif", | ||
"imgThumbnailUrl": "test-1024x679.jpg", | ||
"title": "test" | ||
}, | ||
{ | ||
"id": "9", | ||
"imgUrl": "test.jpeg", | ||
"imgThumbnailUrl": "test-150x150.jpeg", | ||
"title": "archer" | ||
}, | ||
{ | ||
"id": "25", | ||
"imgUrl": "test.png", | ||
"imgThumbnailUrl": "test.png", | ||
"title": "" | ||
}, | ||
{ | ||
"id": "37", | ||
"imgUrl": "test.png", | ||
"imgThumbnailUrl": "test.png", | ||
"title": "test 1" | ||
}, | ||
{ | ||
"id": "2", | ||
"imgUrl": "trailer.png", | ||
"imgThumbnailUrl": "trailer.png", | ||
"title": "trailer" | ||
}, | ||
{ | ||
"id": "10", | ||
"imgUrl": "test.png", | ||
"imgThumbnailUrl": "test.png", | ||
"title": "" | ||
}, | ||
{ | ||
"id": "1", | ||
"imgUrl": "archer.png", | ||
"imgThumbnailUrl": "archer.png", | ||
"title": "archer" | ||
}, | ||
{ | ||
"id": "7", | ||
"imgUrl": "archer.png", | ||
"imgThumbnailUrl": "archer.png", | ||
"title": "archer" | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
[ | ||
{ | ||
"id": "19", | ||
"imgUrl": "test.gif", | ||
"imgThumbnailUrl": "test-1024x679.jpg", | ||
"title": "" | ||
}, | ||
{ | ||
"id": "9", | ||
"imgUrl": "test.jpeg", | ||
"imgThumbnailUrl": "test-150x150.jpeg", | ||
"title": "" | ||
}, | ||
{ | ||
"id": "25", | ||
"imgUrl": "test.png", | ||
"imgThumbnailUrl": "test.png", | ||
"title": "" | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
[ | ||
{ | ||
"id": "19", | ||
"imgUrl": "test.gif", | ||
"imgThumbnailUrl": "test-1024x679.jpg", | ||
"title": "" | ||
}, | ||
{ | ||
"id": "9", | ||
"imgUrl": "test.jpeg", | ||
"imgThumbnailUrl": "test-150x150.jpeg", | ||
"title": "" | ||
}, | ||
{ | ||
"id": "25", | ||
"imgUrl": "test.png", | ||
"imgThumbnailUrl": "test.png", | ||
"title": "" | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
[ | ||
{ | ||
"id": "25", | ||
"imgUrl": "test.png", | ||
"imgThumbnailUrl": "test.png", | ||
"title": "test-title" | ||
}, | ||
{ | ||
"id": "9", | ||
"imgUrl": "test.jpeg", | ||
"imgThumbnailUrl": "test-150x150.jpeg", | ||
"title": "test-title" | ||
}, | ||
{ | ||
"id": "19", | ||
"imgUrl": "test.gif", | ||
"imgThumbnailUrl": "test-1024x679.jpg", | ||
"title": "test-title" | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
[ | ||
{ | ||
"id": "19", | ||
"imgUrl": "test.gif", | ||
"imgThumbnailUrl": "test-1024x679.jpg", | ||
"title": "test-title" | ||
}, | ||
{ | ||
"id": "9", | ||
"imgUrl": "test.jpeg", | ||
"imgThumbnailUrl": "test-150x150.jpeg", | ||
"title": "test-title" | ||
}, | ||
{ | ||
"id": "25", | ||
"imgUrl": "test.png", | ||
"imgThumbnailUrl": "test.png", | ||
"title": "test-title" | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
<?php | ||
/** | ||
* Tests for ClassSort | ||
* | ||
* @package Visual Portfolio | ||
*/ | ||
|
||
/** | ||
* Sort test case. | ||
*/ | ||
class ClassSort extends WP_UnitTestCase { | ||
/** | ||
* Get fixture for test. | ||
* | ||
* @param string $filename - name of json file | ||
* @return string | ||
*/ | ||
public function get_json_array( $filename ) { | ||
$filepath = dirname( dirname( __FILE__ ) ) . '/fixtures/sort/' . $filename . '.json'; | ||
$json = file_get_contents( $filepath ); | ||
// Decode the JSON file | ||
$json_data = json_decode( $json, true ); | ||
|
||
return $json_data; | ||
} | ||
|
||
/** | ||
* Test for sort array with equal elements. | ||
* | ||
* @return void | ||
*/ | ||
public function test_sort_equal() { | ||
// Read the JSON file | ||
$equal_array = $this->get_json_array( 'equal' ); | ||
$equal_sorted_array = $this->get_json_array( 'equal-sorted' ); | ||
$sorted_array_asc = Visual_Portfolio_Get::sort_array_by_field( $equal_array, 'title', 'asc' ); | ||
$sorted_array_desc = Visual_Portfolio_Get::sort_array_by_field( $equal_array, 'title', 'desc' ); | ||
|
||
$this->assertEquals( | ||
$equal_array, | ||
$sorted_array_asc | ||
); | ||
|
||
$this->assertEquals( | ||
$equal_sorted_array, | ||
$sorted_array_desc | ||
); | ||
} | ||
|
||
/** | ||
* Test for sort array with empty elements. | ||
* | ||
* @return void | ||
*/ | ||
public function test_sort_empty() { | ||
$empty_array = $this->get_json_array( 'empty' ); | ||
$empty_sorted_array = $this->get_json_array( 'empty-sorted' ); | ||
$sorted_array_asc = Visual_Portfolio_Get::sort_array_by_field( $empty_array, 'title', 'asc' ); | ||
$sorted_array_desc = Visual_Portfolio_Get::sort_array_by_field( $empty_array, 'title', 'desc' ); | ||
|
||
$this->assertEquals( | ||
$empty_sorted_array, | ||
$sorted_array_asc | ||
); | ||
|
||
$this->assertEquals( | ||
$empty_sorted_array, | ||
$sorted_array_desc | ||
); | ||
} | ||
|
||
/** | ||
* Test for sort array with complex elements. | ||
* | ||
* @return void | ||
*/ | ||
public function test_sort_complex() { | ||
$complex_array = $this->get_json_array( 'complex' ); | ||
$complex_sorted_array_asc = $this->get_json_array( 'complex-sorted-asc' ); | ||
$complex_sorted_array_desc = $this->get_json_array( 'complex-sorted-desc' ); | ||
$sorted_array_asc = Visual_Portfolio_Get::sort_array_by_field( $complex_array, 'title', 'asc' ); | ||
$sorted_array_desc = Visual_Portfolio_Get::sort_array_by_field( $complex_array, 'title', 'desc' ); | ||
|
||
$this->assertEquals( | ||
$complex_sorted_array_asc, | ||
$sorted_array_asc | ||
); | ||
|
||
$this->assertEquals( | ||
$complex_sorted_array_desc, | ||
$sorted_array_desc | ||
); | ||
} | ||
} |