Skip to content

Commit

Permalink
make addDisclose usefuller (fixes #1)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gunter Grodotzki committed Apr 21, 2015
1 parent 1a0ea77 commit 98987cf
Show file tree
Hide file tree
Showing 7 changed files with 274 additions and 7 deletions.
31 changes: 31 additions & 0 deletions examples/create_contact_disclose.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

// debug
error_reporting(E_ALL);
ini_set('display_errors', true);

chdir(__DIR__);

require '../src/AfriCC/autoload.php';

use AfriCC\EPP\Frame\Command\Create\Contact as CreateContact;

$frame = new CreateContact;
$frame->skipInt();
$frame->setId('CONTACT1');
$frame->setName('Günter Grodotzki');
$frame->setOrganization('weheartwebsites UG');
$frame->addStreet('Rönskenstraße 23');
$frame->addStreet('Around the Corner');
$frame->setCity('Cape Town');
$frame->setProvince('WC');
$frame->setPostalCode('8001');
$frame->setCountryCode('ZA');
$frame->setVoice('+27.844784784');
$frame->setFax('+1.844784784');
$frame->setEmail('[email protected]');
$auth = $frame->setAuthInfo();
$frame->addDisclose('voice', 1);
$frame->addDisclose('email', 0);
echo $frame;
var_dump($auth);
4 changes: 2 additions & 2 deletions examples/update_contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@

require '../src/AfriCC/autoload.php';

use AfriCC\EPP\Frame\Command\Update\Contact as ContactUpdate;
use AfriCC\EPP\Frame\Command\Update\Contact as UpdateContact;

$frame = new ContactUpdate;
$frame = new UpdateContact;
$frame->setId('C0054');
$frame->addCity('Voerde');
$frame->addAddStreet('Long St. 14');
Expand Down
24 changes: 24 additions & 0 deletions examples/update_contact_disclose.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

// debug
error_reporting(E_ALL);
ini_set('display_errors', true);

chdir(__DIR__);

require '../src/AfriCC/autoload.php';

use AfriCC\EPP\Frame\Command\Update\Contact as UpdateContact;

$frame = new UpdateContact;
$frame->setId('C0054');
$frame->addCity('Voerde');
$frame->addAddStreet('Long St. 14');
$frame->addAddStreet('CBD');
$frame->changeAddStreet('Long St. 15');
$frame->changeCity('Cape Town');
$frame->removeAddStreet('Long St. 16');
$frame->removeCity('Durban');
$frame->changeAddDisclose('voice', 1);
$frame->changeAddDisclose('name[@type=\'int\']', 1);
echo $frame;
4 changes: 2 additions & 2 deletions src/AfriCC/EPP/Frame/Command/Create/Contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ public function setAuthInfo($pw = null)
return $this->appendAuthInfo('contact:authInfo/contact:pw', $pw);
}

public function addDisclose($value)
public function addDisclose($value, $flag = 0)
{
$this->appendDisclose('contact:disclose[@flag=\'0\']/contact:' . $value);
$this->appendDisclose(sprintf('contact:disclose[@flag=\'%d\']/contact:%s', (int) $flag, $value));
}
}
4 changes: 2 additions & 2 deletions src/AfriCC/EPP/Frame/Command/Update/Contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ private function setAuthInfo($mode, $pw = null)
return $this->appendAuthInfo(sprintf('contact:%s/contact:authInfo/contact:pw', $mode), $pw);
}

private function addDisclose($mode, $value)
private function addDisclose($mode, $value, $flag = 0)
{
$this->appendDisclose(sprintf('contact:%s/contact:disclose[@flag=\'0\']/contact:' . $value, $mode));
$this->appendDisclose(sprintf('contact:%s/contact:disclose[@flag=\'%d\']/contact:%s', $mode, $flag, $value));
}

public function __call($name, $arguments)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use AfriCC\EPP\Frame\Command\Create\Contact as CreateContact;

class ContactTest extends \PHPUnit_Framework_TestCase
class ContactCreateTest extends \PHPUnit_Framework_TestCase
{
public function testContactCreate()
{
Expand Down Expand Up @@ -130,4 +130,62 @@ public function testContactCreateSkipInt()
</epp>'
);
}

public function testContactCreateDisclose()
{
$frame = new CreateContact;
$frame->skipInt();
$frame->setId('CONTACT1');
$frame->setName('Günter Grodotzki');
$frame->setOrganization('weheartwebsites UG');
$frame->addStreet('Rönskenstraße 23');
$frame->addStreet('Around the Corner');
$frame->setCity('Cape Town');
$frame->setProvince('WC');
$frame->setPostalCode('8001');
$frame->setCountryCode('ZA');
$frame->setVoice('+27.844784784');
$frame->setFax('+1.844784784');
$frame->setEmail('[email protected]');
$auth = $frame->setAuthInfo();
$frame->addDisclose('voice', 1);
$frame->addDisclose('email', 0);

$this->assertXmlStringEqualsXmlString((string) $frame,
'<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
<command>
<create>
<contact:create xmlns:contact="urn:ietf:params:xml:ns:contact-1.0">
<contact:id>CONTACT1</contact:id>
<contact:postalInfo type="loc">
<contact:name>Günter Grodotzki</contact:name>
<contact:org>weheartwebsites UG</contact:org>
<contact:addr>
<contact:street>Rönskenstraße 23</contact:street>
<contact:street>Around the Corner</contact:street>
<contact:city>Cape Town</contact:city>
<contact:sp>WC</contact:sp>
<contact:pc>8001</contact:pc>
<contact:cc>ZA</contact:cc>
</contact:addr>
</contact:postalInfo>
<contact:voice>+27.844784784</contact:voice>
<contact:fax>+1.844784784</contact:fax>
<contact:email>[email protected]</contact:email>
<contact:authInfo>
<contact:pw>' . $auth . '</contact:pw>
</contact:authInfo>
<contact:disclose flag="1">
<contact:voice/>
</contact:disclose>
<contact:disclose flag="0">
<contact:email/>
</contact:disclose>
</contact:create>
</create>
</command>
</epp>'
);
}
}
154 changes: 154 additions & 0 deletions tests/AfriCC/EPP/Test/Frame/Command/Update/ContactUpdateTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
<?php

