public function testFormSimple()
 {
     /**
      * @type DomainWorkflow $workflow;
      * @type Domains $domainObj
      */
     $workflow = $this->container->get('syseleven.pdns.workflow.domains');
     $domainObj = $workflow->get(1);
     $recordObj = new Records();
     $recordObj->setDomain($domainObj);
     $recordObj->setName('www.' . $domainObj->getName());
     $recordObj->setType('A');
     $recordObj->setContent('1.1.1.1');
     /**
      * @type FormBuilder $form
      */
     $form = $this->container->get('form.factory')->create(new RecordsType(), $recordObj);
     $requestData = array('content' => '1.1.1.2');
     $form->submit($requestData, false);
     $this->assertEquals('1.1.1.2', $recordObj->getContent());
 }
 /**
  * @covers SysEleven\PowerDnsBundle\Validator\Constraints\RecordValidator::_validateAaaa
  * @covers SysEleven\PowerDnsBundle\Validator\Constraints\RecordValidator::_checkHostname
  */
 public function testValidateAaaa()
 {
     /**
      * @type DomainWorkflow $workflow
      */
     $workflow = $this->container->get('syseleven.pdns.workflow.domains');
     /**
      * @type Domains $domainObj
      */
     $domainObj = $workflow->getRepository()->findOneBy(array());
     $recordObj = new Records();
     $recordObj->setDomain($domainObj);
     $recordObj->setName('bogus___.');
     $recordObj->setType('AAAA');
     $recordObj->setContent('name');
     $validator = $this->container->get('validator');
     $errors = $validator->validate($recordObj);
     $this->assertCount(2, $errors);
     $recordObj->setName('a+.' . $domainObj->getName());
     $recordObj->setContent('::1');
     $validator = $this->container->get('validator');
     $errors = $validator->validate($recordObj);
     $this->assertCount(1, $errors);
 }
 /**
  * Creates a new SOA record for the given domain, see documentation for details
  *
  * @ApiDoc(
  *      description="Creates a new soa record for the given domain",
  *      input="SysEleven\PowerDnsBundle\Form\SoaType",
  *      requirements={
  *          {"name" = "domain", "dataType" = "integer", "requirement" = "\d+", "description" = "Id of the domain"},
  *          {"name" = "_format", "dataType" = "string", "pattern" = "(json|xml)", "description" = "Output Format"}
  *      },
  *
  *      output={
  *          "class"="SysEleven\PowerDnsBundle\Entity\Records",
  *          "groups"="details"
  *      }
  * )
  *
  * @param Request $request
  * @param int     $domain
  *
  * @return \Symfony\Component\HttpFoundation\Response
  * @Rest\Post("soa.{_format}", name="syseleven_powerdns_api_domains_soa_create")
  */
 public function soaCreateAction(Request $request, $domain)
 {
     try {
         /**
          * @type DomainWorkflow $workflow;
          */
         $workflow = $this->get('syseleven.pdns.workflow.domains');
         /**
          * @type Domains $domainObj
          */
         $domainObj = $workflow->get($domain);
         if ($soaRecord = $domainObj->getSoa()) {
             $data = array('status' => 'error', 'errors' => array('soa' => 'Already Exists'));
             return $this->returnView($data, 200, array(), array('details'));
         }
         $soa = new Soa();
         $form = $this->createForm(new SoaType(), $soa, array('method' => 'POST'));
         $form->submit($request, false);
         if (0 == $soa->getSerial()) {
             $soa->setSerial(strtotime('now'));
         }
         $recordObj = new Records();
         $recordObj->setName($domainObj->getName());
         $recordObj->setDomain($domainObj);
         $recordObj->setContent($soa);
         $recordObj->setType('SOA');
         /**
          * @type RecordWorkflow $recordWorkflow;
          */
         $recordWorkflow = $this->get('syseleven.pdns.workflow.records');
         $recordObj = $recordWorkflow->create($recordObj);
         $recordWorkflow->createHistory($recordObj);
         return $this->redirect($this->generateUrl('syseleven_powerdns_api_domains_soa', array('domain' => $domainObj->getId(), '_format' => $request->getRequestFormat())));
     } catch (NotFoundException $nf) {
         $data = array('status' => 'error', 'errors' => array('domain' => 'Not found'));
     } catch (ValidationException $ve) {
         $data = array('status' => 'error', 'errors' => Tools::prepareSymfonyErrorArray($ve->getErrors()));
     }
     return $this->returnView($data, 200, array(), array('details'));
 }
 public function loadFooBar_de(ObjectManager $manager)
 {
     /**
      * @type RecordWorkflow $recordWorkflow
      */
     $recordWorkflow = $this->container->get('syseleven.pdns.workflow.records');
     $domainObj = new Domains();
     $domainObj->setName('foobar.de');
     $domainObj->setType('NATIVE');
     $manager->persist($domainObj);
     $manager->flush();
     $soa = new Records();
     $soa->setName('foobar.de');
     $soa->setType('SOA');
     $soa->setContent('  1375872531 10800 604800 3600 ');
     $soa->setTtl(3600);
     $soa->setChangeDate(strtotime('now'));
     $soa->setManaged(1);
     $soa->setDomain($domainObj);
     $recordWorkflow->create($soa);
     $domainObj->addRecord($soa);
     $recordWorkflow->createHistory($soa, 'CREATE');
     $ns1 = new Records();
     $ns1->setName('foobar.de');
     $ns1->setContent('ns1.ns.de');
     $ns1->setPrio(10);
     $ns1->setTtl(3600);
     $ns1->setType('NS');
     $ns1->setDomain($domainObj);
     $recordWorkflow->create($ns1);
     $ns2 = new Records();
     $ns2->setName('foobar.de');
     $ns2->setContent('ns2.ns.de');
     $ns2->setPrio(20);
     $ns2->setTtl(3600);
     $ns2->setType('NS');
     $ns2->setDomain($domainObj);
     $recordWorkflow->create($ns2);
     $mx = new Records();
     $mx->setName('foobar.de');
     $mx->setContent('mail.foobar.de');
     $mx->setPrio(20);
     $mx->setTtl(3600);
     $mx->setType('MX');
     $mx->setDomain($domainObj);
     $recordWorkflow->create($mx);
     $www = new Records();
     $www->setName('www.foobar.de');
     $www->setType('A');
     $www->setContent('2.1.1.1');
     $www->setDomain($domainObj);
     $recordWorkflow->create($www);
     $www = new Records();
     $www->setName('www2.foobar.de');
     $www->setType('CNAME');
     $www->setContent('www.foobar.de');
     $www->setDomain($domainObj);
     $recordWorkflow->create($www);
 }
 /**
  * Retransforms the content to a soa object if applicable
  */
 public function postUpdate(Records $record, LifecycleEventArgs $event)
 {
     if ($record->getType() == 'SOA') {
         $transformer = new SoaTransformer();
         $record->setContent($transformer->transform($record->getContent()));
     }
 }
 /**
  * Creates a new Soa Entry for the class
  *
  * @param Domains $domainObj
  * @return Records
  */
 public function createSoa(Domains $domainObj)
 {
     if ($soa = $domainObj->getSoa()) {
         $this->updateSoa($domainObj);
     }
     $soaDefaults = new Soa($this->getSoaDefaults());
     $soa = new Records();
     $soa->setName($domainObj->getName());
     $soa->setType('SOA');
     $soa->setContent($soaDefaults);
     $soa->setDomain($domainObj);
     $soa->setTtl($soaDefaults->getDefaultTtl());
     $this->getDatabase()->persist($soa);
     $this->getDatabase()->flush();
     $domainObj->addRecord($soa);
     return $soa;
 }
 public function testCreate()
 {
     /**
      * @type Domains $domainObj
      */
     $domainObj = $this->container->get('syseleven.pdns.workflow.domains')->getRepository()->findOneBy(array('type' => 'NATIVE'));
     $serial = $domainObj->getSerial();
     sleep(4);
     $recordObj = new Records();
     $recordObj->setName('www.' . $domainObj->getName());
     $recordObj->setType('A');
     $recordObj->setContent('1.1.1.9');
     $recordObj->setDomain($domainObj);
     $recordObj = $this->workflow->create($recordObj);
     $this->assertNotEmpty($recordObj->getId());
     $this->assertNotEquals($serial, $domainObj->getSerial());
     return $recordObj->getId();
 }