AuthExtComponentTest.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <?php
  2. App::uses('AuthExtComponent', 'Tools.Controller/Component');
  3. App::uses('Controller', 'Controller');
  4. App::uses('AppModel', 'Model');
  5. /**
  6. * Test case for AuthExt
  7. */
  8. class AuthExtComponentTest extends CakeTestCase {
  9. public $fixtures = array('plugin.tools.tools_user', 'plugin.tools.role', 'core.cake_session');
  10. public function setUp() {
  11. parent::setUp();
  12. Configure::delete('Auth');
  13. $this->Controller = new AuthExtTestController(new CakeRequest, new CakeResponse);
  14. $this->Controller->constructClasses();
  15. $this->Controller->startupProcess();
  16. $this->Controller->User->belongsTo = array(
  17. 'Role' => array(
  18. 'className' => 'Tools.Role'
  19. )
  20. );
  21. }
  22. public function tearDown() {
  23. parent::tearDown();
  24. unset($this->Controller->TestAuthExt);
  25. unset($this->Controller);
  26. }
  27. /**
  28. * AuthExtComponentTest::testBasics()
  29. *
  30. * @return void
  31. */
  32. public function testBasics() {
  33. $res = $this->Controller->TestAuthExt->allow();
  34. $is = $this->Controller->TestAuthExt->getModel();
  35. $this->assertTrue(is_object($is) && $is->name === 'User');
  36. }
  37. /**
  38. * AuthExtComponentTest::_testCompleteAuth()
  39. *
  40. * @return void
  41. */
  42. public function _testCompleteAuth() {
  43. $is = $this->Controller->TestAuthExt->completeAuth(1);
  44. debug($is);
  45. $this->assertTrue(!empty($is));
  46. $is = $this->Controller->TestAuthExt->completeAuth(111);
  47. echo returns($is);
  48. $this->assertFalse($is);
  49. }
  50. }
  51. class TestAuthExtComponent extends AuthExtComponent {
  52. }
  53. class AuthExtTestController extends Controller {
  54. public $uses = array('User');
  55. /**
  56. * Components property
  57. *
  58. * @var array
  59. */
  60. public $components = array('Session', 'TestAuthExt' => array('userModel' => 'AuthUser', 'parentModelAlias' => 'Role'));
  61. /**
  62. * Failed property
  63. *
  64. * @var boolean
  65. */
  66. public $failed = false;
  67. /**
  68. * Used for keeping track of headers in test
  69. *
  70. * @var array
  71. */
  72. public $testHeaders = array();
  73. /**
  74. * Fail method
  75. *
  76. * @return void
  77. */
  78. public function fail() {
  79. $this->failed = true;
  80. }
  81. /**
  82. * Redirect method
  83. *
  84. * @param mixed $option
  85. * @param mixed $code
  86. * @param mixed $exit
  87. * @return void
  88. */
  89. public function redirect($url, $status = null, $exit = true) {
  90. return $status;
  91. }
  92. /**
  93. * Conveinence method for header()
  94. *
  95. * @param string $status
  96. * @return void
  97. */
  98. public function header($status) {
  99. $this->testHeaders[] = $status;
  100. }
  101. }
  102. class AuthUser extends AppModel {
  103. public $name = 'User';
  104. public $alias = 'User';
  105. public $useTable = 'tools_users';
  106. }