1*92200750SAndreas Gohr<?php 2*92200750SAndreas Gohr 3*92200750SAndreas Gohrnamespace dokuwiki\plugin\dw2pdf\test; 4*92200750SAndreas Gohr 5*92200750SAndreas Gohruse dokuwiki\plugin\dw2pdf\src\BookCreatorLiveSelectionCollector; 6*92200750SAndreas Gohruse dokuwiki\plugin\dw2pdf\src\Config; 7*92200750SAndreas Gohruse DokuWikiTest; 8*92200750SAndreas Gohr 9*92200750SAndreas Gohr/** 10*92200750SAndreas Gohr * @group plugin_dw2pdf 11*92200750SAndreas Gohr * @group plugins 12*92200750SAndreas Gohr */ 13*92200750SAndreas Gohrclass BookCreatorLiveSelectionCollectorTest extends DokuWikiTest 14*92200750SAndreas Gohr{ 15*92200750SAndreas Gohr public function setUp(): void 16*92200750SAndreas Gohr { 17*92200750SAndreas Gohr parent::setUp(); 18*92200750SAndreas Gohr $_REQUEST = []; 19*92200750SAndreas Gohr } 20*92200750SAndreas Gohr 21*92200750SAndreas Gohr /** 22*92200750SAndreas Gohr * Live selections should be decoded and normalized via cleanID(). 23*92200750SAndreas Gohr */ 24*92200750SAndreas Gohr public function testCollectsPagesFromJsonSelection(): void 25*92200750SAndreas Gohr { 26*92200750SAndreas Gohr global $INPUT; 27*92200750SAndreas Gohr $pageA = 'playground:bookcreator:a'; 28*92200750SAndreas Gohr $pageB = 'playground:bookcreator:Child'; 29*92200750SAndreas Gohr $pageC = 'playground:bookcreator:nonexistent'; 30*92200750SAndreas Gohr saveWikiText($pageA, 'A', 'create'); 31*92200750SAndreas Gohr saveWikiText($pageB, 'B', 'create'); 32*92200750SAndreas Gohr 33*92200750SAndreas Gohr // page B has mixed case to test cleanID() 34*92200750SAndreas Gohr $INPUT->set('selection', json_encode([$pageA, $pageB, $pageC])); // page B has mixed case to test cleanID() 35*92200750SAndreas Gohr 36*92200750SAndreas Gohr $collector = new BookCreatorLiveSelectionCollector(new Config()); 37*92200750SAndreas Gohr $this->assertSame( 38*92200750SAndreas Gohr [$pageA, 'playground:bookcreator:child'], // page C should be skipped as it does not exist 39*92200750SAndreas Gohr $collector->getPages() 40*92200750SAndreas Gohr ); 41*92200750SAndreas Gohr } 42*92200750SAndreas Gohr 43*92200750SAndreas Gohr /** 44*92200750SAndreas Gohr * Invalid JSON payloads must bubble up as JsonException so the caller can handle them. 45*92200750SAndreas Gohr */ 46*92200750SAndreas Gohr public function testThrowsOnInvalidJson(): void 47*92200750SAndreas Gohr { 48*92200750SAndreas Gohr global $INPUT; 49*92200750SAndreas Gohr $INPUT->set('selection', '{invalid'); 50*92200750SAndreas Gohr 51*92200750SAndreas Gohr $this->expectException(\JsonException::class); 52*92200750SAndreas Gohr new BookCreatorLiveSelectionCollector(new Config()); 53*92200750SAndreas Gohr } 54*92200750SAndreas Gohr} 55