From dbe2e69a973b7a80bf32cd2bbd6f666d72211fcb Mon Sep 17 00:00:00 2001 From: Adam Daley Date: Sun, 8 Mar 2026 20:49:56 +0000 Subject: [PATCH] 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 --- .../modules/Servicedomain/ServiceTest.php | 188 ++++++++++++++++++ 1 file changed, 188 insertions(+) diff --git a/tests-legacy/modules/Servicedomain/ServiceTest.php b/tests-legacy/modules/Servicedomain/ServiceTest.php index 74f8a01cf..92ac9c085 100644 --- a/tests-legacy/modules/Servicedomain/ServiceTest.php +++ b/tests-legacy/modules/Servicedomain/ServiceTest.php @@ -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); + } }