1<?php 2 3use dokuwiki\plugin\structpublish\meta\Assignments; 4use dokuwiki\plugin\structpublish\meta\Constants; 5use dokuwiki\plugin\structpublish\meta\Revision; 6 7/** 8 * Revision tests for the structpublish plugin 9 * 10 * @group plugin_structpublish 11 * @group plugins 12 */ 13class revision_plugin_structpublish_test extends DokuWikiTest 14{ 15 /** @inheritdoc **/ 16 protected $pluginsEnabled = ['sqlite', 'struct', 'structpublish']; 17 18 /** 19 * @var \helper_plugin_sqlite 20 */ 21 protected $sqlite; 22 23 public function setUp(): void 24 { 25 parent::setUp(); 26 27 global $USERINFO; 28 29 // user 30 $_SERVER['REMOTE_USER'] = 'publisher'; 31 $USERINFO['grps'] = ['user', 'approver', 'publisher']; 32 33 // our database migrations 34 /** @var action_plugin_structpublish_migration $migration */ 35 $migration = plugin_load('action', 'structpublish_migration'); 36 $data = ''; 37 $migration->handleMigrations(new Doku_Event('DUMMY_EVENT', $data)); 38 39 // assignments 40 $assignments = Assignments::getInstance(true); 41 $this->sqlite = $assignments->getSqlite(); 42 $assignments->addPattern('public:**', '@approver', 'approve'); 43 $assignments->addPattern('public:**', '@publisher', 'publish'); 44 } 45 46 /** 47 * Test publish workflow 48 * 49 * @return void 50 */ 51 public function test_full_workflow() 52 { 53 global $ID; 54 global $INFO; 55 56 $pid = 'public:structpublish'; 57 $ID = $pid; 58 $INFO['id'] = $pid; 59 60 $text = 'lorem ipsum'; 61 62 saveWikiText($pid, $text, 'Save first draft'); 63 64 $currentrev = time(); 65 $INFO['currentrev'] = $currentrev; 66 67 $revision = new Revision($pid, $currentrev); 68 69 $user = $revision->getUser(); 70 $status = $revision->getStatus(); 71 $version = $revision->getVersion(); 72 73 $this->assertEquals('', $user); 74 $this->assertEquals(Constants::STATUS_DRAFT, $status); 75 $this->assertEquals('', $version); 76 77 $helper = plugin_load('helper', 'structpublish_publish'); 78 79 // approve 80 $helper->saveRevision(Constants::ACTION_APPROVE); 81 82 $revision = new Revision($ID, $currentrev); 83 $status = $revision->getStatus(); 84 $this->assertEquals(Constants::STATUS_APPROVED, $status); 85 86 // publish 87 $helper->saveRevision(Constants::ACTION_PUBLISH, '1'); 88 89 $revision = new Revision($ID, $currentrev); 90 $status = $revision->getStatus(); 91 $user = $revision->getUser(); 92 $this->assertEquals(Constants::STATUS_PUBLISHED, $status); 93 $this->assertEquals('publisher', $user); 94 95 sleep(3); 96 97 saveWikiText($pid, "$text $text", 'Save second draft'); 98 99 $currentrev = time(); 100 $INFO['currentrev'] = $currentrev; 101 102 $helper->saveRevision(Constants::ACTION_PUBLISH, '2'); 103 104 $revision = new Revision($ID, $currentrev); 105 $previous = $revision->getLatestPublishedRevision($currentrev); 106 $this->assertEquals('2', $revision->getVersion()); 107 $this->assertEquals('1', $previous->getVersion()); 108 } 109} 110