예제 #1
0
 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());
 }
예제 #2
0
 /**
  * Sets the error message output by the rule
  *
  * Required rules cannot have an empty error message as that may allow
  * validation to succeed even if the element is empty, and that will make
  * visual difference ("* denotes required field") bogus.
  *
  * @param    string                  Error message to display if validation fails
  * @return   HTML_QuickForm2_Rule
  * @throws   HTML_QuickForm2_InvalidArgumentException
  */
 public function setMessage($message)
 {
     if (!strlen($message)) {
         throw new HTML_QuickForm2_InvalidArgumentException('"required" rule cannot have an empty error message');
     }
     return parent::setMessage($message);
 }
 public function testContainerValidationTriggers()
 {
     $mockContainer = $this->getMock('HTML_QuickForm2_Container', array('getType', 'setValue', '__toString'));
     $foo = $mockContainer->addElement('text', 'foo', array('id' => 'foo'));
     $bar = $mockContainer->addElement('text', 'bar', array('id' => 'bar'));
     $nonEmpty = new HTML_QuickForm2_Rule_Nonempty($mockContainer, 'an error');
     $this->assertContains('["foo","bar"]', $nonEmpty->getJavascript());
 }