1<?php 2/** 3 * Unit tests for HTML_QuickForm2 package 4 * 5 * PHP version 5 6 * 7 * LICENSE 8 * 9 * This source file is subject to BSD 3-Clause License that is bundled 10 * with this package in the file LICENSE and available at the URL 11 * https://raw.githubusercontent.com/pear/HTML_QuickForm2/trunk/docs/LICENSE 12 * 13 * @category HTML 14 * @package HTML_QuickForm2 15 * @author Alexey Borzov <avb@php.net> 16 * @author Bertrand Mansion <golgote@mamasam.com> 17 * @copyright 2006-2021 Alexey Borzov <avb@php.net>, Bertrand Mansion <golgote@mamasam.com> 18 * @license https://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License 19 * @link https://pear.php.net/package/HTML_QuickForm2 20 */ 21 22/** Sets up includes */ 23require_once dirname(dirname(__DIR__)) . '/TestHelper.php'; 24 25/** 26 * Unit test for HTML_QuickForm2_Element_Select class 27 */ 28class HTML_QuickForm2_Element_ScriptTest extends PHPUnit_Framework_TestCase 29{ 30 public function setUp() 31 { 32 HTML_Common2::setOption(HTML_QuickForm2_Node::OPTION_NONCE, null); 33 } 34 35 public function testInlineScriptNonce() 36 { 37 $element = new HTML_QuickForm2_Element_Script(); 38 $element->setContent('Some javascript'); 39 40 $script = $element->__toString(); 41 $this->assertNotRegExp('/<script[^>]*nonce/', $script); 42 43 HTML_Common2::setOption( 44 HTML_QuickForm2_Node::OPTION_NONCE, 45 $nonce = base64_encode('HTML_QuickForm2_nonce' . microtime()) 46 ); 47 $script = $element->__toString(); 48 $this->assertRegExp('/<script[^>]*nonce="' . $nonce . '"/', $script); 49 } 50}