UtilityTest.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734
  1. <?php
  2. namespace Tools\Test\TestCase\Utility;
  3. use Cake\Core\Configure;
  4. use Cake\Core\Plugin;
  5. use Tools\TestSuite\TestCase;
  6. use Tools\Utility\Utility;
  7. /**
  8. * @coversDefaultClass \Tools\Utility\Utility
  9. */
  10. class UtilityTest extends TestCase {
  11. /**
  12. * @return void
  13. */
  14. public function testNotBlank() {
  15. $res = Utility::notBlank('a');
  16. $this->assertTrue($res);
  17. $res = Utility::notBlank(2);
  18. $this->assertTrue($res);
  19. $res = Utility::notBlank(0);
  20. $this->assertTrue($res);
  21. $res = Utility::notBlank('0');
  22. $this->assertTrue($res);
  23. $res = Utility::notBlank(null);
  24. $this->assertFalse($res);
  25. $res = Utility::notBlank(false);
  26. $this->assertFalse($res);
  27. $res = Utility::notBlank('');
  28. $this->assertFalse($res);
  29. $res = Utility::notBlank([]);
  30. $this->assertFalse($res);
  31. }
  32. /**
  33. * @return void
  34. */
  35. public function testNotEmpty() {
  36. $res = Utility::notEmpty('a');
  37. $this->assertTrue($res);
  38. $res = Utility::notEmpty(2);
  39. $this->assertTrue($res);
  40. $res = Utility::notEmpty(0);
  41. $this->assertFalse($res);
  42. $res = Utility::notEmpty('0');
  43. $this->assertTrue($res);
  44. $res = Utility::notEmpty(null);
  45. $this->assertFalse($res);
  46. $res = Utility::notEmpty(false);
  47. $this->assertFalse($res);
  48. $res = Utility::notEmpty('');
  49. $this->assertFalse($res);
  50. $res = Utility::notEmpty([]);
  51. $this->assertFalse($res);
  52. }
  53. /**
  54. * @covers ::inArray
  55. * @return void
  56. */
  57. public function testInArray() {
  58. $res = Utility::inArray(2, [1, 2, 3]);
  59. $this->assertTrue($res);
  60. $res = Utility::inArray(4, [1, 2, 7]);
  61. $this->assertFalse($res);
  62. $res = Utility::inArray('2', [1, 2, 3]);
  63. $this->assertTrue($res);
  64. $res = Utility::inArray(2, ['1x', '2x', '3x']);
  65. $this->assertFalse($res);
  66. $res = Utility::inArray('3x', ['1x', '2x', '3x']);
  67. $this->assertTrue($res);
  68. $res = Utility::inArray(3, ['1', '2', '3']);
  69. $this->assertTrue($res);
  70. $res = Utility::inArray('2x', [1, 2, 3]);
  71. $this->assertFalse($res);
  72. }
  73. /**
  74. * @return void
  75. */
  76. public function testTokenize() {
  77. $res = Utility::tokenize('');
  78. $this->assertSame([], $res);
  79. $res = Utility::tokenize('some');
  80. $this->assertSame(['some'], $res);
  81. $res = Utility::tokenize('some, thing');
  82. $this->assertSame(['some', 'thing'], $res);
  83. $res = Utility::tokenize(',some,,, ,, thing,');
  84. $this->assertSame(['some', 'thing'], array_values($res));
  85. }
  86. /**
  87. * @covers ::pregMatch
  88. * @return void
  89. */
  90. public function testPregMatch() {
  91. $string = '<abc>';
  92. preg_match('/\<(\w+)\>/', $string, $matches);
  93. $this->assertSame([$string, 'abc'], $matches);
  94. $matches = Utility::pregMatch('/\<(\w+)\>/', $string);
  95. $this->assertSame([$string, 'abc'], $matches);
  96. $string = '<äöü>';
  97. preg_match('/\<(.+)\>/', $string, $matches);
  98. $this->assertSame([$string, 'äöü'], $matches);
  99. $matches = Utility::pregMatch('/\<(.+)\>/', $string);
  100. $this->assertSame([$string, 'äöü'], $matches);
  101. $string = 'D-81245 München';
  102. preg_match('/(*UTF8)([\w+])-([a-z0-9]+)\s+\b([\w\s]+)\b/iu', $string, $matches);
  103. $expected = [
  104. $string,
  105. 'D',
  106. '81245',
  107. 'München'
  108. ];
  109. $this->assertSame($expected, $matches);
  110. // we dont need the utf8 hack:
  111. $matches = Utility::pregMatch('/([\w+])-([a-z0-9]+)\s+\b([\w\s]+)\b/iu', $string);
  112. $this->assertSame($expected, $matches);
  113. }
  114. /**
  115. * @covers ::pregMatch
  116. * @return void
  117. */
  118. public function testPregMatchWithPatternEscape() {
  119. $string = 'http://www.example.com/s?q=php.net+docs';
  120. $res = preg_quote($string);
  121. $this->assertSame('http\://www\.example\.com/s\?q\=php\.net\+docs', $res);
  122. $string = 'http://www.example.com/s?q=php.net+docs';
  123. $res = preg_quote($string, '/');
  124. $this->assertSame('http\:\/\/www\.example\.com\/s\?q\=php\.net\+docs', $res);
  125. $res = '/a\s*' . $res . '\s*z/i';
  126. $string = 'a ' . $string . ' z';
  127. $matches = Utility::pregMatch($res, $string);
  128. $expected = [$string];
  129. $this->assertSame($expected, $matches);
  130. }
  131. /**
  132. * @covers ::pregMatchAll
  133. * @return void
  134. */
  135. public function testPregMatchAll() {
  136. $string = 'D-81245 München';
  137. preg_match_all('/(*UTF8)([\w+])-([a-z0-9]+)\s+\b([\w\s]+)\b/iu', $string, $matches, PREG_SET_ORDER);
  138. $expected = [
  139. [
  140. $string,
  141. 'D',
  142. '81245',
  143. 'München'
  144. ]
  145. ];
  146. $this->assertSame($expected, $matches);
  147. // we dont need the utf8 hack:
  148. $matches = Utility::pregMatchAll('/([\w+])-([a-z0-9]+)\s+\b([\w\s]+)\b/iu', $string);
  149. $this->assertSame($expected, $matches);
  150. }
  151. /**
  152. * @covers ::strSplit
  153. * @return void
  154. */
  155. public function testStrSplit() {
  156. $res = str_split('some äöü string', 7);
  157. $expected = ['some äö', 'ü strin', 'g'];
  158. $this->assertNotSame($expected, $res);
  159. $res = Utility::strSplit('some äöü string', 7);
  160. $this->assertSame($expected, $res);
  161. }
  162. /**
  163. * @covers ::typeCast
  164. * @return void
  165. */
  166. public function testTypeCast() {
  167. $res = Utility::typeCast(2, 'string');
  168. $this->assertNotSame(2, $res);
  169. $this->assertSame('2', $res);
  170. }
  171. /**
  172. * @covers ::getClientIp
  173. * @return void
  174. */
  175. public function testGetClientIp() {
  176. $res = Utility::getClientIp();
  177. $this->assertSame((string)env('REMOTE_ADDR'), $res);
  178. }
  179. /**
  180. * @covers ::fileExists
  181. * @return void
  182. */
  183. public function testFileExists() {
  184. $res = Utility::fileExists('http://www.spiegel.de/static/sys/v10/icons/home_v2.png');
  185. $this->assertTrue($res);
  186. $res = Utility::fileExists(Plugin::path('Tools') . 'tests' . DS . 'test_files' . DS . 'img' . DS . 'hotel.jpg');
  187. $this->assertTrue($res);
  188. $res = Utility::fileExists('http://www.spiegel.de/static/sys/v10/icons/home_v2_inexistent.png');
  189. $this->assertFalse($res);
  190. $res = Utility::fileExists(Plugin::path('Tools') . 'tests' . DS . 'test_files' . DS . 'img' . DS . 'fooooo.jpg');
  191. $this->assertFalse($res);
  192. }
  193. /**
  194. * @covers ::urlExists
  195. * @return void
  196. */
  197. public function testUrlExists() {
  198. $res = Utility::urlExists('http://www.spiegel.de');
  199. $this->assertTrue($res);
  200. $res = Utility::urlExists('http://www.spiegel.de/some/inexistent.img');
  201. $this->assertFalse($res);
  202. }
  203. /**
  204. * @covers ::getReferer
  205. * @return void
  206. */
  207. public function testGetReferer() {
  208. $res = Utility::getReferer();
  209. $this->assertSame(env('HTTP_REFERER'), $res);
  210. $res = Utility::getReferer(true);
  211. $this->assertSame(env('HTTP_REFERER'), $res);
  212. $_SERVER['HTTP_REFERER'] = '/foo/bar';
  213. $res = Utility::getReferer(true);
  214. $base = Configure::read('App.fullBaseUrl');
  215. if (!$base) {
  216. $base = ''; //'http://localhost';
  217. }
  218. $this->assertSame($base . env('HTTP_REFERER'), $res);
  219. }
  220. /**
  221. * @covers ::getHeaderFromUrl
  222. * @return void
  223. */
  224. public function testGetHeaderFromUrl() {
  225. $res = Utility::getHeaderFromUrl('http://www.spiegel.de');
  226. $this->assertTrue(is_array($res) && count($res) > 1);
  227. //$this->assertSame('HTTP/1.0 200 OK', $res[0]);
  228. }
  229. /**
  230. * @covers ::autoPrefixUrl
  231. * @return void
  232. */
  233. public function testAutoPrefixUrl() {
  234. $res = Utility::autoPrefixUrl('www.spiegel.de');
  235. $this->assertSame('http://www.spiegel.de', $res);
  236. }
  237. /**
  238. * @covers ::cleanUrl
  239. * @return void
  240. */
  241. public function testCleanUrl() {
  242. $res = Utility::cleanUrl('www.spiegel.de');
  243. $this->assertSame('http://www.spiegel.de', $res);
  244. $res = Utility::cleanUrl('http://');
  245. $this->assertSame('', $res);
  246. $res = Utility::cleanUrl('http://www');
  247. $this->assertSame('', $res);
  248. $res = Utility::cleanUrl('spiegel.de');
  249. $this->assertSame('http://spiegel.de', $res);
  250. $res = Utility::cleanUrl('spiegel.de', true);
  251. $this->assertSame('http://www.spiegel.de', $res);
  252. }
  253. /**
  254. * @return void
  255. */
  256. public function testStripUrl() {
  257. $urls = [
  258. 'http://www.cakephp.org/bla/bla' => 'www.cakephp.org/bla/bla',
  259. 'www.cakephp.org' => 'www.cakephp.org',
  260. 'https://spiegel.de' => 'spiegel.de',
  261. 'ftp://xyz' => 'ftp://xyz',
  262. ];
  263. foreach ($urls as $url => $expected) {
  264. $is = Utility::stripProtocol($url);
  265. $this->assertEquals($expected, $is, $url);
  266. }
  267. }
  268. /**
  269. * @covers ::trimDeep
  270. * @return void
  271. */
  272. public function testDeep() {
  273. $is = [
  274. 'f some',
  275. 'e 49r ' => 'rf r ',
  276. 'er' => [['ee' => ['rr ' => ' tt ', 'empty' => null]]],
  277. 'bsh' => 1,
  278. 'bkd' => '1'
  279. ];
  280. $expected = [
  281. 'f some',
  282. 'e 49r ' => 'rf r',
  283. 'er' => [['ee' => ['rr ' => 'tt', 'empty' => null]]],
  284. 'bsh' => 1,
  285. 'bkd' => '1'
  286. ];
  287. $res = Utility::trimDeep($is);
  288. $this->assertSame($expected, $res);
  289. }
  290. /**
  291. * @covers ::trimDeep
  292. * @return void
  293. */
  294. public function testDeepTransformNullToString() {
  295. $is = [
  296. 'f some',
  297. 'e 49r ' => 'rf r ',
  298. 'er' => [['ee' => ['rr ' => ' tt ', 'empty' => null]]]
  299. ];
  300. $expected = [
  301. 'f some',
  302. 'e 49r ' => 'rf r',
  303. 'er' => [['ee' => ['rr ' => 'tt', 'empty' => '']]]
  304. ];
  305. $res = Utility::trimDeep($is, true);
  306. $this->assertSame($expected, $res);
  307. }
  308. /**
  309. * //TODO
  310. *
  311. * @return void
  312. */
  313. public function _testDeepFunction() {
  314. $is = [
  315. 'f some',
  316. 'e 49r ' => 'rf r ',
  317. 'er' => [['ee' => ['rr ' => ' tt ']]]
  318. ];
  319. $expected = [
  320. 'f some',
  321. 'e 49r ' => 'rf r',
  322. 'er' => [['ee' => ['rr ' => 'tt']]]
  323. ];
  324. $result = Utility::deep('trim', $is);
  325. $this->assertSame($expected, $result);
  326. }
  327. /**
  328. * TestCountDim method
  329. *
  330. * @return void
  331. */
  332. public function testCountDim() {
  333. $data = ['one', '2', 'three'];
  334. $result = Utility::countDim($data);
  335. $this->assertSame(1, $result);
  336. $data = ['1' => '1.1', '2', '3'];
  337. $result = Utility::countDim($data);
  338. $this->assertSame(1, $result);
  339. $data = ['1' => ['1.1' => '1.1.1'], '2', '3' => ['3.1' => '3.1.1']];
  340. $result = Utility::countDim($data);
  341. $this->assertSame(2, $result);
  342. $data = ['1' => '1.1', '2', '3' => ['3.1' => '3.1.1']];
  343. $result = Utility::countDim($data);
  344. $this->assertSame(1, $result);
  345. $data = ['1' => '1.1', '2', '3' => ['3.1' => '3.1.1']];
  346. $result = Utility::countDim($data, true);
  347. $this->assertSame(2, $result);
  348. $data = ['1' => ['1.1' => '1.1.1'], '2', '3' => ['3.1' => ['3.1.1' => '3.1.1.1']]];
  349. $result = Utility::countDim($data);
  350. $this->assertSame(2, $result);
  351. $data = ['1' => ['1.1' => '1.1.1'], '2', '3' => ['3.1' => ['3.1.1' => '3.1.1.1']]];
  352. $result = Utility::countDim($data, true);
  353. $this->assertSame(3, $result);
  354. $data = ['1' => ['1.1' => '1.1.1'], ['2' => ['2.1' => ['2.1.1' => '2.1.1.1']]], '3' => ['3.1' => ['3.1.1' => '3.1.1.1']]];
  355. $result = Utility::countDim($data, true);
  356. $this->assertSame(4, $result);
  357. $data = ['1' => ['1.1' => '1.1.1'], ['2' => ['2.1' => ['2.1.1' => ['2.1.1.1']]]], '3' => ['3.1' => ['3.1.1' => '3.1.1.1']]];
  358. $result = Utility::countDim($data, true);
  359. $this->assertSame(5, $result);
  360. $data = ['1' => ['1.1' => '1.1.1'], ['2' => ['2.1' => ['2.1.1' => ['2.1.1.1' => '2.1.1.1.1']]]], '3' => ['3.1' => ['3.1.1' => '3.1.1.1']]];
  361. $result = Utility::countDim($data, true);
  362. $this->assertSame(5, $result);
  363. $set = ['1' => ['1.1' => '1.1.1'], ['2' => ['2.1' => ['2.1.1' => ['2.1.1.1' => '2.1.1.1.1']]]], '3' => ['3.1' => ['3.1.1' => '3.1.1.1']]];
  364. $result = Utility::countDim($set, false, 0);
  365. $this->assertSame(2, $result);
  366. $result = Utility::countDim($set, true);
  367. $this->assertSame(5, $result);
  368. $data = ['one' => [null], ['null' => null], 'three' => [true, false, null]];
  369. $result = Utility::countDim($data, true);
  370. $this->assertSame(2, $result);
  371. }
  372. /**
  373. * @return void
  374. */
  375. public function testExpandList() {
  376. $is = [
  377. 'Some.Deep.Value1',
  378. 'Some.Deep.Value2',
  379. 'Some.Even.Deeper.Nested.Value',
  380. 'Empty.',
  381. '0.1.2',
  382. '.EmptyString'
  383. ];
  384. $result = Utility::expandList($is);
  385. $expected = [
  386. 'Some' => [
  387. 'Deep' => ['Value1', 'Value2'],
  388. 'Even' => ['Deeper' => ['Nested' => ['Value']]]
  389. ],
  390. 'Empty' => [''],
  391. '0' => ['1' => ['2']],
  392. '' => ['EmptyString']
  393. ];
  394. $this->assertSame($expected, $result);
  395. }
  396. /**
  397. * @expectedException \RuntimeException
  398. * @return void
  399. */
  400. public function testExpandListWithKeyLessListInvalid() {
  401. $is = [
  402. 'Some',
  403. 'ValueOnly',
  404. ];
  405. Utility::expandList($is);
  406. }
  407. /**
  408. * @return void
  409. */
  410. public function testExpandListWithKeyLessList() {
  411. $is = [
  412. 'Some',
  413. 'Thing',
  414. '.EmptyString'
  415. ];
  416. $result = Utility::expandList($is, '.', '');
  417. $expected = [
  418. '' => ['Some', 'Thing', 'EmptyString'],
  419. ];
  420. $this->assertSame($expected, $result);
  421. }
  422. /**
  423. * @return void
  424. */
  425. public function testFlatten() {
  426. $is = [
  427. 'Some' => [
  428. 'Deep' => ['Value1', 'Value2'],
  429. 'Even' => ['Deeper' => ['Nested' => ['Value']]]
  430. ],
  431. 'Empty' => [''],
  432. '0' => ['1' => ['2']],
  433. //'ValueOnly',
  434. '' => ['EmptyString']
  435. ];
  436. $result = Utility::flattenList($is);
  437. $expected = [
  438. 'Some.Deep.Value1',
  439. 'Some.Deep.Value2',
  440. 'Some.Even.Deeper.Nested.Value',
  441. 'Empty.',
  442. '0.1.2',
  443. //'1.ValueOnly'
  444. '.EmptyString'
  445. ];
  446. $this->assertSame($expected, $result);
  447. // Test integers als booleans
  448. $is = [
  449. 'Some' => [
  450. 'Deep' => [true],
  451. 'Even' => ['Deeper' => ['Nested' => [false, true]]]
  452. ],
  453. 'Integer' => ['Value' => [-3]],
  454. ];
  455. $result = Utility::flattenList($is);
  456. $expected = [
  457. 'Some.Deep.1',
  458. 'Some.Even.Deeper.Nested.0',
  459. 'Some.Even.Deeper.Nested.1',
  460. 'Integer.Value.-3',
  461. ];
  462. $this->assertSame($expected, $result);
  463. }
  464. /**
  465. * @covers ::arrayFlatten
  466. * @return void
  467. */
  468. public function testArrayFlattenBasic() {
  469. $strings = [
  470. 'a' => ['a' => 'A'],
  471. 'b' => ['b' => 'B', 'c' => 'C'],
  472. 'c' => [],
  473. 'd' => [[['z' => 'Z'], 'y' => 'Y']]
  474. ];
  475. $result = Utility::arrayFlatten($strings);
  476. $expected = [
  477. 'a' => 'A',
  478. 'b' => 'B',
  479. 'c' => 'C',
  480. 'z' => 'Z',
  481. 'y' => 'Y'
  482. ];
  483. $this->assertSame($expected, $result);
  484. }
  485. /**
  486. * Test that deeper nested values overwrite higher ones.
  487. *
  488. * @covers ::arrayFlatten
  489. * @return void
  490. */
  491. public function testArrayFlatten() {
  492. $array = [
  493. 'a' => 1,
  494. 'b' => ['h' => false, 'c' => ['d' => ['f' => 'g', 'h' => true]]],
  495. 'k' => 'm',
  496. ];
  497. $res = Utility::arrayFlatten($array);
  498. $expected = [
  499. 'a' => 1,
  500. 'h' => true,
  501. 'f' => 'g',
  502. 'k' => 'm',
  503. ];
  504. $this->assertSame($expected, $res);
  505. }
  506. /**
  507. * @covers ::arrayFlatten
  508. * @return void
  509. */
  510. public function testArrayFlattenAndPreserveKeys() {
  511. $array = [
  512. 0 => 1,
  513. 1 => ['c' => ['d' => ['g', 'h' => true]]],
  514. 2 => 'm',
  515. ];
  516. $res = Utility::arrayFlatten($array, true);
  517. $expected = [
  518. 0 => 'g',
  519. 'h' => true,
  520. 2 => 'm',
  521. ];
  522. $this->assertSame($expected, $res);
  523. }
  524. /**
  525. * @covers ::arrayShiftKeys
  526. * @return void
  527. */
  528. public function testArrayShiftKeys() {
  529. $array = [
  530. 'a' => 1,
  531. 'b' => ['c' => ['d' => ['f' => 'g', 'h' => true]]],
  532. 'k' => 'm',
  533. ];
  534. $res = Utility::arrayShiftKeys($array);
  535. $expected = 'a';
  536. $this->assertSame($expected, $res);
  537. $expected = [
  538. 'b' => ['c' => ['d' => ['f' => 'g', 'h' => true]]],
  539. 'k' => 'm',
  540. ];
  541. $this->assertSame($expected, $array);
  542. }
  543. /**
  544. * @covers ::returnElapsedTime
  545. * @return void
  546. */
  547. public function testTime() {
  548. Utility::startClock();
  549. time_nanosleep(0, 200000000);
  550. $res = Utility::returnElapsedTime();
  551. $this->assertTrue(round($res, 1) === 0.2);
  552. time_nanosleep(0, 100000000);
  553. $res = Utility::returnElapsedTime(8, true);
  554. $this->assertTrue(round($res, 1) === 0.3);
  555. time_nanosleep(0, 100000000);
  556. $res = Utility::returnElapsedTime();
  557. $this->assertTrue(round($res, 1) === 0.1);
  558. }
  559. /**
  560. * @covers ::logicalAnd
  561. * @return void
  562. */
  563. public function testLogicalAnd() {
  564. $array = [
  565. 'a' => 1,
  566. 'b' => 1,
  567. 'c' => 0,
  568. 'd' => 1,
  569. ];
  570. $is = Utility::logicalAnd($array);
  571. $this->assertFalse($is);
  572. $array = [
  573. 'a' => 1,
  574. 'b' => 1,
  575. 'c' => 1,
  576. 'd' => 1,
  577. ];
  578. $is = Utility::logicalAnd($array);
  579. $this->assertTrue($is);
  580. }
  581. /**
  582. * @covers ::logicalOr
  583. * @return void
  584. */
  585. public function testLogicalOr() {
  586. $array = [
  587. 'a' => 0,
  588. 'b' => 1,
  589. 'c' => 0,
  590. 'd' => 1,
  591. ];
  592. $is = Utility::logicalOr($array);
  593. $this->assertTrue($is);
  594. $array = [
  595. 'a' => 1,
  596. 'b' => 1,
  597. 'c' => 1,
  598. 'd' => 1,
  599. ];
  600. $is = Utility::logicalOr($array);
  601. $this->assertTrue($is);
  602. $array = [
  603. 'a' => 0,
  604. 'b' => 0,
  605. 'c' => 0,
  606. 'd' => 0,
  607. ];
  608. $is = Utility::logicalOr($array);
  609. $this->assertFalse($is);
  610. }
  611. /**
  612. * @covers ::isValidSaveAll
  613. * @return void
  614. */
  615. public function testIsValidSaveAll() {
  616. $result = Utility::isValidSaveAll([]);
  617. $this->assertFalse($result);
  618. $result = Utility::isValidSaveAll([true, true]);
  619. $this->assertTrue($result);
  620. $result = Utility::isValidSaveAll([true, false]);
  621. $this->assertFalse($result);
  622. }
  623. }