192200750SAndreas Gohr<?php 292200750SAndreas Gohr 392200750SAndreas Gohrnamespace dokuwiki\plugin\dw2pdf\test; 492200750SAndreas Gohr 592200750SAndreas Gohruse dokuwiki\plugin\dw2pdf\src\Config; 6*4c569113SAndreas Gohruse dokuwiki\plugin\dw2pdf\src\ExportException; 792200750SAndreas Gohruse dokuwiki\plugin\dw2pdf\src\NamespaceCollector; 892200750SAndreas Gohruse DokuWikiTest; 992200750SAndreas Gohr 1092200750SAndreas Gohr/** 1192200750SAndreas Gohr * @group plugin_dw2pdf 1292200750SAndreas Gohr * @group plugins 1392200750SAndreas Gohr */ 1492200750SAndreas Gohrclass NamespaceCollectorCollectTest extends DokuWikiTest 1592200750SAndreas Gohr{ 1692200750SAndreas Gohr public function setUp(): void 1792200750SAndreas Gohr { 1892200750SAndreas Gohr parent::setUp(); 1992200750SAndreas Gohr $_REQUEST = []; 2092200750SAndreas Gohr } 2192200750SAndreas Gohr 2292200750SAndreas Gohr /** 2392200750SAndreas Gohr * Namespace collector should remove individually excluded pages and sub-namespaces. 2492200750SAndreas Gohr */ 2592200750SAndreas Gohr public function testCollectHonorsExcludes(): void 2692200750SAndreas Gohr { 2792200750SAndreas Gohr global $INPUT; 2892200750SAndreas Gohr $ns = 'playground:dw2pdfns'; 2992200750SAndreas Gohr 3092200750SAndreas Gohr $this->createPage("$ns:start", 'start page'); 3192200750SAndreas Gohr $this->createPage("$ns:keep", 'keep me'); 3292200750SAndreas Gohr $this->createPage("$ns:skip", 'skip me'); 3392200750SAndreas Gohr $this->createPage("$ns:child:page", 'child namespace'); 3492200750SAndreas Gohr 3592200750SAndreas Gohr $INPUT->set('book_ns', $ns); 3692200750SAndreas Gohr $INPUT->set('book_order', 'pagename'); 3792200750SAndreas Gohr $INPUT->set('excludes', ["$ns:skip"]); 3892200750SAndreas Gohr $INPUT->set('excludesns', ["$ns:child"]); 3992200750SAndreas Gohr 4092200750SAndreas Gohr $collector = new NamespaceCollector(new Config()); 4192200750SAndreas Gohr $this->assertSame( 4292200750SAndreas Gohr ["$ns:start", "$ns:keep"], 4392200750SAndreas Gohr $collector->getPages() 4492200750SAndreas Gohr ); 4592200750SAndreas Gohr } 4692200750SAndreas Gohr 4792200750SAndreas Gohr /** 48*4c569113SAndreas Gohr * A missing namespace must be reported to the user. 4992200750SAndreas Gohr */ 50*4c569113SAndreas Gohr public function testThrowsForMissingNamespace(): void 5192200750SAndreas Gohr { 5292200750SAndreas Gohr global $INPUT; 5392200750SAndreas Gohr $INPUT->set('book_ns', 'missing:dw2pdfns'); 5492200750SAndreas Gohr 55*4c569113SAndreas Gohr $this->expectException(ExportException::class); 56*4c569113SAndreas Gohr $this->expectExceptionMessage('needns'); 57*4c569113SAndreas Gohr new NamespaceCollector(new Config()); 5892200750SAndreas Gohr } 5992200750SAndreas Gohr 6092200750SAndreas Gohr private function createPage(string $id, string $content): void 6192200750SAndreas Gohr { 6292200750SAndreas Gohr saveWikiText($id, $content, 'dw2pdf namespace test'); 6392200750SAndreas Gohr } 6492200750SAndreas Gohr} 65