UtilityTest.php 17 KB

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