UtilityTest.php 17 KB

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