-
Notifications
You must be signed in to change notification settings - Fork 132
/
Copy pathMagentoAssert.php
51 lines (47 loc) · 1.55 KB
/
MagentoAssert.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\FunctionalTestingFramework\Module;
/**
* Class MagentoAssert
*
* Contains all custom assert functions to be used in tests.
*
* @package Magento\FunctionalTestingFramework\Module
*/
class MagentoAssert extends \Codeception\Module
{
/**
* Asserts that all items in the array are sorted by given direction. Can be given int, string, double, dates.
* Converts given date strings to epoch for comparison.
*
* @param array $data
* @param string $sortOrder
* @return void
*/
public function assertArrayIsSorted(array $data, $sortOrder = "asc")
{
$elementTotal = count($data);
$message = null;
// If value can be converted to a date and it isn't 1.1 number (strtotime is overzealous)
if (strtotime($data[0]) !== false && !is_numeric($data[0])) {
$message = "Array of dates converted to unix timestamp for comparison";
$data = array_map('strtotime', $data);
} else {
$data = array_map('strtolower', $data);
}
if ($sortOrder == "asc") {
for ($i = 1; $i < $elementTotal; $i++) {
// $i >= $i-1
$this->assertLessThanOrEqual($data[$i], $data[$i-1], $message);
}
} else {
for ($i = 1; $i < $elementTotal; $i++) {
// $i <= $i-1
$this->assertGreaterThanOrEqual($data[$i], $data[$i-1], $message);
}
}
}
}