forked from spoon/library
/
SpoonFormHiddenTest.php
71 lines (60 loc) · 2.03 KB
/
SpoonFormHiddenTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
use PHPUnit\Framework\TestCase;
$includePath = dirname(dirname(dirname(dirname(__FILE__))));
set_include_path(get_include_path() . PATH_SEPARATOR . $includePath);
require_once 'spoon/spoon.php';
class SpoonFormHiddenTest extends TestCase
{
/**
* @var SpoonForm
*/
protected $frm;
/**
* @var SpoonFormHidden
*/
protected $hidHidden;
public function setup(): void
{
$this->frm = new SpoonForm('hiddenfield');
$this->hidHidden = new SpoonFormHidden('hidden', 'I am the default value');
$this->frm->add($this->hidHidden);
}
public function testAttributes()
{
$this->hidHidden->setAttribute('rel', 'bauffman.jpg');
$this->assertEquals('bauffman.jpg', $this->hidHidden->getAttribute('rel'));
$this->hidHidden->setAttributes(array('id' => 'specialID'));
$this->assertEquals(array('id' => 'specialID', 'name' => 'hidden', 'rel' => 'bauffman.jpg'), $this->hidHidden->getAttributes());
}
public function testIsFilled()
{
$this->assertEquals(false, $this->hidHidden->isFilled());
$_POST['hidden'] = 'I am not empty';
$this->assertTrue($this->hidHidden->isFilled());
$_POST['hidden'] = array('foo', 'bar');
$this->assertTrue($this->hidHidden->isFilled());
}
public function testGetValue()
{
$_POST['form'] = 'hiddenfield';
$_POST['hidden'] = 'But I am le tired';
$this->assertEquals($_POST['hidden'], $this->hidHidden->getValue());
$_POST['hidden'] = array('foo', 'bar');
$this->assertEquals('Array', $this->hidHidden->getValue());
}
public function testParse()
{
$_POST['form'] = 'hiddenfield';
$_POST['hidden'] = 'But I am le tired';
$this->assertEquals(
'<input type="hidden" value="But I am le tired" id="hidden" name="hidden" />',
$this->hidHidden->parse()
);
// Make sure we encode XSS payloads
$_POST['hidden'] = 'But I am le tired\'"()%26%25<yes><ScRiPt%20>alert(1)</ScRiPt>';
$this->assertEquals(
'<input type="hidden" value="But I am le tired'"()%26%25<yes><ScRiPt%20>alert(1)</ScRiPt>" id="hidden" name="hidden" />',
$this->hidHidden->parse()
);
}
}