JsPullTest.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_ProgressBar
  17. * @subpackage UnitTests
  18. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id$
  21. */
  22. // Call Zend_ProgressBar_Adapter_JsPullTest::main() if this source file is executed directly.
  23. if (!defined("PHPUnit_MAIN_METHOD")) {
  24. define("PHPUnit_MAIN_METHOD", "Zend_ProgressBar_Adapter_JsPullTest::main");
  25. }
  26. /**
  27. * Test helper
  28. */
  29. require_once dirname(__FILE__) . '/../../../TestHelper.php';
  30. /**
  31. * Zend_ProgressBar_Adapter_JsPull
  32. */
  33. require_once 'Zend/ProgressBar/Adapter/JsPull.php';
  34. /**
  35. * @category Zend
  36. * @package Zend_ProgressBar
  37. * @subpackage UnitTests
  38. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  39. * @license http://framework.zend.com/license/new-bsd New BSD License
  40. * @group Zend_ProgressBar
  41. */
  42. class Zend_ProgressBar_Adapter_JsPullTest extends PHPUnit_Framework_TestCase
  43. {
  44. /**
  45. * Runs the test methods of this class.
  46. *
  47. * @return void
  48. */
  49. public static function main()
  50. {
  51. $suite = new PHPUnit_Framework_TestSuite("Zend_ProgressBar_Adapter_JsPullTest");
  52. $result = PHPUnit_TextUI_TestRunner::run($suite);
  53. }
  54. public function testJson()
  55. {
  56. $adapter = new Zend_ProgressBar_Adapter_JsPull_Stub();
  57. $adapter->notify(0, 2, 0.5, 1, 1, 'status');
  58. $output = $adapter->getLastOutput();
  59. $data = json_decode($output, true);
  60. $this->assertEquals(0, $data['current']);
  61. $this->assertEquals(2, $data['max']);
  62. $this->assertEquals(50, $data['percent']);
  63. $this->assertEquals(1, $data['timeTaken']);
  64. $this->assertEquals(1, $data['timeRemaining']);
  65. $this->assertEquals('status', $data['text']);
  66. $this->assertFalse($data['finished']);
  67. $adapter->finish();
  68. $output = $adapter->getLastOutput();
  69. $data = json_decode($output, true);
  70. $this->assertTrue($data['finished']);
  71. }
  72. }
  73. class Zend_ProgressBar_Adapter_JsPull_Stub extends Zend_ProgressBar_Adapter_JsPull
  74. {
  75. protected $_lastOutput = null;
  76. public function getLastOutput()
  77. {
  78. return $this->_lastOutput;
  79. }
  80. protected function _outputData($data)
  81. {
  82. $this->_lastOutput = $data;
  83. }
  84. }
  85. // Call Zend_ProgressBar_Adapter_JsPullTest::main() if this source file is executed directly.
  86. if (PHPUnit_MAIN_METHOD == "Zend_ProgressBar_Adapter_JsPullTest::main") {
  87. Zend_ProgressBar_Adapter_JsPullTest::main();
  88. }