/**
  * @see Form::createElements()
  */
 public function createElements(array $formData)
 {
     $this->addElement('hidden', 'type', array('required' => true, 'value' => 'ldap'));
     if (isset($formData['skip_validation']) && $formData['skip_validation']) {
         $this->addSkipValidationCheckbox();
     } else {
         $this->addElement('hidden', 'skip_validation', array('required' => true, 'value' => 0));
     }
     $resourceForm = new LdapResourceForm();
     $this->addElements($resourceForm->createElements($formData)->getElements());
     $this->getElement('name')->setValue('icingaweb_ldap');
 }
 /**
  * @runInSeparateProcess
  * @preserveGlobalState disabled
  */
 public function testInvalidLdapResourceIsNotValid()
 {
     $this->setUpResourceFactoryMock(Mockery::mock()->shouldReceive('bind')->andThrow('\\Exception')->getMock());
     // Passing array(null) is required to make Mockery call the constructor...
     $form = Mockery::mock('Icinga\\Forms\\Config\\Resource\\LdapResourceForm[getView]', array(null));
     $form->shouldReceive('getView->escape')->with(Mockery::type('string'))->andReturnUsing(function ($s) {
         return $s;
     });
     $form->setTokenDisabled();
     $this->assertFalse(LdapResourceForm::isValidResource($form->create()), 'ResourceForm claims that an invalid ldap resource is valid');
 }
 /**
  * Validate the given form data and check whether a BIND-request is successful
  *
  * @param   array   $data   The data to validate
  *
  * @return  bool
  */
 public function isValid($data)
 {
     if (false === parent::isValid($data)) {
         return false;
     }
     if (false === isset($data['skip_validation']) || $data['skip_validation'] == 0) {
         if (false === LdapResourceForm::isValidResource($this)) {
             $this->addSkipValidationCheckbox();
             return false;
         }
     }
     return true;
 }