namespace AfriCC\EPP\Frame\Command;

use AfriCC\EPP\Frame\Command\Update\Contact as UpdateContact;

class ContactUpdateTest extends \PHPUnit_Framework_TestCase
{
public function testContactUpdate()
{
$frame = new UpdateContact;
$frame->setId('C0054');
$frame->addCity('Voerde');
$frame->addAddStreet('Long St. 14');
$frame->addAddStreet('CBD');
$frame->changeAddStreet('Long St. 15');
$frame->changeCity('Cape Town');
$frame->removeAddStreet('Long St. 16');
$frame->removeCity('Durban');

$this->assertXmlStringEqualsXmlString((string) $frame,
'<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
<command>
<update>
<contact:update xmlns:contact="urn:ietf:params:xml:ns:contact-1.0">
<contact:id>C0054</contact:id>
<contact:add>
<contact:postalInfo type="loc">
<contact:addr>
<contact:city>Voerde</contact:city>
<contact:street>Long St. 14</contact:street>
<contact:street>CBD</contact:street>
</contact:addr>
</contact:postalInfo>
<contact:postalInfo type="int">
<contact:addr>
<contact:city>Voerde</contact:city>
<contact:street>Long St. 14</contact:street>
<contact:street>CBD</contact:street>
</contact:addr>
</contact:postalInfo>
</contact:add>
<contact:chg>
<contact:postalInfo type="loc">
<contact:addr>
<contact:street>Long St. 15</contact:street>
<contact:city>Cape Town</contact:city>
</contact:addr>
</contact:postalInfo>
<contact:postalInfo type="int">
<contact:addr>
<contact:street>Long St. 15</contact:street>
<contact:city>Cape Town</contact:city>
</contact:addr>
</contact:postalInfo>
</contact:chg>
<contact:rem>
<contact:postalInfo type="loc">
<contact:addr>
<contact:street>Long St. 16</contact:street>
<contact:city>Durban</contact:city>
</contact:addr>
</contact:postalInfo>
<contact:postalInfo type="int">
<contact:addr>
<contact:street>Long St. 16</contact:street>
<contact:city>Durban</contact:city>
</contact:addr>
</contact:postalInfo>
</contact:rem>
</contact:update>
</update>
</command>
</epp>'
);
}

public function testContactUpdateDisclose()
{
$frame = new UpdateContact;
$frame->setId('C0054');
$frame->addCity('Voerde');
$frame->addAddStreet('Long St. 14');
$frame->addAddStreet('CBD');
$frame->changeAddStreet('Long St. 15');
$frame->changeCity('Cape Town');
$frame->removeAddStreet('Long St. 16');
$frame->removeCity('Durban');
$frame->changeAddDisclose('voice', 1);
$frame->changeAddDisclose('name[@type=\'int\']', 1);

$this->assertXmlStringEqualsXmlString((string) $frame,
'<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
<command>
<update>
<contact:update xmlns:contact="urn:ietf:params:xml:ns:contact-1.0">
<contact:id>C0054</contact:id>
<contact:add>
<contact:postalInfo type="loc">
<contact:addr>
<contact:city>Voerde</contact:city>
<contact:street>Long St. 14</contact:street>
<contact:street>CBD</contact:street>
</contact:addr>
</contact:postalInfo>
<contact:postalInfo type="int">
<contact:addr>
<contact:city>Voerde</contact:city>
<contact:street>Long St. 14</contact:street>
<contact:street>CBD</contact:street>
</contact:addr>
</contact:postalInfo>
</contact:add>
<contact:chg>
<contact:postalInfo type="loc">
<contact:addr>
<contact:street>Long St. 15</contact:street>
<contact:city>Cape Town</contact:city>
</contact:addr>
</contact:postalInfo>
<contact:postalInfo type="int">
<contact:addr>
<contact:street>Long St. 15</contact:street>
<contact:city>Cape Town</contact:city>
</contact:addr>
</contact:postalInfo>
<contact:disclose flag="1">
<contact:voice/>
<contact:name type="int"/>
</contact:disclose>
</contact:chg>
<contact:rem>
<contact:postalInfo type="loc">
<contact:addr>
<contact:street>Long St. 16</contact:street>
<contact:city>Durban</contact:city>
</contact:addr>
</contact:postalInfo>
<contact:postalInfo type="int">
<contact:addr>
<contact:street>Long St. 16</contact:street>
<contact:city>Durban</contact:city>
</contact:addr>
</contact:postalInfo>
</contact:rem>
</contact:update>
</update>
</command>
</epp>'
);
}
}

0 comments on commit 98987cf

Please sign in to comment.