1<?php 2 3namespace dokuwiki\plugin\acknowledge\test; 4 5use DokuWikiTest; 6 7/** 8 * Tests for the approve plugin integration (helper->isBlockedByApprove) 9 * 10 * The test drives the approve plugin exclusively through its public helper API 11 * (addMaintainer / handlePageEdit / setApprovedStatus) rather than touching its 12 * database directly, so it exercises the real integration path. 13 * 14 * @group plugin_acknowledge 15 * @group plugins 16 */ 17class ApproveIntegrationTest extends DokuWikiTest 18{ 19 /** @var array */ 20 protected $pluginsEnabled = ['acknowledge', 'sqlite', 'approve']; 21 22 /** @var \helper_plugin_acknowledge */ 23 protected $helper; 24 25 /** @var \helper_plugin_approve_db */ 26 protected $approve; 27 28 public function setUp(): void 29 { 30 parent::setUp(); 31 32 // setApprovedStatus() records the approving user from $INFO 33 global $INFO; 34 $INFO['client'] = 'someapprover'; 35 36 $this->helper = plugin_load('helper', 'acknowledge'); 37 $this->approve = plugin_load('helper', 'approve_db'); 38 39 // track the whole "approved:" namespace 40 $this->approve->addMaintainer('approved:**', 'someapprover'); 41 } 42 43 /** 44 * Create a wiki page and let approve record its current revision, 45 * just as the COMMON_WIKIPAGE_SAVE hook would. 46 * 47 * @param string $id page id 48 * @return void 49 */ 50 protected function createPage($id) 51 { 52 saveWikiText($id, 'content', 'test'); 53 $this->approve->handlePageEdit($id); 54 } 55 56 /** 57 * A page outside any approve-maintained namespace is never blocked. 58 */ 59 public function testUntrackedPageNotBlocked() 60 { 61 $id = 'free:page'; 62 $this->createPage($id); 63 self::assertFalse($this->helper->isBlockedByApprove($id)); 64 } 65 66 /** 67 * A maintained page that is still a draft is blocked. 68 */ 69 public function testDraftPageBlocked() 70 { 71 $id = 'approved:draft'; 72 $this->createPage($id); 73 self::assertTrue($this->helper->isBlockedByApprove($id)); 74 } 75 76 /** 77 * A maintained page whose current revision is approved is not blocked. 78 */ 79 public function testApprovedPageNotBlocked() 80 { 81 $id = 'approved:done'; 82 $this->createPage($id); 83 $this->approve->setApprovedStatus($id); 84 self::assertFalse($this->helper->isBlockedByApprove($id)); 85 } 86 87 /** 88 * With the integration disabled, even a maintained draft is not blocked. 89 */ 90 public function testDisabledIntegrationNeverBlocks() 91 { 92 global $conf; 93 $conf['plugin']['acknowledge']['approve_integration'] = 0; 94 95 $id = 'approved:ignored'; 96 $this->createPage($id); 97 self::assertFalse($this->helper->isBlockedByApprove($id)); 98 } 99} 100