1<?php 2// (c) Copyright by authors of the Tiki Wiki CMS Groupware Project 3// 4// All Rights Reserved. See copyright.txt for details and a complete list of authors. 5// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details. 6// $Id$ 7 8require_once(__DIR__ . '/../../wiki-plugins/wikiplugin_translationof.php'); 9require_once(__DIR__ . '/../../test/TestHelpers.php'); 10$relationlib = TikiLib::lib('relation'); 11 12class WikiPlugin_TranslationOfTest extends TikiTestCase 13{ 14 public $orig_user; 15 16 private $page_containing_plugin = "PageToBeCreated"; 17 18 protected function setUp() 19 { 20 global $user, $prefs; 21 $multilinguallib = TikiLib::lib('multilingual'); 22 $tikilib = TikiLib::lib('tiki'); 23 $this->orig_user = $user; 24 25 $prefs['site_language'] = 'en'; 26 27 28 /* Need to set those global vars to be able to create and delete pages */ 29 $_SERVER['HTTP_HOST'] = 'localhost'; 30 $_SERVER['REQUEST_URI'] = 'phpunit'; 31 $user = "user_that_can_edit"; 32 33 /* Remove all translationof relations */ 34 // 35 } 36 37 protected function tearDown() 38 { 39 global $tikilib, $user, $testhelpers; 40 41 $testhelpers->remove_all_versions($this->page_containing_plugin); 42 43 unset($_SERVER['HTTP_HOST']); 44 unset($_SERVER['REQUEST_URI']); 45 $user = $this->orig_user; 46 } 47 48 /** 49 * @dataProvider provider 50 * @group marked-as-skipped 51 */ 52 public function testWikiPlugin_TranslationOf($data, $expectedOutput, $params = [], $message = "") 53 { 54 $this->markTestSkipped('SkipBroken: 2017-10-14, wikiplugin_translationof broken with commit https://sourceforge.net/p/tikiwiki/code/62640/'); 55 $this->assertEquals($expectedOutput, wikiplugin_translationof($data, $params), $message); 56 } 57 58 public function provider() 59 { 60 return [ 61 ['', '<a href="tiki-index.php?page=SomePage" data-toggle="popover" data-container="body" data-trigger="click" data-content="<a href=\"tiki-edit_translation.php?page=SomePage&target_lang=fr#new_translation\">Translate this link</a>" data-delay=\'{"show":"0","hide":"10"}\'>SomePage</a>', 62 ['orig_page' => 'SomePage', 'translation_lang' => 'fr'], 63 "Happy Path Case"], 64 ['', '<a href="tiki-index.php?page=SomePage" data-toggle="popover" data-container="body" data-trigger="click" data-content="<a href=\"tiki-edit_translation.php?page=SomePage&target_lang=fr&translation_name=UnePage#new_translation\">Translate this link</a>" data-delay=\'{"show":"0","hide":"10"}\'>UnePage</a>', 65 ['orig_page' => 'SomePage', 'translation_lang' => 'fr', 'translation_page' => 'UnePage'], 66 "Case with name of translated page provided"], 67 ]; 68 } 69 70 public function test_create_page_that_contains_a_TranslationOf_plugin_generates_an_object_relation() 71 { 72 global $prefs; 73 $tikilib = TikiLib::lib('tiki'); 74 $relationlib = TikiLib::lib('relation'); 75 $testhelpers = new TestHelpers(); 76 77 // Make sure the page doesn't exist to start with. 78 $tikilib->remove_all_versions($this->page_containing_plugin); 79 80 $link_source_page = "SourcePage"; 81 $link_target_page = "TargetPage"; 82 83 $relation_id = $relationlib->get_relation_id('tiki.wiki.translationof', 'wiki page', $this->page_containing_plugin, 'wiki page', $link_target_page); 84 $this->assertTrue( 85 $relation_id == null, 86 "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." 87 ); 88 89 $page_containing_plugin_content = "{TranslationOf(orig_page=\"$link_source_page\" translation_page=\"$link_target_page\") /}"; 90 $prefs['wikiplugin_translationof'] = 'y'; 91 $prefs['feature_multilingual'] = 'y'; 92 93 $tikilib->create_page($this->page_containing_plugin, 0, $page_containing_plugin_content, time(), ""); 94 95 $relation_id = $relationlib->get_relation_id('tiki.wiki.translationof', 'wiki page', $this->page_containing_plugin, 'wiki page', $link_target_page); 96 $this->assertTrue( 97 $relation_id != null, 98 "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." 99 ); 100 } 101} 102