diff --git a/tests/phpunit/fixtures/sort/complex-sorted-asc.json b/tests/phpunit/fixtures/sort/complex-sorted-asc.json new file mode 100644 index 00000000..0d19545a --- /dev/null +++ b/tests/phpunit/fixtures/sort/complex-sorted-asc.json @@ -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": "" + } +] diff --git a/tests/phpunit/fixtures/sort/complex-sorted-desc.json b/tests/phpunit/fixtures/sort/complex-sorted-desc.json new file mode 100644 index 00000000..2ed69aac --- /dev/null +++ b/tests/phpunit/fixtures/sort/complex-sorted-desc.json @@ -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": "" + } +] diff --git a/tests/phpunit/fixtures/sort/complex.json b/tests/phpunit/fixtures/sort/complex.json new file mode 100644 index 00000000..918214e2 --- /dev/null +++ b/tests/phpunit/fixtures/sort/complex.json @@ -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" + } +] diff --git a/tests/phpunit/fixtures/sort/empty-sorted.json b/tests/phpunit/fixtures/sort/empty-sorted.json new file mode 100644 index 00000000..540f968c --- /dev/null +++ b/tests/phpunit/fixtures/sort/empty-sorted.json @@ -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": "" + } +] diff --git a/tests/phpunit/fixtures/sort/empty.json b/tests/phpunit/fixtures/sort/empty.json new file mode 100644 index 00000000..540f968c --- /dev/null +++ b/tests/phpunit/fixtures/sort/empty.json @@ -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": "" + } +] diff --git a/tests/phpunit/fixtures/sort/equal-sorted.json b/tests/phpunit/fixtures/sort/equal-sorted.json new file mode 100644 index 00000000..5f2ca1da --- /dev/null +++ b/tests/phpunit/fixtures/sort/equal-sorted.json @@ -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" + } +] diff --git a/tests/phpunit/fixtures/sort/equal.json b/tests/phpunit/fixtures/sort/equal.json new file mode 100644 index 00000000..048ff20e --- /dev/null +++ b/tests/phpunit/fixtures/sort/equal.json @@ -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" + } +] diff --git a/tests/phpunit/unit/test-sort.php b/tests/phpunit/unit/test-sort.php new file mode 100644 index 00000000..9e064aa7 --- /dev/null +++ b/tests/phpunit/unit/test-sort.php @@ -0,0 +1,94 @@ +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 + ); + } +}