JsPushTest.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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_jsPushTest::main() if this source file is executed directly.
  23. if (!defined("PHPUnit_MAIN_METHOD")) {
  24. define("PHPUnit_MAIN_METHOD", "Zend_ProgressBar_Adapter_jsPushTest::main");
  25. }
  26. /**
  27. * Zend_ProgressBar_Adapter_JsPush
  28. */
  29. require_once 'Zend/ProgressBar/Adapter/JsPush.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_jsPushTest 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_jsPushTest");
  48. $result = PHPUnit_TextUI_TestRunner::run($suite);
  49. }
  50. public function testJson()
  51. {
  52. $result = array();
  53. $adapter = new Zend_ProgressBar_Adapter_jsPush_Stub(array('finishMethodName' => 'Zend_ProgressBar_Finish'));
  54. $adapter->notify(0, 2, 0.5, 1, 1, 'status');
  55. $output = $adapter->getLastOutput();
  56. $matches = preg_match('#<script type="text/javascript">parent.Zend_ProgressBar_Update\((.*?)\);</script>#', $output, $result);
  57. $this->assertEquals(1, $matches);
  58. $data = json_decode($result[1], true);
  59. $this->assertEquals(0, $data['current']);
  60. $this->assertEquals(2, $data['max']);
  61. $this->assertEquals(50, $data['percent']);
  62. $this->assertEquals(1, $data['timeTaken']);
  63. $this->assertEquals(1, $data['timeRemaining']);
  64. $this->assertEquals('status', $data['text']);
  65. $adapter->finish();
  66. $output = $adapter->getLastOutput();
  67. $matches = preg_match('#<script type="text/javascript">parent.Zend_ProgressBar_Finish\(\);</script>#', $output, $result);
  68. $this->assertEquals(1, $matches);
  69. }
  70. }
  71. class Zend_ProgressBar_Adapter_jsPush_Stub extends Zend_ProgressBar_Adapter_jsPush
  72. {
  73. protected $_lastOutput = null;
  74. public function getLastOutput()
  75. {
  76. return $this->_lastOutput;
  77. }
  78. protected function _outputData($data)
  79. {
  80. $this->_lastOutput = $data;
  81. }
  82. }
  83. // Call Zend_ProgressBar_Adapter_jsPushTest::main() if this source file is executed directly.
  84. if (PHPUnit_MAIN_METHOD == "Zend_ProgressBar_Adapter_jsPushTest::main") {
  85. Zend_ProgressBar_Adapter_jsPushTest::main();
  86. }