QloginTest.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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 = ['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. $this->Qlogin->generator = 'CodeKey';
  17. $this->CodeKey = ClassRegistry::init('Tools.CodeKey');
  18. $count = $this->CodeKey->find('count');
  19. $url = Router::url(['admin' => false, 'plugin' => 'tools', 'controller' => 'qlogin', 'action' => 'go'], true) . '/';
  20. $this->assertTrue(!empty($url));
  21. $res = $this->Qlogin->url(['controller' => 'test', 'action' => 'foo', 'bar'], 1);
  22. $this->assertTrue(is_string($res) && !empty($res));
  23. $this->assertTrue(strpos($res, $url) === 0);
  24. $res = $this->Qlogin->url('/test/foo/bar', 2);
  25. $this->assertTrue(is_string($res) && !empty($res));
  26. $count2 = $this->CodeKey->find('count');
  27. $this->assertTrue($count2 > $count);
  28. }
  29. public function testUseDeprecated() {
  30. $this->Qlogin->generator = 'CodeKey';
  31. $key = $this->Qlogin->generate(['controller' => 'test', 'action' => 'foo', 'bar'], 1);
  32. $res = $this->Qlogin->translate($key);
  33. $this->assertTrue(is_array($res) && !empty($res));
  34. $key = $this->Qlogin->generate('/test/foo/bar', 2);
  35. $res = $this->Qlogin->translate($key);
  36. $this->assertTrue(is_array($res) && !empty($res));
  37. $res = $this->Qlogin->translate('foobar');
  38. $this->assertFalse($res);
  39. }
  40. public function testGenerate() {
  41. $url = Router::url(['admin' => false, 'plugin' => 'tools', 'controller' => 'qlogin', 'action' => 'go'], true) . '/';
  42. //debug($url);
  43. $this->assertTrue(!empty($url));
  44. $res = $this->Qlogin->url(['controller' => 'test', 'action' => 'foo', 'bar'], 1);
  45. //debug($res);
  46. $this->assertTrue(is_string($res) && !empty($res));
  47. $this->assertTrue(strpos($res, $url) === 0);
  48. $res = $this->Qlogin->url('/test/foo/bar', 2);
  49. //debug($res);
  50. $this->assertTrue(is_string($res) && !empty($res));
  51. }
  52. public function testUse() {
  53. $key = $this->Qlogin->generate(['controller' => 'test', 'action' => 'foo', 'bar'], 1);
  54. $res = $this->Qlogin->translate($key);
  55. $this->assertTrue(is_array($res) && !empty($res));
  56. $key = $this->Qlogin->generate('/test/foo/bar', 2);
  57. $res = $this->Qlogin->translate($key);
  58. $this->assertTrue(is_array($res) && !empty($res));
  59. $res = $this->Qlogin->translate('foobar');
  60. $this->assertFalse($res);
  61. }
  62. }