UtilityTest.php 16 KB

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