setPageRegex();
parent::__construct();
}
protected function setUp(): void
{
$_SERVER['HTTP_HOST'] = ''; // editlib expects that HTTP_HOST is defined
$_SERVER['SERVER_NAME'] = 'myserver'; // the ParserLib expects the servername to be set
global $prefs;
$prefs['feature_sefurl'] = 'n'; // default
$this->el = TikiLib::lib('edit');
}
/**
* remove the external Wikis defined in the tests
*/
protected function tearDown(): void
{
$tikilib = TikiLib::lib('tiki');
$query = 'SELECT `name`, `extwikiId` FROM `tiki_extwiki`';
$wikis = $tikilib->fetchMap($query);
$tmp_wikis = [$this->ext1];
foreach ($tmp_wikis as $w) {
if (isset($wikis[$w])) {
$id = $wikis[$w];
$tikilib::lib('admin')->remove_extwiki($id);
}
}
}
/**
* Test links to pages of an external Wiki
*
* This test is used to detect changes in the parser. Here, the EditLib is not used.
*
* Note: Links with an invalid wiki identifier are parsed as regular Wiki page links.
*/
public function testExternalWiki(): void
{
/*
* setup the external wikis and the parser
*/
$tikilib = TikiLib::lib('tiki');
$tikilib::lib('admin')->replace_extwiki(0, 'http://tikiwiki.org/tiki-index.php?page=$page', $this->ext1);
$p = $tikilib::lib('parser');
/*
* External Wiki
* - page name
*/
$inData = "(($this->ext1:Download))";
$ex = 'Download';
$out = trim($p->parse_data($inData));
$this->assertStringContainsString($ex, $out);
/*
* External Wiki
* - page name
* - anchor
*/
$inData = "(($this->ext1:Download|#LTS_-_the_Long_Term_Support_release))";
$ex = 'Download';
$out = trim($p->parse_data($inData));
$this->assertStringContainsString($ex, $out);
/*
* External Wiki
* - page name
* - anchor
* - description
*/
$inData = "(($this->ext1:Download|#LTS_-_the_Long_Term_Support_release|Download LTS))";
$ex = 'Download LTS';
$out = trim($p->parse_data($inData));
$this->assertStringContainsString($ex, $out);
}
/**
* Test link to anchor within a page
*/
public function testInPage(): void
{
/*
* with description
*/
$inData = '[#A_Heading|Link to heading]';
$ex = 'Link to heading';
$out = trim($this->el->parseToWysiwyg($inData));
$out = preg_replace('/ {2}/', ' ', $out); // the parser writes to many spaces
$this->assertStringContainsString($ex, $out);
/*
* no description
*/
$inData = '[#A_Heading]';
$ex = '#A_Heading';
$out = trim($this->el->parseToWysiwyg($inData));
$out = preg_replace('/ {2}/', ' ', $out); // the parser writes to many spaces
$this->assertStringContainsString($ex, $out);
}
/**
* Test link for creating e-mail
*/
public function testMailTo(): void
{
/*
* e-mail
*/
$inData = '[mailto:sombody@nowhere.xyz]';
$ex = 'mailto:sombody@nowhere.xyz';
$out = trim($this->el->parseToWysiwyg($inData));
$this->assertStringContainsString($ex, $out);
/*
* e-mail with description
*/
$inData = '[mailto:sombody@nowhere.xyz|Mail to "Somebody"]';
$ex = 'Mail to "Somebody"';
$out = trim($this->el->parseToWysiwyg($inData));
$this->assertStringContainsString($ex, $out);
}
/**
* Test links to articles, blogs, ...
*/
public function testOtherTikiPages(): void
{
/*
* article
*/
$inData = '[article1]';
$ex = 'article1';
$out = trim($this->el->parseToWysiwyg($inData));
$this->assertStringContainsString($ex, $out);
$inData = '[article1|An Article]';
$ex = 'An Article';
$out = trim($this->el->parseToWysiwyg($inData));
$this->assertStringContainsString($ex, $out);
/*
* blog
*/
$inData = '[blog1]';
$ex = 'blog1';
$out = trim($this->el->parseToWysiwyg($inData));
$this->assertStringContainsString($ex, $out);
$inData = '[blog1|A Blog]';
$ex = 'A Blog';
$out = trim($this->el->parseToWysiwyg($inData));
$this->assertStringContainsString($ex, $out);
/*
* forum
*/
$inData = '[forum1]';
$ex = 'forum1';
$out = trim($this->el->parseToWysiwyg($inData));
$this->assertStringContainsString($ex, $out);
$inData = '[forum1|A Forum]';
$ex = 'A Forum';
$out = trim($this->el->parseToWysiwyg($inData));
$this->assertStringContainsString($ex, $out);
}
/**
* Test links to web pages
*
*/
public function testWebResource(): void
{
/* $this->markTestSkipped(
"As of 2013-10-02, this test is broken, and nobody knows how to fix it. Mark as Skipped for now."
);*/
/*
* Web Page:
* - link
*/
$inData = '[http://www.tiki.org]';
$ex = 'http://www.tiki.org';
$out = trim($this->el->parseToWysiwyg($inData));
$this->assertStringContainsString($ex, $out);
/*
* Web Page:
* - link
* - description
*/
$inData = '[http://www.tiki.org|Tiki Wiki CMS Groupware]';
$ex = 'Tiki Wiki CMS Groupware';
$out = trim($this->el->parseToWysiwyg($inData));
$this->assertStringContainsString($ex, $out);
/*
* Web Page:
* - link
* - description
* - anchor
*/
$inData = '[http://www.tiki.org#Tiki_News_|News of the Tiki Wiki CMS Groupware]';
$ex = 'News of the Tiki Wiki CMS Groupware';
$out = trim($this->el->parseToWysiwyg($inData));
$this->assertStringContainsString($ex, $out);
/*
* Web Page:
* - link
* - description
* - anchor
* - box
*/
$inData
= '[http://www.tiki.org#Tiki_News_|News of the Tiki Wiki CMS Groupware|box]';
$ex = 'News of the Tiki Wiki CMS Groupware';
$out = trim($this->el->parseToWysiwyg($inData));
$this->assertStringContainsString($ex, $out);
/*
* Link to video
* - link
*
*/
$inData = '[http://www.youtube.com/v/KBewVCducWw&autoplay=1|nocache]';
$ex = 'http://www.youtube.com/v/KBewVCducWw&autoplay=1';
$out = trim($this->el->parseToWysiwyg($inData));
$this->assertStringContainsString($ex, $out);
/*
* Link to video
* - link
* - description
*/
$inData
= '[http://www.youtube.com/v/KBewVCducWw&autoplay=1|You Tube video in their flash player|nocache]';
$ex
= 'You Tube video in their flash player';
$out = trim($this->el->parseToWysiwyg($inData));
$this->assertStringContainsString($ex, $out);
/*
* Link to video
* - link
* - description
* - box
*/
$inData
= '[http://www.youtube.com/v/KBewVCducWw&autoplay=1|You Tube video in their flash player|box]'; // additional nocache does not work
$ex
= 'You Tube video in their flash player';
$out = trim($this->el->parseToWysiwyg($inData));
$this->assertStringContainsString($ex, $out);
}
/**
* Test links to internal wiki pages
*
* @group marked-as-skipped
*/
public function testWikiPage(): void
{
$tikilib = TikiLib::lib('tiki');
$this->markTestSkipped(
"As of 2013-10-02, this test is broken, and nobody knows how to fix it. Mark as Skipped for now."
);
$homePage = 'HomePage';
$noPage = 'Page does not exist not exist';
/*
* - existing page
*/
$inData = "(($homePage))";
$ex = 'HomePage';
$out = trim($this->el->parseToWysiwyg($inData));
$this->assertStringContainsString($ex, $out);
/*
* - existing page
* - description
*/
$inData = "(($homePage|The Home Page))";
$ex = 'The Home Page';
$out = trim($this->el->parseToWysiwyg($inData));
$this->assertStringContainsString($ex, $out);
/*
* - existing name
* - link to an anchor
* - description
*/
$inData = "(($homePage|#Get_Started_using_Admin_Panel|Home Page, Heading \"Admin Panel\"))";
$ex = 'Home Page, Heading "Admin Panel"';
$out = trim($this->el->parseToWysiwyg($inData));
$this->assertStringContainsString($ex, $out);
/*
* Default behavior -> class="wiki wikinew"
*
* - inexistent page
*/
$inData = "(($noPage))";
$ex = 'Page does not exist not exist?';
$out = trim($tikilib::lib('parser')->parse_Data($inData));
$this->assertStringContainsString($ex, $out);
/*
* Default behavior -> class="wiki wikinew"
*
* - inexistent page
* - description
*/
$inData = "(($noPage|Page does not exist))";
$ex = 'Page does not exist?';
$out = trim($tikilib::lib('parser')->parse_Data($inData));
$this->assertStringContainsString($ex, $out);
/*
* Default behavior -> class="wiki wikinew"
*
* - inexistent page
* - link to an anchor
* - description
*/
$inData = "(($noPage|#anchor|Page does not exist))";
$ex = 'Page does not exist?';
$out = trim($tikilib::lib('parser')->parse_Data($inData));
$this->assertStringContainsString($ex, $out);
/*
* CKE behavior -> class="wiki page"
* - inexistent page
*/
$inData = "(($noPage))";
$ex = 'Page does not exist not exist';
$out = trim($this->el->parseToWysiwyg($inData));
$this->assertStringContainsString($ex, $out);
/*
* CKE behavior -> class="wiki page"
*
* - inexistent page
* - description
*/
$inData = "(($noPage|Page does not exist))";
$ex = 'Page does not exist';
$out = trim($this->el->parseToWysiwyg($inData));
$this->assertStringContainsString($ex, $out);
/*
* CKE behavior -> class="wiki page"
*
* - inexistent page
* - link to an anchor
* - description
*/
$inData = "(($noPage|#anchor|Page does not exist))";
$ex = 'Page does not exist';
$out = trim($this->el->parseToWysiwyg($inData));
$this->assertStringContainsString($ex, $out);
/*
* Internation characters
*/
$inData = "((äöü€ Page))";
$ex = 'äöü€ Page';
$out = trim($this->el->parseToWysiwyg($inData));
$this->assertStringContainsString($ex, $out);
}
/**
* Test anchors generated by {ANAME}
*
* @group marked-as-incomplete
*/
public function testPluginAname(): void
{
$this->markTestIncomplete('Work in progress.');
$inData = "{ANAME()}anchor{ANAME}";
$ex = '';
$out = trim($this->el->parseToWysiwyg($inData));
$this->assertEquals($ex, $out);
}
}