QloginTest.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. App::uses('Qlogin', 'Tools.Model');
  3. App::uses('MyCakeTestCase', 'Tools.TestSuite');
  4. App::uses('Router', 'Routing');
  5. class QloginTest extends MyCakeTestCase {
  6. public $Qlogin = null;
  7. public $fixtures = array('plugin.tools.code_key', 'plugin.tools.token');
  8. public function setUp() {
  9. parent::setUp();
  10. $this->Qlogin = ClassRegistry::init('Tools.Qlogin');
  11. }
  12. public function testQloginInstance() {
  13. $this->assertInstanceOf('Qlogin', $this->Qlogin);
  14. }
  15. public function testGenerateDeprecated() {
  16. $url = Router::url(array('admin' => false, 'plugin' => 'tools', 'controller' => 'qlogin', 'action' => 'go'), true) . '/';
  17. //debug($url);
  18. $this->assertTrue(!empty($url));
  19. $res = $this->Qlogin->url(array('controller' => 'test', 'action' => 'foo', 'bar'), 1);
  20. //debug($res);
  21. $this->assertTrue(is_string($res) && !empty($res));
  22. $this->assertTrue(strpos($res, $url) === 0);
  23. $res = $this->Qlogin->url('/test/foo/bar', 2);
  24. //debug($res);
  25. $this->assertTrue(is_string($res) && !empty($res));
  26. }
  27. public function testUseDeprecated() {
  28. $key = $this->Qlogin->generate(array('controller' => 'test', 'action' => 'foo', 'bar'), 1);
  29. $res = $this->Qlogin->translate($key);
  30. $this->assertTrue(is_array($res) && !empty($res));
  31. $key = $this->Qlogin->generate('/test/foo/bar', 2);
  32. $res = $this->Qlogin->translate($key);
  33. $this->assertTrue(is_array($res) && !empty($res));
  34. $res = $this->Qlogin->translate('foobar');
  35. $this->assertFalse($res);
  36. }
  37. public function testGenerate() {
  38. $this->Qlogin->generator = 'Token';
  39. $url = Router::url(array('admin' => false, 'plugin' => 'tools', 'controller' => 'qlogin', 'action' => 'go'), true) . '/';
  40. //debug($url);
  41. $this->assertTrue(!empty($url));
  42. $res = $this->Qlogin->url(array('controller' => 'test', 'action' => 'foo', 'bar'), 1);
  43. //debug($res);
  44. $this->assertTrue(is_string($res) && !empty($res));
  45. $this->assertTrue(strpos($res, $url) === 0);
  46. $res = $this->Qlogin->url('/test/foo/bar', 2);
  47. //debug($res);
  48. $this->assertTrue(is_string($res) && !empty($res));
  49. }
  50. public function testUse() {
  51. $this->Qlogin->generator = 'Token';
  52. $key = $this->Qlogin->generate(array('controller' => 'test', 'action' => 'foo', 'bar'), 1);
  53. $res = $this->Qlogin->translate($key);
  54. $this->assertTrue(is_array($res) && !empty($res));
  55. $key = $this->Qlogin->generate('/test/foo/bar', 2);
  56. $res = $this->Qlogin->translate($key);
  57. $this->assertTrue(is_array($res) && !empty($res));
  58. $res = $this->Qlogin->translate('foobar');
  59. $this->assertFalse($res);
  60. }
  61. }