This repository was archived by the owner on May 16, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 814
Fixes #374 - Implement Zend_Pdf::getJavascript() and Zend_Pdf::setJavascript() #375
Merged
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,159 @@ | ||
| <?php | ||
|
|
||
| /** | ||
| * Zend Framework | ||
| * | ||
| * LICENSE | ||
| * | ||
| * This source file is subject to the new BSD license that is bundled | ||
| * with this package in the file LICENSE.txt. | ||
| * It is also available through the world-wide-web at this URL: | ||
| * http://framework.zend.com/license/new-bsd | ||
| * If you did not receive a copy of the license and are unable to | ||
| * obtain it through the world-wide-web, please send an email | ||
| * to [email protected] so we can send you a copy immediately. | ||
| * | ||
| * @category Zend | ||
| * @package Zend_Pdf | ||
| * @subpackage UnitTests | ||
| * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) | ||
| * @license http://framework.zend.com/license/new-bsd New BSD License | ||
| * @version $Id$ | ||
| */ | ||
| /** | ||
| * @see Zend_Pdf | ||
| */ | ||
| require_once 'Zend/Pdf.php'; | ||
| /** | ||
| * @see Zend_Pdf_Exception | ||
| */ | ||
| require_once 'Zend/Pdf/Exception.php'; | ||
|
|
||
| /** | ||
| * @category Zend | ||
| * @package Zend_Pdf | ||
| * @subpackage UnitTests | ||
| * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) | ||
| * @license http://framework.zend.com/license/new-bsd New BSD License | ||
| * @group Zend_Pdf | ||
| */ | ||
| class Zend_PdfTest extends PHPUnit_Framework_TestCase | ||
| { | ||
|
|
||
| public function testGetJavasriptNull() | ||
| { | ||
| // getting JavaScript without setting it returns NULL | ||
| $pdf = new Zend_Pdf(); | ||
| $this->assertNull($pdf->getJavaScript()); | ||
| } | ||
|
|
||
| public function testSetAndGetJavasriptArray() | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And here. |
||
| { | ||
| // getting JavaScript after setting it returns array | ||
| $pdf = new Zend_Pdf(); | ||
| $pdf->setJavascript('print();'); | ||
| $this->assertTrue(is_array($pdf->getJavaScript())); | ||
| } | ||
|
|
||
| public function testSetJavascriptString() | ||
| { | ||
| // setting string value is possible | ||
| $pdf = new Zend_Pdf(); | ||
| $javaScriptString = 'print();'; | ||
| $pdf->setJavaScript($javaScriptString); | ||
| $javaScript = $pdf->getJavaScript(); | ||
| $this->assertEquals($javaScriptString, $javaScript[0]); | ||
| } | ||
|
|
||
| public function testSetJavascriptArray() | ||
| { | ||
| // setting string value is possible | ||
| $pdf = new Zend_Pdf(); | ||
| $javaScriptArray = array('print();', 'alert();'); | ||
| $pdf->setJavaScript($javaScriptArray); | ||
| $this->assertEquals($javaScriptArray, $pdf->getJavaScript()); | ||
| } | ||
|
|
||
| public function testResetJavascript() | ||
| { | ||
| // reset removes the added JavaScript | ||
| $pdf = new Zend_Pdf(); | ||
| $pdf->setJavaScript('print();'); | ||
| $pdf->resetJavaScript(); | ||
| $this->assertNull($pdf->getJavaScript()); | ||
| } | ||
|
|
||
| public function testAddJavascript() | ||
| { | ||
| // adding JavaScript appends previously added JavaScript | ||
| $pdf = new Zend_Pdf(); | ||
| $javaScriptArray = array('print();', 'alert();'); | ||
| $pdf->addJavaScript($javaScriptArray[0]); | ||
| $pdf->addJavaScript($javaScriptArray[1]); | ||
| $this->assertEquals($javaScriptArray, $pdf->getJavaScript()); | ||
| } | ||
|
|
||
| public function testSetJavascriptEmptyString() | ||
| { | ||
| // setting empty JavaScript string throws exception | ||
| $pdf = new Zend_Pdf(); | ||
| try { | ||
| $pdf->setJavaScript(''); | ||
| $this->fail('Expected exception when trying to set empty string.'); | ||
| } catch (Zend_Pdf_Exception $e) { | ||
| $this->assertContains('JavaScript must be a non empty string or array of strings', $e->getMessage()); | ||
| } | ||
| } | ||
|
|
||
| public function testSetJavascriptEmptyArray() | ||
| { | ||
| // setting empty JavaScript string throws exception | ||
| $pdf = new Zend_Pdf(); | ||
| try { | ||
| $pdf->setJavaScript(array()); | ||
| $this->fail('Expected exception when trying to set empty array.'); | ||
| } catch (Zend_Pdf_Exception $e) { | ||
| $this->assertContains('JavaScript must be a non empty string or array of strings', $e->getMessage()); | ||
| } | ||
| } | ||
|
|
||
| public function testSetAndSaveLoadAndGetJavascript() | ||
| { | ||
| $tempFile = tempnam(sys_get_temp_dir(), 'PdfUnitFile'); | ||
| $javaScript = array('print();', 'alert();'); | ||
|
|
||
| $pdf = new Zend_Pdf(); | ||
| $pdf->setJavaScript($javaScript); | ||
| $pdf->save($tempFile); | ||
| unset($pdf); | ||
|
|
||
| $pdf = Zend_Pdf::load($tempFile); | ||
| unlink($tempFile); | ||
|
|
||
| $this->assertEquals($javaScript, $pdf->getJavaScript()); | ||
| } | ||
|
|
||
| public function testSetAndSaveLoadAndResetAndSaveLoadAndGetJavascript() | ||
| { | ||
| $tempFile = tempnam(sys_get_temp_dir(), 'PdfUnitFile'); | ||
| $javaScript = array('print();', 'alert();'); | ||
|
|
||
| $pdf = new Zend_Pdf(); | ||
| $pdf->setJavaScript($javaScript); | ||
| $pdf->save($tempFile); | ||
| unset($pdf); | ||
|
|
||
| $pdf = Zend_Pdf::load($tempFile); | ||
| unlink($tempFile); | ||
|
|
||
| $pdf->resetJavaScript(); | ||
| $pdf->save($tempFile); | ||
| unset($pdf); | ||
|
|
||
| $pdf = Zend_Pdf::load($tempFile); | ||
| unlink($tempFile); | ||
|
|
||
| $this->assertNull($pdf->getJavaScript()); | ||
| } | ||
|
|
||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo: should be testGetJavaScript.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had an illusion that Zend_Pdf has methods like
Javascriptand notJavaScript. I must have mixed it up with another library. I'll fix that asap.