Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
MagentoAssert.php
Go to the documentation of this file.
1 <?php
8 
16 class MagentoAssert extends \Codeception\Module
17 {
26  public function assertArrayIsSorted(array $data, $sortOrder = "asc")
27  {
28  $elementTotal = count($data);
29  $message = null;
30 
31  // If value can be converted to a date and it isn't 1.1 number (strtotime is overzealous)
32  if (strtotime($data[0]) !== false && !is_numeric($data[0])) {
33  $message = "Array of dates converted to unix timestamp for comparison";
34  $data = array_map('strtotime', $data);
35  } else {
36  $data = array_map('strtolower', $data);
37  }
38 
39  if ($sortOrder == "asc") {
40  for ($i = 1; $i < $elementTotal; $i++) {
41  // $i >= $i-1
42  $this->assertLessThanOrEqual($data[$i], $data[$i-1], $message);
43  }
44  } else {
45  for ($i = 1; $i < $elementTotal; $i++) {
46  // $i <= $i-1
47  $this->assertGreaterThanOrEqual($data[$i], $data[$i-1], $message);
48  }
49  }
50  }
51 }
$message
$i
Definition: gallery.phtml:31