orig_user = $user;
$prefs['site_language'] = 'en';
/* Need to set those global vars to be able to create and delete pages */
$_SERVER['HTTP_HOST'] = 'localhost';
$_SERVER['REQUEST_URI'] = 'phpunit';
$user = "user_that_can_edit";
/* Remove all translationof relations */
//
}
protected function tearDown(): void
{
global $user, $testhelpers;
$testhelpers->removeAllVersions($this->page_containing_plugin);
unset($_SERVER['HTTP_HOST'], $_SERVER['REQUEST_URI']);
$user = $this->orig_user;
}
/**
* @dataProvider provider
* @param $data
* @param $expectedOutput
* @param array $params
* @param string $message
*/
public function testWikiPluginTranslationOf($data, $expectedOutput, $params = [], $message = ""): void
{
$this->assertEquals($expectedOutput, wikiplugin_translationof($data, $params), $message);
}
public function provider(): array
{
return [
['', 'SomePage',
['orig_page' => 'SomePage', 'translation_lang' => 'fr'],
"Happy Path Case"],
['', 'UnePage',
['orig_page' => 'SomePage', 'translation_lang' => 'fr', 'translation_page' => 'UnePage'],
"Case with name of translated page provided"],
];
}
public function testCreatePageThatContainsAtranslationOfPluginGeneratesAnObjectRelation(): void
{
global $prefs;
$tikilib = TikiLib::lib('tiki');
$relationlib = TikiLib::lib('relation');
// Make sure the page doesn't exist to start with.
$tikilib->remove_all_versions($this->page_containing_plugin);
$link_source_page = "SourcePage";
$link_target_page = "TargetPage";
$relation_id = $relationlib->get_relation_id('tiki.wiki.translationof', 'wiki page', $this->page_containing_plugin, 'wiki page', $link_target_page);
$this->assertFalse(
$relation_id,
"Before creating a page that contains a TranslationOf plugin, there should NOT have been a 'translationof' relation from $this->page_containing_plugin to $link_target_page."
);
$page_containing_plugin_content = "{TranslationOf(orig_page=\"$link_source_page\" translation_page=\"$link_target_page\") /}";
$prefs['wikiplugin_translationof'] = 'y';
$prefs['feature_multilingual'] = 'y';
$tikilib->create_page($this->page_containing_plugin, 0, $page_containing_plugin_content, time(), "");
$relation_id = $relationlib->get_relation_id('tiki.wiki.translationof', 'wiki page', $this->page_containing_plugin, 'wiki page', $link_target_page);
$this->assertNotNull(
$relation_id,
"After we created a page that contains a TranslationOf plugin, there SHOULD have been a 'translationof' relation from $this->page_containing_plugin to $link_target_page."
);
}
}