public function testFormInitialState()
 {
     // check the form properties
     foreach ($this->_formProperties as $propertyName => $propertyValue) {
         $this->assertEquals(true, $this->_form->hasAttribute($propertyName), "Form has no property {$propertyName} element");
         $this->assertEquals($propertyValue, $this->_form->getAttribute($propertyName), "Form property {$propertyName} doesn't match {$propertyValue}");
     }
     foreach ($this->_formFields as $fieldName => $properties) {
         $this->assertEquals(true, $this->_form->has($fieldName), "Form missing element '{$fieldName}'");
         foreach ($properties as $propertyName => $propertyValue) {
             switch ($propertyName) {
                 case 'type':
                     $this->assertEquals($propertyValue, $this->_form->get($fieldName)->getAttribute('type'), "field {$fieldName} should have been of type: " . $this->_form->get($fieldName)->getAttribute('type'));
                     break;
                 case 'value':
                     $this->assertEquals($propertyValue, $this->_form->get($fieldName)->getValue(), "field {$fieldName} should have value: " . $this->_form->get($fieldName)->getValue());
                     break;
                 case 'label':
                     $this->assertEquals($propertyValue, $this->_form->get($fieldName)->getLabel(), "field {$fieldName} should have label matching: " . $this->_form->get($fieldName)->getLabel());
                     break;
                 case 'placeholder':
                     $this->assertEquals($propertyValue, $this->_form->get($fieldName)->getAttribute('placeholder'), "field {$fieldName} should placeholder matching: {$propertyValue}");
                     break;
             }
         }
     }
 }
Example #2
0
 /**
  * @param array $completions
  * @param array $uninputs
  * @return $this
  * @throws ErrorException
  * @throws NoLocationException
  * @throws StateException
  * @throws \Exception
  */
 public function submit(array $completions, array $uninputs = [])
 {
     $this->form->setSimpleXMLForm($this->_source)->addCompletions($completions);
     foreach ($uninputs as $uninput) {
         $this->form->removeInput($uninput);
     }
     $method = 'get';
     $action = $this->crawler->getUrl();
     if ($this->form->hasAttribute('method')) {
         $method = $this->form->getAttribute('method');
     }
     if ($this->form->hasAttribute('action')) {
         $action = $this->form->getAttribute('action');
         if (isset($action[0])) {
             if ('/' === $action[0]) {
                 $action = $this->crawler->getBaseUrl() . $action;
             } else {
                 throw new \Exception("TODO: " . __FILE__ . " L" . __LINE__);
             }
         }
     }
     $this->crawler->submit($method, $action, $this->form->getData());
     return $this;
 }