Skip to content

Commit 3f0d1db

Browse files
Merge pull request #46 from lifeofguenter/fixes-20-optional-contact-types
Closes #20: implement skipLoc() + improve folder structure
2 parents 4504356 + 601ac4c commit 3f0d1db

File tree

13 files changed

+138
-70
lines changed

13 files changed

+138
-70
lines changed

README.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,9 @@ meaningful branchname, issue pull request with thus branchname)!
2727
Requirements
2828
------------
2929

30-
* PHP 5.4 or higher
31-
* libicu 4.8 or higher
32-
* php-intl 3 or higher
33-
* php-mcrypt
30+
* PHP 5.5+
31+
* php-ext-intl
32+
* php-ext-openssl
3433

3534

3635
Features
@@ -42,8 +41,8 @@ Features
4241
* high-level usage (Plug & Play)
4342
* simplified client (auto login/logout, auto inject clTRID)
4443
* SSL (+local-cert)
45-
* Xpath like setter to simplify the creation of complex XML structures
46-
* XML based responses for direct traversal via Xpath
44+
* XPath like setter to simplify the creation of complex XML structures
45+
* XML based responses for direct traversal via XPath
4746
* [RFC 5730](http://tools.ietf.org/html/rfc5730), [RFC 5731](http://tools.ietf.org/html/rfc5731), [RFC 5732](http://tools.ietf.org/html/rfc5732), [RFC 5733](http://tools.ietf.org/html/rfc5733), [RFC 5734](http://tools.ietf.org/html/rfc5734) & [RFC 3915](http://tools.ietf.org/html/rfc3915)
4847

4948

@@ -168,6 +167,7 @@ foreach ($data['chkData']['cd'] as $cd) {
168167
Future
169168
------
170169

170+
* objectspec on login needs to be smarter (no global/static object, auto-injecter)
171171
* stricter response parsing
172172
* stricter request validation
173173
* make it server capable (in conjunction with apache mod_epp)
@@ -193,3 +193,4 @@ License
193193
php-epp2 is released under the GPLv3 License. See the bundled
194194
[LICENSE](https://github.com/AfriCC/php-epp2/blob/master/LICENSE) file for
195195
details.
196+

phpunit.xml.dist

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212
>
1313
<testsuites>
1414
<testsuite name="AfriCC/EPP Test Suite">
15-
<directory>tests/AfriCC/EPP</directory>
15+
<directory suffix="Test.php">./tests</directory>
1616
</testsuite>
1717
</testsuites>
1818
<filter>
1919
<whitelist>
20-
<directory suffix=".php">src/AfriCC/EPP</directory>
20+
<directory suffix=".php">./src</directory>
2121
</whitelist>
2222
</filter>
2323
</phpunit>

src/AfriCC/EPP/ContactTrait.php

Lines changed: 35 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -16,44 +16,60 @@
1616
trait ContactTrait
1717
{
1818
/**
19-
* this was once needed as the conversion done by COZA was faulty
19+
* This was once needed as the conversion done by COZA was faulty
2020
* the bug has since been fixed but this remains to allow testing
21-
* set true to force ascii usage on type=loc (which should allow UTF8)
21+
* set true to force ascii usage on type=loc (which should allow UTF8).
2222
*
2323
* @var bool
2424
*/
2525
protected $force_ascii = false;
2626

2727
/**
28-
* set true to skip the generation of type=int (like .MX)
28+
* Set true to skip the generation of type=int.
2929
*
3030
* @var bool
3131
*/
3232
protected $skip_int = false;
3333

34+
/**
35+
* Set true to skip the generation of type=loc.
36+
*
37+
* @var bool
38+
*/
39+
protected $skip_loc = false;
40+
3441
abstract public function set($path = null, $value = null);
3542

3643
public function forceAscii()
3744
{
3845
$this->force_ascii = true;
3946
}
4047

48+
/**
49+
* Skip the generation of type=int.
50+
*/
4151
public function skipInt()
4252
{
4353
$this->skip_int = true;
4454
}
4555

56+
/**
57+
* Skip the generation of type=loc.
58+
*/
59+
public function skipLoc()
60+
{
61+
$this->skip_loc = true;
62+
}
63+
4664
public function appendId($path, $id)
4765
{
4866
$this->set($path, $id);
4967
}
5068

5169
public function appendName($path, $name)
5270
{
53-
if ($this->force_ascii) {
54-
$this->set(sprintf($path, 'loc'), Translit::transliterate($name));
55-
} else {
56-
$this->set(sprintf($path, 'loc'), $name);
71+
if (!$this->skip_loc) {
72+
$this->set(sprintf($path, 'loc'), $this->force_ascii ? Translit::transliterate($name) : $name);
5773
}
5874

5975
if (!$this->skip_int) {
@@ -63,10 +79,8 @@ public function appendName($path, $name)
6379

6480
public function appendOrganization($path, $org)
6581
{
66-
if ($this->force_ascii) {
67-
$this->set(sprintf($path, 'loc'), Translit::transliterate($org));
68-
} else {
69-
$this->set(sprintf($path, 'loc'), $org);
82+
if (!$this->skip_loc) {
83+
$this->set(sprintf($path, 'loc'), $this->force_ascii ? Translit::transliterate($org) : $org);
7084
}
7185

7286
if (!$this->skip_int) {
@@ -76,10 +90,8 @@ public function appendOrganization($path, $org)
7690

7791
public function appendStreet($path, $street)
7892
{
79-
if ($this->force_ascii) {
80-
$this->set(sprintf($path, 'loc'), Translit::transliterate($street));
81-
} else {
82-
$this->set(sprintf($path, 'loc'), $street);
93+
if (!$this->skip_loc) {
94+
$this->set(sprintf($path, 'loc'), $this->force_ascii ? Translit::transliterate($street) : $street);
8395
}
8496

8597
if (!$this->skip_int) {
@@ -89,10 +101,8 @@ public function appendStreet($path, $street)
89101

90102
public function appendCity($path, $city)
91103
{
92-
if ($this->force_ascii) {
93-
$this->set(sprintf($path, 'loc'), Translit::transliterate($city));
94-
} else {
95-
$this->set(sprintf($path, 'loc'), $city);
104+
if (!$this->skip_loc) {
105+
$this->set(sprintf($path, 'loc'), $this->force_ascii ? Translit::transliterate($city) : $city);
96106
}
97107

98108
if (!$this->skip_int) {
@@ -102,10 +112,8 @@ public function appendCity($path, $city)
102112

103113
public function appendProvince($path, $sp)
104114
{
105-
if ($this->force_ascii) {
106-
$this->set(sprintf($path, 'loc'), Translit::transliterate($sp));
107-
} else {
108-
$this->set(sprintf($path, 'loc'), $sp);
115+
if (!$this->skip_loc) {
116+
$this->set(sprintf($path, 'loc'), $this->force_ascii ? Translit::transliterate($sp) : $sp);
109117
}
110118

111119
if (!$this->skip_int) {
@@ -115,10 +123,8 @@ public function appendProvince($path, $sp)
115123

116124
public function appendPostalCode($path, $pc)
117125
{
118-
if ($this->force_ascii) {
119-
$this->set(sprintf($path, 'loc'), Translit::transliterate($pc));
120-
} else {
121-
$this->set(sprintf($path, 'loc'), $pc);
126+
if (!$this->skip_loc) {
127+
$this->set(sprintf($path, 'loc'), $this->force_ascii ? Translit::transliterate($pc) : $pc);
122128
}
123129

124130
if (!$this->skip_int) {
@@ -132,10 +138,8 @@ public function appendCountryCode($path, $cc)
132138
throw new Exception(sprintf('the country-code: \'%s\' is unknown', $cc));
133139
}
134140

135-
if ($this->force_ascii) {
136-
$this->set(sprintf($path, 'loc'), Translit::transliterate($cc));
137-
} else {
138-
$this->set(sprintf($path, 'loc'), $cc);
141+
if (!$this->skip_loc) {
142+
$this->set(sprintf($path, 'loc'), $this->force_ascii ? Translit::transliterate($cc) : $cc);
139143
}
140144

141145
if (!$this->skip_int) {

src/AfriCC/EPP/Frame/Command/Create/Contact.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212
namespace AfriCC\EPP\Frame\Command\Create;
1313

1414
use AfriCC\EPP\ContactTrait;
15-
use AfriCC\EPP\Frame\Command\Create as CreateCommand;
15+
use AfriCC\EPP\Frame\Command\Create;
1616

1717
/**
1818
* @see http://tools.ietf.org/html/rfc5733#section-3.2.1
1919
*/
20-
class Contact extends CreateCommand
20+
class Contact extends Create
2121
{
2222
use ContactTrait;
2323

tests/AfriCC/EPP/Test/Extension/NICMX/Restore/DomainTest.php renamed to tests/EPP/Extension/NICMX/Restore/DomainTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
<?php
22

3-
namespace AfriCC\EPP\Extension\NICMX\Restore;
3+
namespace AfriCC\Tests\EPP\Extension\NICMX\Restore;
44

5+
use AfriCC\EPP\Extension\NICMX\Restore\Domain;
56
use PHPUnit\Framework\TestCase;
67

7-
class DomainTest extends TestCase
8+
class DomainRestoreTest extends TestCase
89
{
910
public function testNicMxRestoreDomainFrame()
1011
{

tests/AfriCC/EPP/Test/Extension/Rgp/Update/DomainTest.php renamed to tests/EPP/Extension/Rgp/Update/DomainTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
<?php
22

3-
namespace AfriCC\EPP\Extension\Rgp\Update;
3+
namespace AfriCC\Tests\EPP\Extension\Rgp\Update;
44

5+
use AfriCC\EPP\Extension\Rgp\Update\Domain;
56
use PHPUnit\Framework\TestCase;
67

78
class DomainTest extends TestCase

tests/AfriCC/EPP/Test/Frame/Command/Create/ContactCreateTest.php renamed to tests/EPP/Frame/Command/Create/ContactCreateTest.php

Lines changed: 68 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
<?php
22

3-
namespace AfriCC\EPP\Frame\Command;
3+
namespace AfriCC\Tests\EPP\Frame\Command\Create;
44

5-
use AfriCC\EPP\Frame\Command\Create\Contact as CreateContact;
5+
use AfriCC\EPP\Frame\Command\Create\Contact;
66
use PHPUnit\Framework\TestCase;
77

8-
class ContactCreateTest extends TestCase
8+
class CreateContactTest extends TestCase
99
{
10-
public function testContactCreate()
10+
public function testCreateContactFrame()
1111
{
12-
$frame = new CreateContact();
12+
$frame = new Contact();
1313
$frame->setId('CONTACT1');
1414
$frame->setName('Günter Grodotzki');
1515
$frame->setName('Jun Grodotzki');
@@ -77,9 +77,9 @@ public function testContactCreate()
7777
);
7878
}
7979

80-
public function testContactCreateSkipInt()
80+
public function testCreateContactSkipIntFrame()
8181
{
82-
$frame = new CreateContact();
82+
$frame = new Contact();
8383
$frame->skipInt();
8484
$frame->setId('CONTACT1');
8585
$frame->setName('Günter Grodotzki');
@@ -136,9 +136,68 @@ public function testContactCreateSkipInt()
136136
);
137137
}
138138

139-
public function testContactCreateDisclose()
139+
public function testCreateContactSkipLocFrame()
140140
{
141-
$frame = new CreateContact();
141+
$frame = new Contact();
142+
$frame->skipLoc();
143+
$frame->setId('CONTACT1');
144+
$frame->setName('Günter Grodotzki');
145+
$frame->setName('Jun Grodotzki');
146+
$frame->setOrganization('weheartwebsites UG');
147+
$frame->addStreet('Rönskenstraße 23');
148+
$frame->addStreet('Around the Corner');
149+
$frame->setCity('Cape Town');
150+
$frame->setProvince('WC');
151+
$frame->setPostalCode('8001');
152+
$frame->setCountryCode('ZA');
153+
$frame->setVoice('+27.844784784');
154+
$frame->setFax('+1.844784784');
155+
$frame->setEmail('[email protected]');
156+
$auth = $frame->setAuthInfo();
157+
$frame->addDisclose('voice');
158+
$frame->addDisclose('email');
159+
160+
$this->assertXmlStringEqualsXmlString(
161+
'<?xml version="1.0" encoding="UTF-8" standalone="no"?>
162+
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
163+
<command>
164+
<create>
165+
<contact:create xmlns:contact="urn:ietf:params:xml:ns:contact-1.0">
166+
<contact:id>CONTACT1</contact:id>
167+
<contact:postalInfo type="int">
168+
<contact:name>Jun Grodotzki</contact:name>
169+
<contact:org>weheartwebsites UG</contact:org>
170+
<contact:addr>
171+
<contact:street>Ronskenstrasse 23</contact:street>
172+
<contact:street>Around the Corner</contact:street>
173+
<contact:city>Cape Town</contact:city>
174+
<contact:sp>WC</contact:sp>
175+
<contact:pc>8001</contact:pc>
176+
<contact:cc>ZA</contact:cc>
177+
</contact:addr>
178+
</contact:postalInfo>
179+
<contact:voice>+27.844784784</contact:voice>
180+
<contact:fax>+1.844784784</contact:fax>
181+
<contact:email>[email protected]</contact:email>
182+
<contact:authInfo>
183+
<contact:pw>' . $auth . '</contact:pw>
184+
</contact:authInfo>
185+
<contact:disclose flag="0">
186+
<contact:voice/>
187+
<contact:email/>
188+
</contact:disclose>
189+
</contact:create>
190+
</create>
191+
</command>
192+
</epp>
193+
',
194+
(string) $frame
195+
);
196+
}
197+
198+
public function testCreateContactDiscloseFrame()
199+
{
200+
$frame = new Contact();
142201
$frame->skipInt();
143202
$frame->setId('CONTACT1');
144203
$frame->setName('Günter Grodotzki');

tests/AfriCC/EPP/Test/Frame/Command/LoginTest.php renamed to tests/EPP/Frame/Command/LoginTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
<?php
22

3-
namespace AfriCC\EPP\Frame\Command;
3+
namespace AfriCC\Tests\EPP\Frame\Command;
44

5+
use AfriCC\EPP\Frame\Command\Login;
56
use PHPUnit\Framework\TestCase;
67

78
class LoginTest extends TestCase

tests/AfriCC/EPP/Test/Frame/Command/Transfer/DomainTransferTest.php renamed to tests/EPP/Frame/Command/Transfer/DomainTransferTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
<?php
22

3-
namespace AfriCC\EPP\Frame\Command;
3+
namespace AfriCC\Tests\EPP\Frame\Command\Transfer;
44

5-
use AfriCC\EPP\Frame\Command\Transfer\Domain as TransferDomain;
5+
use AfriCC\EPP\Frame\Command\Transfer\Domain;
66
use PHPUnit\Framework\TestCase;
77

88
class DomainTransferTest extends TestCase
99
{
10-
public function testContactCreate()
10+
public function testTransferDomainFrame()
1111
{
12-
$frame = new TransferDomain();
12+
$frame = new Domain();
1313
$frame->setOperation('cancel');
1414
$frame->setDomain(TEST_DOMAIN);
1515
$frame->setPeriod('6y');
@@ -35,9 +35,9 @@ public function testContactCreate()
3535
);
3636
}
3737

38-
public function testDomainTransferQuery()
38+
public function testTransferDomainQueryFrame()
3939
{
40-
$frame = new TransferDomain();
40+
$frame = new Domain();
4141
$frame->setOperation('query');
4242
$frame->setDomain(TEST_DOMAIN);
4343
$frame->setAuthInfo('password');

0 commit comments

Comments
 (0)