UtilityTest.php 17 KB

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