1<?php 2 3/** 4 * Tests over DokuWiki function for the Webcode plugin 5 * 6 * Most of the test are cache test that are no more used 7 * They are still there for documentation purpose 8 * 9 * @group plugin_webcode 10 * @group plugins 11 */ 12class dokuwiki_plugin_webcode_test extends DokuWikiTest 13{ 14 15 const pageId = 'PageId'; 16 const webCodeUniqueId = 'WebCodeUniqueKey'; 17 const storedContent = 'MyHTMLContent'; 18 const extension = '.webcode'; 19 20 public $cacheKey; 21 public $cleanPageId; 22 public $cleanWebCodeId; 23 24 function setUp(){ 25 // The cache system is change unfortunately 26 global $conf; 27 parent::setUp(); 28 $conf['cachedir']=DOKU_INC.'/data/cache'; 29 $this->cleanPageId = cleanID(SELF::pageId); 30 $this->cleanWebCodeId = cleanID(SELF::webCodeUniqueId); 31 $this->cacheKey = $this->cleanPageId.$this->cleanWebCodeId; 32 } 33 34 public function test_key(){ 35 $this->assertNotEquals($this->cacheKey, 0, 'The key must be not 0'); 36 $this->assertNotNull($this->cacheKey, 'The key must be not NULL'); 37 } 38 /** 39 * Dokuwiki Test to see if I can cache and get cached data 40 */ 41 public function test_StoreCache() 42 { 43 44 $cache = new cache($this->cacheKey, SELF::extension); 45 $cache->storeCache(SELF::storedContent); 46 $this->assertNotNull($cache->cache, "The cache file name must be not NULL. It was (+".$cache->cache.")"); 47 $this->assertTrue(strpos($cache->cache,DOKU_INC) !== false, "The cache file path must contains DOKU_INC (".DOKU_INC."). It was (".$cache->cache.")"); 48 49 50 } 51 52 public function test_RetrieveCache() 53 { 54 55 $cache = new cache($this->cacheKey, SELF::extension); 56 // Now we retrieve the content 57 $content = $cache->retrieveCache(); 58 $this->assertEquals($content, SELF::storedContent, 'The stored content that we retrieve must be the same'); 59 60 } 61 62 63 64 65 /** 66 * From: 67 * - the file indexer_indexing.test.php 68 * - https://www.dokuwiki.org/devel:metadata 69 * 70 * You can add a meta to the index and lookup the pages with this key 71 * You cannot retrieve the meta unfortunately 72 */ 73 public function test_metaInIndex(){ 74 75 /** @var Doku_Indexer $indexer */ 76 $indexer = idx_get_indexer(); 77 $indexMetaWebCodeKey = 'webCodeMetaKey'; 78 79 // Add a meta from Webcode 80 $indexer->addMetaKeys($this->cleanPageId, $indexMetaWebCodeKey, 'testvalue'); 81 82 // Retrieve the page with this meta value 83 $query = 'testvalue'; 84 $this->assertEquals(array($this->cleanPageId), $indexer->lookupKey($indexMetaWebCodeKey, $query)); 85 86 87 } 88 89 /** 90 * 91 * @see http://www.dokuwiki.org/devel:metadata#functions_to_get_and_set_metadata 92 * 93 */ 94 public function test_metaAddAndGet(){ 95 96 // The list of WebCode hash of a page 97 // One hash is one webCode node 98 $metaToSave = array('keyCacheId1', 'keyCacheId2'); 99 100 // The meta key 101 $metaKey = 'WebCodeIds'; 102 103 // Set 104 $meta = array($metaKey => $metaToSave); 105 p_set_metadata($this->cleanPageId, $meta, false, true); 106 107 // Retrieve the meta 108 $meta_get = p_get_metadata($this->cleanPageId, $metaKey); 109 110 // Test 111 $this->assertEquals($meta_get, $metaToSave, "They must be equals"); 112 113 } 114 115} 116