UtilityTest.php 16 KB

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