|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Tests for FAIR\Packages\Admin\sort_sections_in_api(). |
| 4 | + * |
| 5 | + * @package FAIR |
| 6 | + */ |
| 7 | + |
| 8 | +use function FAIR\Packages\Admin\sort_sections_in_api; |
| 9 | + |
| 10 | +/** |
| 11 | + * Tests for FAIR\Packages\Admin\sort_sections_in_api(). |
| 12 | + * |
| 13 | + * @covers FAIR\Packages\Admin\sort_sections_in_api |
| 14 | + */ |
| 15 | +class SortSectionsInApi extends WP_UnitTestCase { |
| 16 | + |
| 17 | + /** |
| 18 | + * Test that sections are ordered in a predefined order. |
| 19 | + * |
| 20 | + * @dataProvider data_plugin_detail_sections |
| 21 | + * |
| 22 | + * @param array $sections Sections provided in arbitrary order, as if returned from MetadataDocument. |
| 23 | + * @param array $expected_order The sections in order we expect them to be. |
| 24 | + */ |
| 25 | + public function test_should_return_sections_in_predefined_order( array $sections, array $expected_order ) { |
| 26 | + $res = new stdClass(); |
| 27 | + $res->sections = $sections; |
| 28 | + $actual = sort_sections_in_api( $res ); |
| 29 | + $this->assertIsObject( $actual, 'The response is not an object.' ); |
| 30 | + // $this->assertObjectHasProperty( 'sections', $actual, 'The response object has no sections.' ); |
| 31 | + $this->assertSame( |
| 32 | + $expected_order, |
| 33 | + $actual->sections, |
| 34 | + 'The sections were not in the expected order.' |
| 35 | + ); |
| 36 | + } |
| 37 | + |
| 38 | + /** |
| 39 | + * Data provider. |
| 40 | + */ |
| 41 | + public static function data_plugin_detail_sections(): array { |
| 42 | + return [ |
| 43 | + 'expected sections' => [ |
| 44 | + 'sections' => [ |
| 45 | + 'faq' => 'faq', |
| 46 | + 'screenshots' => 'screenshots', |
| 47 | + 'changelog' => 'changelog', |
| 48 | + 'description' => 'description', |
| 49 | + 'security' => 'security', |
| 50 | + 'reviews' => 'reviews', |
| 51 | + 'other_notes' => 'other_notes', |
| 52 | + 'installation' => 'installation', |
| 53 | + 'upgrade_notice' => 'upgrade_notice', |
| 54 | + ], |
| 55 | + 'expected_order' => [ |
| 56 | + 'description' => 'description', |
| 57 | + 'installation' => 'installation', |
| 58 | + 'faq' => 'faq', |
| 59 | + 'screenshots' => 'screenshots', |
| 60 | + 'changelog' => 'changelog', |
| 61 | + 'upgrade_notice' => 'upgrade_notice', |
| 62 | + 'security' => 'security', |
| 63 | + 'other_notes' => 'other_notes', |
| 64 | + 'reviews' => 'reviews', |
| 65 | + ], |
| 66 | + ], |
| 67 | + 'unknown sections' => [ |
| 68 | + 'sections' => [ |
| 69 | + 'foo' => 'foo', |
| 70 | + 'bar' => 'bar', |
| 71 | + 'baz' => 'baz', |
| 72 | + ], |
| 73 | + 'expected_order' => [ |
| 74 | + 'foo' => 'foo', |
| 75 | + 'bar' => 'bar', |
| 76 | + 'baz' => 'baz', |
| 77 | + ], |
| 78 | + ], |
| 79 | + 'expected and unknown sections' => [ |
| 80 | + 'sections' => [ |
| 81 | + 'faq' => 'faq', |
| 82 | + 'foo' => 'foo', |
| 83 | + 'screenshots' => 'screenshots', |
| 84 | + 'changelog' => 'changelog', |
| 85 | + 'bar' => 'bar', |
| 86 | + 'reviews' => 'reviews', |
| 87 | + 'installation' => 'installation', |
| 88 | + 'security' => 'security', |
| 89 | + ], |
| 90 | + 'expected_order' => [ |
| 91 | + 'installation' => 'installation', |
| 92 | + 'faq' => 'faq', |
| 93 | + 'screenshots' => 'screenshots', |
| 94 | + 'changelog' => 'changelog', |
| 95 | + 'security' => 'security', |
| 96 | + 'reviews' => 'reviews', |
| 97 | + 'foo' => 'foo', |
| 98 | + 'bar' => 'bar', |
| 99 | + ], |
| 100 | + ], |
| 101 | + 'empty sections' => [ |
| 102 | + 'sections' => [], |
| 103 | + 'expected_order' => [], |
| 104 | + ], |
| 105 | + ]; |
| 106 | + } |
| 107 | +} |
0 commit comments