function testValidateInputFileElement() { $mockValid = $this->getMock('HTML_QuickForm2_Element_InputFile', array('getValue')); $mockValid->expects($this->once())->method('getValue')->will($this->returnValue(array('name' => 'goodfile.php', 'type' => 'application/octet-stream', 'tmp_name' => '/tmp/foobar', 'error' => UPLOAD_ERR_OK, 'size' => 1234))); $rule = new HTML_QuickForm2_Rule_Nonempty($mockValid, 'an error'); $this->assertTrue($rule->validate()); $this->assertEquals('', $mockValid->getError()); $mockInvalid = $this->getMock('HTML_QuickForm2_Element_InputFile', array('getValue')); $mockInvalid->expects($this->once())->method('getValue')->will($this->returnValue(array('name' => '', 'type' => '', 'tmp_name' => '', 'error' => UPLOAD_ERR_NO_FILE, 'size' => 0))); $rule2 = new HTML_QuickForm2_Rule_Nonempty($mockInvalid, 'an error'); $this->assertFalse($rule2->validate()); $this->assertEquals('an error', $mockInvalid->getError()); }
function testValidateNestedContainer() { $mockOuter = $this->getMock('HTML_QuickForm2_Container', array('getType', 'setValue', '__toString')); $mockInner = $this->getMock('HTML_QuickForm2_Container', array('getType', 'setValue', '__toString')); $foo = $mockOuter->addElement('text', 'foo[idx]')->setValue(''); $bar = $mockInner->addElement('text', 'bar[idx]')->setValue('not empty'); $mockOuter->appendChild($mockInner); $nonEmpty = new HTML_QuickForm2_Rule_Nonempty($mockOuter, 'an error'); $this->assertTrue($nonEmpty->validate()); $nonEmpty->setConfig(2); $this->assertFalse($nonEmpty->validate()); }