@@ -82,6 +82,85 @@ public function testIssRetidoSetsTribCode(): void
8282
8383 // -------------------------------------------------------------------------
8484
85+ public function testTomadorCnpjBlockIsIncludedWhenDocumentHas14Digits (): void
86+ {
87+ $ dps = $ this ->makeDps (documentoTomador: '12345678000195 ' , nomeTomador: 'Empresa Tomadora S.A. ' );
88+ $ xml = $ this ->builder ->buildDps ($ dps );
89+
90+ $ doc = new \DOMDocument ();
91+ $ doc ->loadXML ($ xml );
92+ $ xpath = new \DOMXPath ($ doc );
93+ $ xpath ->registerNamespace ('n ' , 'http://www.sped.fazenda.gov.br/nfse ' );
94+
95+ $ nodes = $ xpath ->query ('//n:toma/n:CNPJ ' );
96+ self ::assertSame (1 , $ nodes ->length , '<toma><CNPJ> block expected ' );
97+ self ::assertSame ('12345678000195 ' , $ nodes ->item (0 )->textContent );
98+
99+ $ nameNodes = $ xpath ->query ('//n:toma/n:xNome ' );
100+ self ::assertSame (1 , $ nameNodes ->length , '<toma><xNome> block expected ' );
101+ self ::assertSame ('Empresa Tomadora S.A. ' , $ nameNodes ->item (0 )->textContent );
102+ }
103+
104+ public function testTomadorCpfBlockIsIncludedWhenDocumentHas11Digits (): void
105+ {
106+ $ dps = $ this ->makeDps (documentoTomador: '12345678901 ' , nomeTomador: 'Pessoa Física Tomadora ' );
107+ $ xml = $ this ->builder ->buildDps ($ dps );
108+
109+ $ doc = new \DOMDocument ();
110+ $ doc ->loadXML ($ xml );
111+ $ xpath = new \DOMXPath ($ doc );
112+ $ xpath ->registerNamespace ('n ' , 'http://www.sped.fazenda.gov.br/nfse ' );
113+
114+ $ nodes = $ xpath ->query ('//n:toma/n:CPF ' );
115+ self ::assertSame (1 , $ nodes ->length , '<toma><CPF> block expected for 11-digit doc ' );
116+ self ::assertSame ('12345678901 ' , $ nodes ->item (0 )->textContent );
117+ }
118+
119+ public function testTomadorBlockIsAbsentWhenDocumentoTomadorIsEmpty (): void
120+ {
121+ $ dps = $ this ->makeDps (documentoTomador: '' );
122+ $ xml = $ this ->builder ->buildDps ($ dps );
123+
124+ $ doc = new \DOMDocument ();
125+ $ doc ->loadXML ($ xml );
126+ $ xpath = new \DOMXPath ($ doc );
127+ $ xpath ->registerNamespace ('n ' , 'http://www.sped.fazenda.gov.br/nfse ' );
128+
129+ $ nodes = $ xpath ->query ('//n:toma ' );
130+ self ::assertSame (0 , $ nodes ->length , '<toma> block must be absent when no buyer document ' );
131+ }
132+
133+ public function testRegimeEspecialTributacaoIsIncludedWhenSet (): void
134+ {
135+ $ dps = $ this ->makeDps (regimeEspecialTributacao: 1 );
136+ $ xml = $ this ->builder ->buildDps ($ dps );
137+
138+ $ doc = new \DOMDocument ();
139+ $ doc ->loadXML ($ xml );
140+ $ xpath = new \DOMXPath ($ doc );
141+ $ xpath ->registerNamespace ('n ' , 'http://www.sped.fazenda.gov.br/nfse ' );
142+
143+ $ nodes = $ xpath ->query ('//n:regEspTrib ' );
144+ self ::assertSame (1 , $ nodes ->length , '<regEspTrib> expected when regimeEspecialTributacao is set ' );
145+ self ::assertSame ('1 ' , $ nodes ->item (0 )->textContent );
146+ }
147+
148+ public function testRegimeEspecialTributacaoIsAbsentWhenNull (): void
149+ {
150+ $ dps = $ this ->makeDps (regimeEspecialTributacao: null );
151+ $ xml = $ this ->builder ->buildDps ($ dps );
152+
153+ $ doc = new \DOMDocument ();
154+ $ doc ->loadXML ($ xml );
155+ $ xpath = new \DOMXPath ($ doc );
156+ $ xpath ->registerNamespace ('n ' , 'http://www.sped.fazenda.gov.br/nfse ' );
157+
158+ $ nodes = $ xpath ->query ('//n:regEspTrib ' );
159+ self ::assertSame (0 , $ nodes ->length , '<regEspTrib> must be absent when null ' );
160+ }
161+
162+ // -------------------------------------------------------------------------
163+
85164 private function makeDps (
86165 string $ cnpjPrestador = '11222333000181 ' ,
87166 string $ municipioIbge = '3303302 ' ,
@@ -90,15 +169,21 @@ private function makeDps(
90169 string $ aliquota = '5.00 ' ,
91170 string $ discriminacao = 'Consultoria em TI ' ,
92171 bool $ issRetido = false ,
172+ string $ documentoTomador = '' ,
173+ string $ nomeTomador = '' ,
174+ ?int $ regimeEspecialTributacao = null ,
93175 ): DpsData {
94176 return new DpsData (
95- cnpjPrestador: $ cnpjPrestador ,
96- municipioIbge: $ municipioIbge ,
97- itemListaServico: $ itemListaServico ,
98- valorServico: $ valorServico ,
99- aliquota: $ aliquota ,
100- discriminacao: $ discriminacao ,
101- issRetido: $ issRetido ,
177+ cnpjPrestador: $ cnpjPrestador ,
178+ municipioIbge: $ municipioIbge ,
179+ itemListaServico: $ itemListaServico ,
180+ valorServico: $ valorServico ,
181+ aliquota: $ aliquota ,
182+ discriminacao: $ discriminacao ,
183+ documentoTomador: $ documentoTomador ,
184+ nomeTomador: $ nomeTomador ,
185+ regimeEspecialTributacao: $ regimeEspecialTributacao ,
186+ issRetido: $ issRetido ,
102187 );
103188 }
104189}
0 commit comments