|
38 | 38 |
|
39 | 39 | test('can render documents', function () { |
40 | 40 | expect($this->generator->canRenderDocuments()) |
41 | | - ->toBeFalse(); |
| 41 | + ->toBeTrue(); |
42 | 42 | }); |
43 | 43 |
|
44 | 44 | test('is templated', function () { |
45 | 45 | expect($this->generator->isTemplated()) |
46 | | - ->toBeFalse(); |
| 46 | + ->toBeTrue(); |
47 | 47 | }); |
48 | 48 |
|
49 | 49 | test('render element', function () { |
|
121 | 121 | $document->appendChild($element); |
122 | 122 | $result = $this->generator->render($document); |
123 | 123 | expect($result) |
124 | | - ->toBeNull(); |
| 124 | + ->toBeString(); |
| 125 | + expect($result) |
| 126 | + ->toContain('This file is auto-generated'); |
125 | 127 | }); |
126 | 128 |
|
127 | 129 | test('render invalid', function () { |
|
261 | 263 | } |
262 | 264 | }); |
263 | 265 |
|
264 | | -test('render head', function () { |
| 266 | +test('set document render mode normalizes and validates values', function () { |
265 | 267 | $reflection = new ReflectionClass($this->generator); |
266 | | - $method = $reflection->getMethod('renderHead'); |
267 | | - $method->setAccessible(true); |
| 268 | + $property = $reflection->getProperty('documentRenderMode'); |
| 269 | + $property->setAccessible(true); |
268 | 270 |
|
269 | | - $document = HTMLDocumentDelegator::createEmpty(); |
270 | | - $result = $method->invoke($this->generator, $document); |
| 271 | + $this->generator->setDocumentRenderMode(' include '); |
| 272 | + expect($property->getValue($this->generator)) |
| 273 | + ->toBe('include'); |
271 | 274 |
|
272 | | - // Since getDocumentMetadata returns empty array, renderHead should return null |
273 | | - expect($result) |
274 | | - ->toBeNull(); |
| 275 | + $this->generator->setDocumentRenderMode('unsupported'); |
| 276 | + expect($property->getValue($this->generator)) |
| 277 | + ->toBe('raw'); |
275 | 278 | }); |
276 | 279 |
|
277 | | -test('render body', function () { |
278 | | - $reflection = new ReflectionClass($this->generator); |
279 | | - $method = $reflection->getMethod('renderBody'); |
280 | | - $method->setAccessible(true); |
| 280 | +test('render document include mode uses include/embed templates', function () { |
| 281 | + $this->generator->setDocumentRenderMode('include'); |
281 | 282 |
|
282 | 283 | $document = HTMLDocumentDelegator::createEmpty(); |
283 | 284 | $body = Body::create($document); |
| 285 | + $anchor = Anchor::create($document); |
| 286 | + $anchor->setHref('https://example.com'); |
| 287 | + $anchor->append('Example'); |
| 288 | + $body->appendChild($anchor); |
284 | 289 | $document->appendChild($body); |
285 | 290 |
|
286 | | - $result = $method->invoke($this->generator, $document); |
| 291 | + $result = $this->generator->render($document); |
287 | 292 |
|
288 | 293 | expect($result) |
289 | 294 | ->toBeString(); |
290 | 295 | expect($result) |
291 | | - ->toContain('{% block body %}'); |
| 296 | + ->toContain('Strict mode: include'); |
| 297 | + expect($result) |
| 298 | + ->toContain("{% embed 'inline/a/a.twig'"); |
292 | 299 | }); |
293 | 300 |
|
294 | | -test('get document metadata', function () { |
| 301 | +test('extract twig expression helper', function () { |
295 | 302 | $reflection = new ReflectionClass($this->generator); |
296 | | - $method = $reflection->getMethod('getDocumentMetadata'); |
| 303 | + $method = $reflection->getMethod('extractTwigExpression'); |
297 | 304 | $method->setAccessible(true); |
298 | 305 |
|
299 | | - $document = HTMLDocumentDelegator::createEmpty(); |
300 | | - $result = $method->invoke($this->generator, $document); |
301 | | - |
302 | | - expect($result) |
303 | | - ->toBeArray(); |
304 | | - expect($result) |
305 | | - ->toBeEmpty(); |
| 306 | + expect($method->invoke($this->generator, '{{ user.name }}')) |
| 307 | + ->toBe('user.name'); |
| 308 | + expect($method->invoke($this->generator, 'plain-text')) |
| 309 | + ->toBeNull(); |
306 | 310 | }); |
307 | 311 |
|
308 | | -test('render twig template', function () { |
| 312 | +test('build twig map string helper', function () { |
309 | 313 | $reflection = new ReflectionClass($this->generator); |
310 | | - $method = $reflection->getMethod('renderTwigTemplate'); |
| 314 | + $method = $reflection->getMethod('buildTwigMapString'); |
311 | 315 | $method->setAccessible(true); |
312 | 316 |
|
313 | | - $result = $method->invoke($this->generator, 'head', [ |
314 | | - 'test' => 'data', |
| 317 | + $result = $method->invoke($this->generator, [ |
| 318 | + 'id' => 'main', |
| 319 | + 'class' => 'hero', |
| 320 | + 'content' => ['__twig_expr' => 'user.name'], |
315 | 321 | ]); |
316 | 322 |
|
317 | | - // Since loadTwigTemplate returns null, renderTwigTemplate should return null |
318 | 323 | expect($result) |
319 | | - ->toBeNull(); |
| 324 | + ->toContain('id:'); |
| 325 | + expect($result) |
| 326 | + ->toContain('class:'); |
| 327 | + expect($result) |
| 328 | + ->toContain('content: user.name'); |
320 | 329 | }); |
321 | 330 |
|
322 | | -test('load twig template', function () { |
| 331 | +test('resolve twig template path helper', function () { |
323 | 332 | $reflection = new ReflectionClass($this->generator); |
324 | | - $method = $reflection->getMethod('loadTwigTemplate'); |
| 333 | + $method = $reflection->getMethod('resolveTwigTemplatePath'); |
325 | 334 | $method->setAccessible(true); |
326 | 335 |
|
327 | | - $result = $method->invoke($this->generator, 'head'); |
328 | | - |
329 | | - expect($result) |
| 336 | + expect($method->invoke($this->generator, 'a')) |
| 337 | + ->toBe('inline/a/a.twig'); |
| 338 | + expect($method->invoke($this->generator, 'not-a-real-tag')) |
330 | 339 | ->toBeNull(); |
331 | 340 | }); |
332 | 341 |
|
|
344 | 353 | expect($result) |
345 | 354 | ->toBeString(); |
346 | 355 | expect($result) |
347 | | - ->toContain('<?xml version="1.0" encoding="UTF-8"?>'); |
348 | | - expect($result) |
349 | | - ->toContain('<!DOCTYPE html>'); |
350 | | - expect($result) |
351 | | - ->toContain('<html lang="en">'); |
352 | | - expect($result) |
353 | | - ->toContain('<body>'); |
354 | | - expect($result) |
355 | | - ->toContain('</body>'); |
| 356 | + ->toContain('This file is auto-generated'); |
356 | 357 | expect($result) |
357 | | - ->toContain('</html>'); |
| 358 | + ->toContain('Component: component'); |
358 | 359 | }); |
359 | 360 |
|
360 | | -test('render head with metadata', function () { |
361 | | - $reflection = new ReflectionClass($this->generator); |
362 | | - |
363 | | - // Mock getDocumentMetadata to return data |
364 | | - $metadataMethod = $reflection->getMethod('getDocumentMetadata'); |
365 | | - $metadataMethod->setAccessible(true); |
| 361 | +test('render document use mode falls back to embed strategy', function () { |
| 362 | + $this->generator->setDocumentRenderMode('use'); |
366 | 363 |
|
367 | | - // Create a document with a title |
368 | 364 | $document = HTMLDocumentDelegator::createEmpty(); |
369 | | - $title = $document->createElement('title'); |
370 | | - $title->textContent = 'Test Document'; |
371 | | - $head = $document->createElement('head'); |
372 | | - $head->appendChild($title); |
373 | | - $document->appendChild($head); |
374 | | - |
375 | | - // Test getDocumentMetadata |
376 | | - $metadata = $metadataMethod->invoke($this->generator, $document); |
377 | | - expect($metadata) |
378 | | - ->toBeArray(); |
| 365 | + $body = Body::create($document); |
| 366 | + $anchor = Anchor::create($document); |
| 367 | + $anchor->setHref('https://example.com'); |
| 368 | + $anchor->append('Go'); |
| 369 | + $body->appendChild($anchor); |
| 370 | + $document->appendChild($body); |
379 | 371 |
|
380 | | - // Test renderHead - it will still return null since renderTwigTemplate returns null |
381 | | - $headMethod = $reflection->getMethod('renderHead'); |
382 | | - $headMethod->setAccessible(true); |
| 372 | + $result = $this->generator->render($document); |
383 | 373 |
|
384 | | - $result = $headMethod->invoke($this->generator, $document); |
385 | 374 | expect($result) |
386 | | - ->toBeNull(); |
| 375 | + ->toBeString(); |
| 376 | + expect($result) |
| 377 | + ->toContain('Strict mode: use'); |
| 378 | + expect($result) |
| 379 | + ->toContain('{% embed'); |
387 | 380 | }); |
388 | 381 |
|
389 | 382 | test('camel to kebab', function () { |
|
0 commit comments