JsPullTest.php 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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-2015 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. * Zend_ProgressBar_Adapter_JsPull
  28. */
  29. require_once 'Zend/ProgressBar/Adapter/JsPull.php';
  30. /**
  31. * @category Zend
  32. * @package Zend_ProgressBar
  33. * @subpackage UnitTests
  34. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  35. * @license http://framework.zend.com/license/new-bsd New BSD License
  36. * @group Zend_ProgressBar
  37. */
  38. class Zend_ProgressBar_Adapter_JsPullTest extends PHPUnit_Framework_TestCase
  39. {
  40. /**
  41. * Runs the test methods of this class.
  42. *
  43. * @return void
  44. */
  45. public static function main()
  46. {
  47. $suite = new PHPUnit_Framework_TestSuite("Zend_ProgressBar_Adapter_JsPullTest");
  48. $result = PHPUnit_TextUI_TestRunner::run($suite);
  49. }
  50. public function testJson()
  51. {
  52. $adapter = new Zend_ProgressBar_Adapter_JsPull_Stub();
  53. $adapter->notify(0, 2, 0.5, 1, 1, 'status');
  54. $output = $adapter->getLastOutput();
  55. $data = json_decode($output, true);
  56. $this->assertEquals(0, $data['current']);
  57. $this->assertEquals(2, $data['max']);
  58. $this->assertEquals(50, $data['percent']);
  59. $this->assertEquals(1, $data['timeTaken']);
  60. $this->assertEquals(1, $data['timeRemaining']);
  61. $this->assertEquals('status', $data['text']);
  62. $this->assertFalse($data['finished']);
  63. $adapter->finish();
  64. $output = $adapter->getLastOutput();
  65. $data = json_decode($output, true);
  66. $this->assertTrue($data['finished']);
  67. }
  68. }
  69. class Zend_ProgressBar_Adapter_JsPull_Stub extends Zend_ProgressBar_Adapter_JsPull
  70. {
  71. protected $_lastOutput = null;
  72. public function getLastOutput()
  73. {
  74. return $this->_lastOutput;
  75. }
  76. protected function _outputData($data)
  77. {
  78. $this->_lastOutput = $data;
  79. }
  80. }
  81. // Call Zend_ProgressBar_Adapter_JsPullTest::main() if this source file is executed directly.
  82. if (PHPUnit_MAIN_METHOD == "Zend_ProgressBar_Adapter_JsPullTest::main") {
  83. Zend_ProgressBar_Adapter_JsPullTest::main();
  84. }