ActionsServiceTest.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. namespace Elgg;
  3. class ActionsServiceTest extends \PHPUnit_Framework_TestCase {
  4. public function setUp() {
  5. $this->actionsDir = dirname(dirname(__FILE__)) . "/test_files/actions";
  6. }
  7. /**
  8. * Tests register, exists and unregisrer
  9. */
  10. public function testCanRegisterFilesAsActions() {
  11. $actions = new \Elgg\ActionsService();
  12. $this->assertFalse($actions->exists('test/output'));
  13. $this->assertFalse($actions->exists('test/not_registered'));
  14. $this->assertTrue($actions->register('test/output', "$this->actionsDir/output.php", 'public'));
  15. $this->assertTrue($actions->register('test/non_ex_file', "$this->actionsDir/non_existing_file.php", 'public'));
  16. $this->assertTrue($actions->exists('test/output'));
  17. $this->assertFalse($actions->exists('test/non_ex_file'));
  18. $this->assertFalse($actions->exists('test/not_registered'));
  19. return $actions;
  20. }
  21. /**
  22. * @depends testCanRegisterFilesAsActions
  23. */
  24. public function testCanUnregisterActions($actions) {
  25. $this->assertTrue($actions->unregister('test/output'));
  26. $this->assertTrue($actions->unregister('test/non_ex_file'));
  27. $this->assertFalse($actions->unregister('test/not_registered'));
  28. $this->assertFalse($actions->exists('test/output'));
  29. $this->assertFalse($actions->exists('test/non_ex_file'));
  30. $this->assertFalse($actions->exists('test/not_registered'));
  31. }
  32. /**
  33. * Tests overwriting existing action
  34. */
  35. public function testCanOverrideRegisteredActions() {
  36. $actions = new \Elgg\ActionsService();
  37. $this->assertFalse($actions->exists('test/output'));
  38. $this->assertTrue($actions->register('test/output', "$this->actionsDir/output.php", 'public'));
  39. $this->assertTrue($actions->exists('test/output'));
  40. $this->assertTrue($actions->register('test/output', "$this->actionsDir/output2.php", 'public'));
  41. $this->assertTrue($actions->exists('test/output'));
  42. }
  43. public function testActionsAccessLevels() {
  44. $actions = new \Elgg\ActionsService();
  45. $this->assertFalse($actions->exists('test/output'));
  46. $this->assertFalse($actions->exists('test/not_registered'));
  47. $this->assertTrue($actions->register('test/output', "$this->actionsDir/output.php", 'public'));
  48. $this->assertTrue($actions->register('test/output_logged_in', "$this->actionsDir/output.php", 'logged_in'));
  49. $this->assertTrue($actions->register('test/output_admin', "$this->actionsDir/output.php", 'admin'));
  50. //TODO finish this test
  51. $this->markTestIncomplete("Can't test execution due to missing configuration.php dependencies");
  52. // $actions->execute('test/not_registered');
  53. }
  54. public function testActionReturnValuesAreIgnored() {
  55. $this->markTestIncomplete();
  56. }
  57. //TODO call non existing
  58. //TODO token generation/validation
  59. // public function testGenerateValidateTokens() {
  60. // $actions = new \Elgg\ActionsService();
  61. // $i = 40;
  62. // while ($i-->0) {
  63. // $timestamp = rand(100000000, 2000000000);
  64. // $token = $actions->generateActionToken($timestamp);
  65. // $this->assertTrue($actions->validateActionToken(false, $token, $timestamp));
  66. // $this->assertFalse($actions->validateActionToken(false, $token, $timestamp+1));
  67. // $this->assertFalse($actions->validateActionToken(false, $token, $timestamp-1));
  68. // }
  69. // }
  70. //TODO gatekeeper?
  71. }