1<?php 2 3namespace dokuwiki\test\Parsing\ParserMode; 4 5use dokuwiki\Parsing\ParserMode\Rss; 6 7class RssTest extends ParserTestBase 8{ 9 function setUp(): void 10 { 11 parent::setUp(); 12 $this->P->addMode('rss', new Rss()); 13 } 14 15 function testRssBasic() 16 { 17 $this->P->parse('Foo {{rss>http://example.com/feed}} Bar'); 18 $calls = [ 19 ['document_start', []], 20 ['p_open', []], 21 ['cdata', ["\nFoo "]], 22 ['p_close', []], 23 ['rss', ['http://example.com/feed', [ 24 'max' => 8, 25 'reverse' => 0, 26 'author' => 0, 27 'date' => 0, 28 'details' => 0, 29 'nosort' => 0, 30 'refresh' => 14400, 31 ]]], 32 ['p_open', []], 33 ['cdata', [' Bar']], 34 ['p_close', []], 35 ['document_end', []], 36 ]; 37 $this->assertCalls($calls, $this->H->calls); 38 } 39 40 function testRssMaxItems() 41 { 42 $this->P->parse('{{rss>http://example.com/feed 5}}'); 43 $calls = [ 44 ['document_start', []], 45 ['rss', ['http://example.com/feed', [ 46 'max' => '5', 47 'reverse' => 0, 48 'author' => 0, 49 'date' => 0, 50 'details' => 0, 51 'nosort' => 0, 52 'refresh' => 14400, 53 ]]], 54 ['document_end', []], 55 ]; 56 $this->assertCalls($calls, $this->H->calls); 57 } 58 59 function testRssAllParams() 60 { 61 $this->P->parse('{{rss>http://example.com/feed 3 rev author date desc nosort 2h}}'); 62 $calls = [ 63 ['document_start', []], 64 ['rss', ['http://example.com/feed', [ 65 'max' => '3', 66 'reverse' => 1, 67 'author' => 1, 68 'date' => 1, 69 'details' => 1, 70 'nosort' => 1, 71 'refresh' => 7200, 72 ]]], 73 ['document_end', []], 74 ]; 75 $this->assertCalls($calls, $this->H->calls); 76 } 77 78 function testRssRefreshDays() 79 { 80 $this->P->parse('{{rss>http://example.com/feed 1d}}'); 81 $calls = [ 82 ['document_start', []], 83 ['rss', ['http://example.com/feed', [ 84 'max' => 8, 85 'reverse' => 0, 86 'author' => 0, 87 'date' => 0, 88 'details' => 0, 89 'nosort' => 0, 90 'refresh' => 86400, 91 ]]], 92 ['document_end', []], 93 ]; 94 $this->assertCalls($calls, $this->H->calls); 95 } 96 97 function testRssRefreshMinimum() 98 { 99 $this->P->parse('{{rss>http://example.com/feed 1m}}'); 100 $calls = [ 101 ['document_start', []], 102 ['rss', ['http://example.com/feed', [ 103 'max' => 8, 104 'reverse' => 0, 105 'author' => 0, 106 'date' => 0, 107 'details' => 0, 108 'nosort' => 0, 109 'refresh' => 600, 110 ]]], 111 ['document_end', []], 112 ]; 113 $this->assertCalls($calls, $this->H->calls); 114 } 115 116 function testRssDetailAlias() 117 { 118 $this->P->parse('{{rss>http://example.com/feed detail}}'); 119 $calls = [ 120 ['document_start', []], 121 ['rss', ['http://example.com/feed', [ 122 'max' => 8, 123 'reverse' => 0, 124 'author' => 0, 125 'date' => 0, 126 'details' => 1, 127 'nosort' => 0, 128 'refresh' => 14400, 129 ]]], 130 ['document_end', []], 131 ]; 132 $this->assertCalls($calls, $this->H->calls); 133 } 134 135 function testRssAuthorAlias() 136 { 137 $this->P->parse('{{rss>http://example.com/feed by}}'); 138 $calls = [ 139 ['document_start', []], 140 ['rss', ['http://example.com/feed', [ 141 'max' => 8, 142 'reverse' => 0, 143 'author' => 1, 144 'date' => 0, 145 'details' => 0, 146 'nosort' => 0, 147 'refresh' => 14400, 148 ]]], 149 ['document_end', []], 150 ]; 151 $this->assertCalls($calls, $this->H->calls); 152 } 153 154 function testRssNotMatched() 155 { 156 $this->P->parse('Foo {{rss>}} Bar'); 157 $calls = [ 158 ['document_start', []], 159 ['p_open', []], 160 ['cdata', ["\nFoo {{rss>}} Bar"]], 161 ['p_close', []], 162 ['document_end', []], 163 ]; 164 $this->assertCalls($calls, $this->H->calls); 165 } 166} 167