/** * Test sorting an array of objects. * * @param array $input Input array of objects * @param mixed $key Key to sort on * @param mixed $direction Ascending (1) or Descending(-1) * @param string $casesensitive @todo * @param string $locale @todo * @param array $expect The expected results * @param string $message The failure message * @param boolean $defaults Use the defaults (true) or full argument list * * @return void * * @dataProvider seedTestSortObject * @covers Windwalker\Utilities\ArrayHelper::sortObjects * @since 1.0 */ public function testSortObjects($input, $key, $direction, $casesensitive, $locale, $expect, $message, $defaults, $swappable_keys = array()) { // Convert the $locale param to a string if it is an array if (is_array($locale)) { $locale = "'" . implode("', '", $locale) . "'"; } if (empty($input)) { $this->markTestSkipped('Skip for MAC until PHP sort bug is fixed'); return; } elseif ($locale != false && !setlocale(LC_COLLATE, $locale)) { // If the locale is not available, we can't have to transcode the string and can't reliably compare it. $this->markTestSkipped("Locale {$locale} is not available."); return; } if ($defaults) { $output = ArrayHelper::sortObjects($input, $key); } else { $output = ArrayHelper::sortObjects($input, $key, $direction, $casesensitive, $locale); } // The ordering of elements that compare equal according to // $key is undefined (implementation dependent). if ($expect != $output && $swappable_keys) { list($k1, $k2) = $swappable_keys; $e1 = $output[$k1]; $e2 = $output[$k2]; $output[$k1] = $e2; $output[$k2] = $e1; } $this->assertEquals($expect, $output, $message); }