order() public method

See also: Bolt\Twig\Handler\ArrayHandler::order()
public order ( $array, $on, $onSecondary = '' )
Example #1
0
 public function testOrder()
 {
     $app = $this->getApp();
     $handlers = $this->getTwigHandlers($app);
     $handlers['array'] = $this->getMockHandler('ArrayHandler', 'order');
     $twig = new TwigExtension($app, $handlers, true);
     $twig->order(null, null, null);
 }
Example #2
0
 public function testOrder()
 {
     $app = $this->getApp();
     $handlers = $this->getTwigHandlers($app);
     $twig = new TwigExtension($app, $handlers, false);
     $input = [['title' => 'Gamma', 'id' => 10, 'date' => '2014-01-19'], ['title' => 'Alpha', 'id' => 10, 'date' => '2014-02-20'], ['title' => 'Beta', 'id' => 8, 'date' => '2014-01-10'], ['title' => 'Delta', 'id' => 6, 'date' => '2014-01-19']];
     $result = array_values($twig->order($input, 'id'));
     $this->assertEquals('Delta', $result[0]['title']);
     $this->assertEquals('Beta', $result[1]['title']);
     $this->assertRegExp('/Alpha|Gamma/', $result[2]['title']);
     // Test sort on secondary keys
     $result = array_values($twig->order($input, 'id', 'date'));
     $this->assertEquals('Gamma', $result[2]['title']);
 }