UtilityTest.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742
  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. 'bol' => true,
  280. 'bl' => 'true',
  281. 'flt' => 3.14,
  282. 'fl' => '3.14'
  283. ];
  284. $expected = [
  285. 'f some',
  286. 'e 49r ' => 'rf r',
  287. 'er' => [['ee' => ['rr ' => 'tt', 'empty' => null]]],
  288. 'bsh' => 1,
  289. 'bkd' => '1',
  290. 'bol' => true,
  291. 'bl' => 'true',
  292. 'flt' => 3.14,
  293. 'fl' => '3.14'
  294. ];
  295. $res = Utility::trimDeep($is);
  296. $this->assertSame($expected, $res);
  297. }
  298. /**
  299. * @covers ::trimDeep
  300. * @return void
  301. */
  302. public function testDeepTransformNullToString() {
  303. $is = [
  304. 'f some',
  305. 'e 49r ' => 'rf r ',
  306. 'er' => [['ee' => ['rr ' => ' tt ', 'empty' => null]]]
  307. ];
  308. $expected = [
  309. 'f some',
  310. 'e 49r ' => 'rf r',
  311. 'er' => [['ee' => ['rr ' => 'tt', 'empty' => '']]]
  312. ];
  313. $res = Utility::trimDeep($is, true);
  314. $this->assertSame($expected, $res);
  315. }
  316. /**
  317. * //TODO
  318. *
  319. * @return void
  320. */
  321. public function _testDeepFunction() {
  322. $is = [
  323. 'f some',
  324. 'e 49r ' => 'rf r ',
  325. 'er' => [['ee' => ['rr ' => ' tt ']]]
  326. ];
  327. $expected = [
  328. 'f some',
  329. 'e 49r ' => 'rf r',
  330. 'er' => [['ee' => ['rr ' => 'tt']]]
  331. ];
  332. $result = Utility::deep('trim', $is);
  333. $this->assertSame($expected, $result);
  334. }
  335. /**
  336. * TestCountDim method
  337. *
  338. * @return void
  339. */
  340. public function testCountDim() {
  341. $data = ['one', '2', 'three'];
  342. $result = Utility::countDim($data);
  343. $this->assertSame(1, $result);
  344. $data = ['1' => '1.1', '2', '3'];
  345. $result = Utility::countDim($data);
  346. $this->assertSame(1, $result);
  347. $data = ['1' => ['1.1' => '1.1.1'], '2', '3' => ['3.1' => '3.1.1']];
  348. $result = Utility::countDim($data);
  349. $this->assertSame(2, $result);
  350. $data = ['1' => '1.1', '2', '3' => ['3.1' => '3.1.1']];
  351. $result = Utility::countDim($data);
  352. $this->assertSame(1, $result);
  353. $data = ['1' => '1.1', '2', '3' => ['3.1' => '3.1.1']];
  354. $result = Utility::countDim($data, true);
  355. $this->assertSame(2, $result);
  356. $data = ['1' => ['1.1' => '1.1.1'], '2', '3' => ['3.1' => ['3.1.1' => '3.1.1.1']]];
  357. $result = Utility::countDim($data);
  358. $this->assertSame(2, $result);
  359. $data = ['1' => ['1.1' => '1.1.1'], '2', '3' => ['3.1' => ['3.1.1' => '3.1.1.1']]];
  360. $result = Utility::countDim($data, true);
  361. $this->assertSame(3, $result);
  362. $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']]];
  363. $result = Utility::countDim($data, true);
  364. $this->assertSame(4, $result);
  365. $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']]];
  366. $result = Utility::countDim($data, true);
  367. $this->assertSame(5, $result);
  368. $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']]];
  369. $result = Utility::countDim($data, true);
  370. $this->assertSame(5, $result);
  371. $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']]];
  372. $result = Utility::countDim($set, false, 0);
  373. $this->assertSame(2, $result);
  374. $result = Utility::countDim($set, true);
  375. $this->assertSame(5, $result);
  376. $data = ['one' => [null], ['null' => null], 'three' => [true, false, null]];
  377. $result = Utility::countDim($data, true);
  378. $this->assertSame(2, $result);
  379. }
  380. /**
  381. * @return void
  382. */
  383. public function testExpandList() {
  384. $is = [
  385. 'Some.Deep.Value1',
  386. 'Some.Deep.Value2',
  387. 'Some.Even.Deeper.Nested.Value',
  388. 'Empty.',
  389. '0.1.2',
  390. '.EmptyString'
  391. ];
  392. $result = Utility::expandList($is);
  393. $expected = [
  394. 'Some' => [
  395. 'Deep' => ['Value1', 'Value2'],
  396. 'Even' => ['Deeper' => ['Nested' => ['Value']]]
  397. ],
  398. 'Empty' => [''],
  399. '0' => ['1' => ['2']],
  400. '' => ['EmptyString']
  401. ];
  402. $this->assertSame($expected, $result);
  403. }
  404. /**
  405. * @expectedException \RuntimeException
  406. * @return void
  407. */
  408. public function testExpandListWithKeyLessListInvalid() {
  409. $is = [
  410. 'Some',
  411. 'ValueOnly',
  412. ];
  413. Utility::expandList($is);
  414. }
  415. /**
  416. * @return void
  417. */
  418. public function testExpandListWithKeyLessList() {
  419. $is = [
  420. 'Some',
  421. 'Thing',
  422. '.EmptyString'
  423. ];
  424. $result = Utility::expandList($is, '.', '');
  425. $expected = [
  426. '' => ['Some', 'Thing', 'EmptyString'],
  427. ];
  428. $this->assertSame($expected, $result);
  429. }
  430. /**
  431. * @return void
  432. */
  433. public function testFlatten() {
  434. $is = [
  435. 'Some' => [
  436. 'Deep' => ['Value1', 'Value2'],
  437. 'Even' => ['Deeper' => ['Nested' => ['Value']]]
  438. ],
  439. 'Empty' => [''],
  440. '0' => ['1' => ['2']],
  441. //'ValueOnly',
  442. '' => ['EmptyString']
  443. ];
  444. $result = Utility::flattenList($is);
  445. $expected = [
  446. 'Some.Deep.Value1',
  447. 'Some.Deep.Value2',
  448. 'Some.Even.Deeper.Nested.Value',
  449. 'Empty.',
  450. '0.1.2',
  451. //'1.ValueOnly'
  452. '.EmptyString'
  453. ];
  454. $this->assertSame($expected, $result);
  455. // Test integers als booleans
  456. $is = [
  457. 'Some' => [
  458. 'Deep' => [true],
  459. 'Even' => ['Deeper' => ['Nested' => [false, true]]]
  460. ],
  461. 'Integer' => ['Value' => [-3]],
  462. ];
  463. $result = Utility::flattenList($is);
  464. $expected = [
  465. 'Some.Deep.1',
  466. 'Some.Even.Deeper.Nested.0',
  467. 'Some.Even.Deeper.Nested.1',
  468. 'Integer.Value.-3',
  469. ];
  470. $this->assertSame($expected, $result);
  471. }
  472. /**
  473. * @covers ::arrayFlatten
  474. * @return void
  475. */
  476. public function testArrayFlattenBasic() {
  477. $strings = [
  478. 'a' => ['a' => 'A'],
  479. 'b' => ['b' => 'B', 'c' => 'C'],
  480. 'c' => [],
  481. 'd' => [[['z' => 'Z'], 'y' => 'Y']]
  482. ];
  483. $result = Utility::arrayFlatten($strings);
  484. $expected = [
  485. 'a' => 'A',
  486. 'b' => 'B',
  487. 'c' => 'C',
  488. 'z' => 'Z',
  489. 'y' => 'Y'
  490. ];
  491. $this->assertSame($expected, $result);
  492. }
  493. /**
  494. * Test that deeper nested values overwrite higher ones.
  495. *
  496. * @covers ::arrayFlatten
  497. * @return void
  498. */
  499. public function testArrayFlatten() {
  500. $array = [
  501. 'a' => 1,
  502. 'b' => ['h' => false, 'c' => ['d' => ['f' => 'g', 'h' => true]]],
  503. 'k' => 'm',
  504. ];
  505. $res = Utility::arrayFlatten($array);
  506. $expected = [
  507. 'a' => 1,
  508. 'h' => true,
  509. 'f' => 'g',
  510. 'k' => 'm',
  511. ];
  512. $this->assertSame($expected, $res);
  513. }
  514. /**
  515. * @covers ::arrayFlatten
  516. * @return void
  517. */
  518. public function testArrayFlattenAndPreserveKeys() {
  519. $array = [
  520. 0 => 1,
  521. 1 => ['c' => ['d' => ['g', 'h' => true]]],
  522. 2 => 'm',
  523. ];
  524. $res = Utility::arrayFlatten($array, true);
  525. $expected = [
  526. 0 => 'g',
  527. 'h' => true,
  528. 2 => 'm',
  529. ];
  530. $this->assertSame($expected, $res);
  531. }
  532. /**
  533. * @covers ::arrayShiftKeys
  534. * @return void
  535. */
  536. public function testArrayShiftKeys() {
  537. $array = [
  538. 'a' => 1,
  539. 'b' => ['c' => ['d' => ['f' => 'g', 'h' => true]]],
  540. 'k' => 'm',
  541. ];
  542. $res = Utility::arrayShiftKeys($array);
  543. $expected = 'a';
  544. $this->assertSame($expected, $res);
  545. $expected = [
  546. 'b' => ['c' => ['d' => ['f' => 'g', 'h' => true]]],
  547. 'k' => 'm',
  548. ];
  549. $this->assertSame($expected, $array);
  550. }
  551. /**
  552. * @covers ::returnElapsedTime
  553. * @return void
  554. */
  555. public function testTime() {
  556. Utility::startClock();
  557. time_nanosleep(0, 200000000);
  558. $res = Utility::returnElapsedTime();
  559. $this->assertTrue(round($res, 1) === 0.2);
  560. time_nanosleep(0, 100000000);
  561. $res = Utility::returnElapsedTime(8, true);
  562. $this->assertTrue(round($res, 1) === 0.3);
  563. time_nanosleep(0, 100000000);
  564. $res = Utility::returnElapsedTime();
  565. $this->assertTrue(round($res, 1) === 0.1);
  566. }
  567. /**
  568. * @covers ::logicalAnd
  569. * @return void
  570. */
  571. public function testLogicalAnd() {
  572. $array = [
  573. 'a' => 1,
  574. 'b' => 1,
  575. 'c' => 0,
  576. 'd' => 1,
  577. ];
  578. $is = Utility::logicalAnd($array);
  579. $this->assertFalse($is);
  580. $array = [
  581. 'a' => 1,
  582. 'b' => 1,
  583. 'c' => 1,
  584. 'd' => 1,
  585. ];
  586. $is = Utility::logicalAnd($array);
  587. $this->assertTrue($is);
  588. }
  589. /**
  590. * @covers ::logicalOr
  591. * @return void
  592. */
  593. public function testLogicalOr() {
  594. $array = [
  595. 'a' => 0,
  596. 'b' => 1,
  597. 'c' => 0,
  598. 'd' => 1,
  599. ];
  600. $is = Utility::logicalOr($array);
  601. $this->assertTrue($is);
  602. $array = [
  603. 'a' => 1,
  604. 'b' => 1,
  605. 'c' => 1,
  606. 'd' => 1,
  607. ];
  608. $is = Utility::logicalOr($array);
  609. $this->assertTrue($is);
  610. $array = [
  611. 'a' => 0,
  612. 'b' => 0,
  613. 'c' => 0,
  614. 'd' => 0,
  615. ];
  616. $is = Utility::logicalOr($array);
  617. $this->assertFalse($is);
  618. }
  619. /**
  620. * @covers ::isValidSaveAll
  621. * @return void
  622. */
  623. public function testIsValidSaveAll() {
  624. $result = Utility::isValidSaveAll([]);
  625. $this->assertFalse($result);
  626. $result = Utility::isValidSaveAll([true, true]);
  627. $this->assertTrue($result);
  628. $result = Utility::isValidSaveAll([true, false]);
  629. $this->assertFalse($result);
  630. }
  631. }