Enable default WHOIS privacy status for domain registration (Tests) (#3293)

* Allow registrar modules to set default WHOIS privacy status on domain registration

Allow registrar modules to set WHOIS privacy status during domain
registration. Some registries (e.g. .ge) automatically enable privacy
protection or require it by default. This change allows modules to return the resulting privacy status via getPrivacyEnabled() so the domain model can store the correct value.

* Add tests for syncWhois privacy sync in Servicedomain module

Adds comprehensive tests for PR #3286:
- testSyncWhoisWithPrivacyEnabled(): Verifies privacy=true is persisted
- testSyncWhoisWithPrivacyDisabled(): Verifies privacy=false is persisted
- testSyncWhoisWithPrivacyNull(): Verifies privacy=null doesn't update model

These tests exercise the syncWhois() method directly via reflection to test
that getPrivacyEnabled() returns from Registrar_Domain are properly synced
to the Model_ServiceDomain's privacy field.

---------

Co-authored-by: Namingo <help@namingo.org>
This commit is contained in:
Adam DaleyandNamingo authored and GitHub committed 2026-03-08 20:49:56 +00:00
1 parent cd68d32d03
commit dbe2e69a97
1 file changed
+188
@@ -1931,4 +1931,192 @@ final class ServiceTest extends \BBTestCase
$this->assertTrue($result);
}
public function testSyncWhoisWithPrivacyEnabled(): void
{
$contact = new \Registrar_Domain_Contact();
$contact->setFirstName('John');
$contact->setLastName('Doe');
$contact->setEmail('john@example.com');
$contact->setCompany('Test Co');
$contact->setAddress1('123 Test St');
$contact->setCity('Test City');
$contact->setCountry('US');
$contact->setState('CA');
$contact->setZip('12345');
$contact->setTelCc('1');
$contact->setTel('5551234567');
$registrarDomain = new \Registrar_Domain();
$registrarDomain->setPrivacyEnabled(true);
$registrarDomain->setLocked(true);
$registrarDomain->setExpirationTime(strtotime('+1 year'));
$registrarDomain->setRegistrationTime(time());
$registrarDomain->setContactRegistrar($contact);
$registrarAdapterMock = $this->getMockBuilder('Registrar_Adapter_Custom')
->disableOriginalConstructor()
->getMock();
$registrarAdapterMock->expects($this->atLeastOnce())
->method('getDomainDetails')
->willReturn($registrarDomain);
$serviceMock = $this->getMockBuilder(\Box\Mod\Servicedomain\Service::class)
->onlyMethods(['_getD'])
->getMock();
$serviceMock->expects($this->atLeastOnce())
->method('_getD')
->willReturn([$registrarDomain, $registrarAdapterMock]);
$dbMock = $this->createMock('\Box_Database');
$dbMock->expects($this->atLeastOnce())
->method('store')
->willReturnCallback(function ($model) {
$this->assertInstanceOf(\Model_ServiceDomain::class, $model);
$this->assertEquals(1, $model->privacy);
$this->assertEquals(1, $model->locked);
return 1;
});
$di = $this->getDi();
$di['db'] = $dbMock;
$di['logger'] = $this->createMock('Box_Log');
$serviceMock->setDi($di);
$domainModel = new \Model_ServiceDomain();
$domainModel->loadBean(new \DummyBean());
$order = new \Model_ClientOrder();
$order->loadBean(new \DummyBean());
$reflection = new \ReflectionMethod($serviceMock, 'syncWhois');
$reflection->setAccessible(true);
$reflection->invoke($serviceMock, $domainModel, $order);
}
public function testSyncWhoisWithPrivacyDisabled(): void
{
$contact = new \Registrar_Domain_Contact();
$contact->setFirstName('John');
$contact->setLastName('Doe');
$contact->setEmail('john@example.com');
$contact->setCompany('Test Co');
$contact->setAddress1('123 Test St');
$contact->setCity('Test City');
$contact->setCountry('US');
$contact->setState('CA');
$contact->setZip('12345');
$contact->setTelCc('1');
$contact->setTel('5551234567');
$registrarDomain = new \Registrar_Domain();
$registrarDomain->setPrivacyEnabled(false);
$registrarDomain->setLocked(false);
$registrarDomain->setExpirationTime(strtotime('+1 year'));
$registrarDomain->setRegistrationTime(time());
$registrarDomain->setContactRegistrar($contact);
$registrarAdapterMock = $this->getMockBuilder('Registrar_Adapter_Custom')
->disableOriginalConstructor()
->getMock();
$registrarAdapterMock->expects($this->atLeastOnce())
->method('getDomainDetails')
->willReturn($registrarDomain);
$serviceMock = $this->getMockBuilder(\Box\Mod\Servicedomain\Service::class)
->onlyMethods(['_getD'])
->getMock();
$serviceMock->expects($this->atLeastOnce())
->method('_getD')
->willReturn([$registrarDomain, $registrarAdapterMock]);
$dbMock = $this->createMock('\Box_Database');
$dbMock->expects($this->atLeastOnce())
->method('store')
->willReturnCallback(function ($model) {
$this->assertInstanceOf(\Model_ServiceDomain::class, $model);
$this->assertEquals(0, $model->privacy);
$this->assertEquals(0, $model->locked);
return 1;
});
$di = $this->getDi();
$di['db'] = $dbMock;
$di['logger'] = $this->createMock('Box_Log');
$serviceMock->setDi($di);
$domainModel = new \Model_ServiceDomain();
$domainModel->loadBean(new \DummyBean());
$order = new \Model_ClientOrder();
$order->loadBean(new \DummyBean());
$reflection = new \ReflectionMethod($serviceMock, 'syncWhois');
$reflection->setAccessible(true);
$reflection->invoke($serviceMock, $domainModel, $order);
}
public function testSyncWhoisWithPrivacyNull(): void
{
$contact = new \Registrar_Domain_Contact();
$contact->setFirstName('John');
$contact->setLastName('Doe');
$contact->setEmail('john@example.com');
$contact->setCompany('Test Co');
$contact->setAddress1('123 Test St');
$contact->setCity('Test City');
$contact->setCountry('US');
$contact->setState('CA');
$contact->setZip('12345');
$contact->setTelCc('1');
$contact->setTel('5551234567');
$registrarDomain = new \Registrar_Domain();
$registrarDomain->setLocked(true);
$registrarDomain->setExpirationTime(strtotime('+1 year'));
$registrarDomain->setRegistrationTime(time());
$registrarDomain->setContactRegistrar($contact);
$registrarAdapterMock = $this->getMockBuilder('Registrar_Adapter_Custom')
->disableOriginalConstructor()
->getMock();
$registrarAdapterMock->expects($this->atLeastOnce())
->method('getDomainDetails')
->willReturn($registrarDomain);
$serviceMock = $this->getMockBuilder(\Box\Mod\Servicedomain\Service::class)
->onlyMethods(['_getD'])
->getMock();
$serviceMock->expects($this->atLeastOnce())
->method('_getD')
->willReturn([$registrarDomain, $registrarAdapterMock]);
$dbMock = $this->createMock('\Box_Database');
$dbMock->expects($this->atLeastOnce())
->method('store')
->willReturnCallback(function ($model) {
$this->assertInstanceOf(\Model_ServiceDomain::class, $model);
$this->assertNull($model->privacy);
$this->assertEquals(1, $model->locked);
return 1;
});
$di = $this->getDi();
$di['db'] = $dbMock;
$di['logger'] = $this->createMock('Box_Log');
$serviceMock->setDi($di);
$domainModel = new \Model_ServiceDomain();
$domainModel->loadBean(new \DummyBean());
$order = new \Model_ClientOrder();
$order->loadBean(new \DummyBean());
$reflection = new \ReflectionMethod($serviceMock, 'syncWhois');
$reflection->setAccessible(true);
$reflection->invoke($serviceMock, $domainModel, $order);
}
}