PageRenderTime 45ms CodeModel.GetById 10ms RepoModel.GetById 0ms app.codeStats 0ms

/kirby/toolkit/test/SystemTest.php

https://gitlab.com/gricelya/Blog-Merry
PHP | 89 lines | 50 code | 20 blank | 19 comment | 0 complexity | a7ec1311ac94b09335c2de40fc6877c9 MD5 | raw file
  1. <?php
  2. require_once('lib/bootstrap.php');
  3. class SystemTest extends PHPUnit_Framework_TestCase {
  4. public function testIsExecutable() {
  5. // basic stuff
  6. $this->assertTrue(System::isExecutable('bash'));
  7. $this->assertFalse(System::isExecutable('somethingtotallynotexisting'));
  8. // with path
  9. $this->assertTrue(System::isExecutable('/bin/bash'));
  10. // with additional arguments
  11. $this->assertTrue(System::isExecutable('bash something totally strange and this should be ignored'));
  12. $this->assertFalse(System::isExecutable('somethingtotallynotexisting something totally strange and this should be ignored'));
  13. // executable files not in $PATH
  14. $this->assertTrue(System::isExecutable(TEST_ROOT_ETC . '/system/executable.sh'));
  15. $this->assertTrue(System::isExecutable(TEST_ROOT_ETC . '/system/executable.sh something totally strange and this should be ignored'));
  16. // non-executable files
  17. $this->assertFileExists(TEST_ROOT_ETC . '/system/nonexecutable.sh');
  18. $this->assertFalse(is_executable(TEST_ROOT_ETC . '/system/nonexecutable.sh'));
  19. $this->assertFalse(System::isExecutable(TEST_ROOT_ETC . '/system/nonexecutable.sh'));
  20. // invalid files
  21. $this->assertFalse(System::isExecutable(TEST_ROOT_ETC . '/system/notexisting.sh'));
  22. }
  23. public function testExecute() {
  24. // execute an existing system task
  25. $this->assertEquals(array('output' => 'Hello World', 'status' => 0, 'success' => true), System::execute('echo', 'Hello World'));
  26. // execute the dummy script
  27. $this->assertEquals(array('output' => 'Some dummy output just to test execution of this file.', 'status' => 0, 'success' => true), System::execute(TEST_ROOT_ETC . '/system/executable.sh', array('totallywayne')));
  28. // other arguments
  29. $this->assertEquals(array('output' => 'Something is sometimes not that cool. But anyway.', 'status' => 0, 'success' => true), System::execute(TEST_ROOT_ETC . '/system/executable.sh', array('something')));
  30. $this->assertEquals(array('output' => 'This probably failed. Or so.', 'status' => 42, 'success' => false), System::execute(TEST_ROOT_ETC . '/system/executable.sh', array('fail')));
  31. // other return values
  32. $this->assertEquals(array('output' => 'Some dummy output just to test execution of this file.', 'status' => 0, 'success' => true), System::execute(TEST_ROOT_ETC . '/system/executable.sh', array('totallywayne'), 'all'));
  33. $this->assertEquals(array('output' => 'Some dummy output just to test execution of this file.', 'status' => 0, 'success' => true), System::execute(TEST_ROOT_ETC . '/system/executable.sh', array('totallywayne'), 'notexistingforsure'));
  34. $this->assertEquals('Some dummy output just to test execution of this file.', System::execute(TEST_ROOT_ETC . '/system/executable.sh', array('totallywayne'), 'output'));
  35. $this->assertEquals(0, System::execute(TEST_ROOT_ETC . '/system/executable.sh', array('totallywayne'), 'status'));
  36. $this->assertEquals(true, System::execute(TEST_ROOT_ETC . '/system/executable.sh', array('totallywayne'), 'success'));
  37. // other ways of calling
  38. $this->assertEquals(System::execute(TEST_ROOT_ETC . '/system/executable.sh', array('something'), 'all'), System::execute(TEST_ROOT_ETC . '/system/executable.sh', 'something'));
  39. $this->assertEquals(System::execute(TEST_ROOT_ETC . '/system/executable.sh', array('something'), 'all'), System::execute(array(TEST_ROOT_ETC . '/system/executable.sh', 'something')));
  40. $this->assertEquals(System::execute(TEST_ROOT_ETC . '/system/executable.sh', array('something'), 'all'), System::execute(array(TEST_ROOT_ETC . '/system/executable.sh', 'something'), 'all'));
  41. $this->assertEquals(System::execute(TEST_ROOT_ETC . '/system/executable.sh', array('something'), 'success'), System::execute(array(TEST_ROOT_ETC . '/system/executable.sh', 'something'), 'success'));
  42. $this->assertEquals(System::execute(TEST_ROOT_ETC . '/system/executable.sh', array('fail'), 'success'), System::execute(array(TEST_ROOT_ETC . '/system/executable.sh', 'fail'), 'success'));
  43. }
  44. /**
  45. * @expectedException Exception
  46. */
  47. public function testExecuteInvalidThrow() {
  48. System::execute('notexistingforsure');
  49. }
  50. public function testCallStatic() {
  51. $filename = TEST_ROOT_ETC . '/system/executable.sh';
  52. // call the appropriate method statically
  53. $this->assertEquals(System::execute($filename, array('something'), 'all'), System::$filename('something'));
  54. $this->assertEquals(System::execute($filename, array('something'), 'all'), System::$filename('something', 'success'));
  55. $this->assertNotEquals(System::execute($filename, array('something'), 'success'), System::$filename('something', 'success'));
  56. }
  57. public function testRealpath() {
  58. // basic stuff
  59. $this->assertEquals('/bin/bash', System::realpath('bash'));
  60. $this->assertEquals(false, System::realpath('notexistingforsure'));
  61. // executable file
  62. $this->assertEquals(realpath(TEST_ROOT_ETC . '/system/executable.sh'), System::realpath(TEST_ROOT_ETC . '/system/executable.sh'));
  63. // not executable file
  64. $this->assertFileExists(TEST_ROOT_ETC . '/system/nonexecutable.sh');
  65. $this->assertEquals(false, System::realpath(TEST_ROOT_ETC . '/system/nonexecutable.sh'));
  66. // not existing file
  67. $this->assertEquals(false, System::realpath(TEST_ROOT_ETC . '/system/notexisting.sh'));
  68. }
  69. }