UtilityTest.php 17 KB

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