/extensions/DSMW/tests/p2pAttachmentsTest5.php

https://github.com/ChuguluGames/mediawiki-svn · PHP · 353 lines · 171 code · 78 blank · 104 comment · 1 complexity · 8083d316c5b4e06e7148385abebd6e89 MD5 · raw file

  1. <?php
  2. if ( !defined( 'MEDIAWIKI' ) ) { define( 'MEDIAWIKI', true ); }
  3. require_once 'p2pBot.php';
  4. require_once 'BasicBot.php';
  5. include_once 'p2pAssert.php';
  6. require_once '../../../includes/GlobalFunctions.php';
  7. require_once '../patch/Patch.php';
  8. require_once '../files/utils.php';
  9. require_once 'settings.php';
  10. $wgDebugLogGroups = array(
  11. 'p2p' => "/tmp/p2p.log",
  12. );
  13. /**
  14. * Description of p2pAttachmentTest5
  15. *
  16. * @author Émile Morel
  17. */
  18. class p2pAttachmentsTest5 extends PHPUnit_Framework_TestCase {
  19. var $p2pBot1;
  20. var $p2pBot2;
  21. var $p2pBot3;
  22. var $wiki1 = WIKI1;
  23. var $wiki2 = WIKI2;
  24. var $wiki3 = WIKI3;
  25. var $pageName = "Ours";
  26. var $pushRequest = "[[Category:Animal]]";
  27. var $pushFeed = 'PushFeed:PushAnimal';
  28. var $pullFeed = 'PullFeed:PullAnimal';
  29. var $pushName = 'PushAnimal';
  30. var $pullName = 'PullAnimal';
  31. var $fileDir = 'Import/';
  32. var $file = 'Ours.pdf';
  33. var $filePage = 'File:Ours.pdf';
  34. var $file1 = 'ours1.pdf';
  35. var $file2 = 'ours2.pdf';
  36. var $file3 = 'ours3.pdf';
  37. var $file_size1;
  38. var $file_size2;
  39. var $file_size3;
  40. var $content = "Les ours (ou ursinés, du latin ŭrsus, de même sens) sont de grands
  41. mammifères plantigrades appartenant à la famille des ursidés. Il
  42. n'existe que huit espèces d'ours vivants, mais ils sont largement
  43. répandus et apparaissent dans une grande variété d'habitats, aussi
  44. bien dans l'hémisphère nord qu'une partie de l'hémisphère sud. Les
  45. ours vivent dans les continents d'Europe, d'Amérique du Nord,
  46. d'Amérique du Sud, et en Asie.
  47. [[Image:ours.pdf|right|frame|Un Ours]]
  48. [[Category:Animal]]";
  49. /**
  50. * Sets up the fixture, for example, opens a network connection.
  51. * This method is called before a test is executed.
  52. *
  53. * @access protected
  54. */
  55. protected function setUp() {
  56. exec( './initWikiTest.sh ./dump.sql' );
  57. exec( 'rm ./cache/*' );
  58. $basicbot1 = new BasicBot();
  59. $basicbot1->wikiServer = $this->wiki1;
  60. $this->p2pBot1 = new p2pBot( $basicbot1 );
  61. $basicbot2 = new BasicBot();
  62. $basicbot2->wikiServer = $this->wiki2;
  63. $this->p2pBot2 = new p2pBot( $basicbot2 );
  64. $basicbot3 = new BasicBot();
  65. $basicbot3->wikiServer = $this->wiki3;
  66. $this->p2pBot3 = new p2pBot( $basicbot3 );
  67. // trois fichiers images de tailles differentes pour les reconnaitres.
  68. $this->file_size1 = filesize( $this->fileDir . $this->file1 );
  69. $this->file_size2 = filesize( $this->fileDir . $this->file2 );
  70. $this->file_size3 = filesize( $this->fileDir . $this->file3 );
  71. }
  72. /**
  73. * Tears down the fixture, for example, closes a network connection.
  74. * This method is called after a test is executed.
  75. *
  76. * @access protected
  77. */
  78. protected function tearDown() {
  79. $this->viderRepertoire();
  80. // exec('./deleteTest.sh');
  81. }
  82. /**
  83. * Create one page with an attachment, push it
  84. * pull it on wiki2
  85. * modify the attachment on wiki2 , push it
  86. * pull it on wiki3
  87. * modify the attachment on wiki3 , push it
  88. * pull it on wiki1, push it
  89. * pull it on wiki2
  90. * the three wiki must have the same page an attachment
  91. */
  92. public function testSimple1() {
  93. // create page
  94. $this->assertTrue( $this->p2pBot1->createPage( $this->pageName, $this->content ),
  95. 'Failed to create page ' . $this->pageName . ' (' . $this->p2pBot1->bot->results . ')' );
  96. // assert page Ours exist on wiki1
  97. assertPageExist( $this->p2pBot1->bot->wikiServer, $this->pageName );
  98. // upload the file on wiki1
  99. $this->assertTrue( $this->p2pBot1->uploadFile( $this->fileDir . $this->file1, $this->file, '0' ) );
  100. // test if the good file was upload on wiki1 from wiki3
  101. $this->assertTrue( $this->p2pBot1->getFileFeatures( $this->file, $this->file_size1 ) );
  102. // edit File:Ours.jpg on wiki1
  103. $this->assertTrue( $this->p2pBot1->editPage( $this->filePage, $this->pushRequest ),
  104. 'failed to edit page ' . $this->filePage . ' ( ' . $this->p2pBot1->bot->results . ' )' );
  105. // create push on wiki1
  106. $this->assertTrue( $this->p2pBot1->createPush( $this->pushName, $this->pushRequest ),
  107. 'Failed to create push : ' . $this->pushName . ' (' . $this->p2pBot1->bot->results . ')' );
  108. // push
  109. $this->assertTrue( $this->p2pBot1->push( $this->pushFeed ),
  110. 'failed to push ' . $this->pushFeed . ' (' . $this->p2pBot2->bot->results . ')' );
  111. // create pull on wiki2
  112. $this->assertTrue( $this->p2pBot2->createPull( $this->pullName, $this->wiki1, $this->pushName ),
  113. 'failed to create pull ' . $this->pullName . ' (' . $this->p2pBot2->bot->results . ')' );
  114. // pull
  115. $this->assertTrue( $this->p2pBot2->Pull( $this->pullFeed ),
  116. 'failed to pull ' . $this->pullFeed . ' (' . $this->p2pBot2->bot->results . ')' );
  117. // change file on wiki2
  118. $this->assertTrue( $this->p2pBot2->uploadFile( $this->fileDir . $this->file2, $this->file, '1' ) );
  119. // test if the good file was upload on wiki2
  120. $this->assertTrue( $this->p2pBot2->getFileFeatures( $this->file, $this->file_size2 ) );
  121. // create push on wiki2
  122. $this->assertTrue( $this->p2pBot2->createPush( $this->pushName, $this->pushRequest ),
  123. 'Failed to create push : ' . $this->pushName . ' (' . $this->p2pBot2->bot->results . ')' );
  124. // push
  125. $this->assertTrue( $this->p2pBot2->push( $this->pushFeed ),
  126. 'failed to push ' . $this->pushFeed . ' (' . $this->p2pBot2->bot->results . ')' );
  127. // create pull on wiki3
  128. $this->assertTrue( $this->p2pBot3->createPull( $this->pullName, $this->wiki2, $this->pushName ),
  129. 'failed to create pull ' . $this->pullName . ' (' . $this->p2pBot3->bot->results . ')' );
  130. // pull
  131. $this->assertTrue( $this->p2pBot3->Pull( $this->pullFeed ),
  132. 'failed to pull ' . $this->pullFeed . ' (' . $this->p2pBot3->bot->results . ')' );
  133. // change file on wiki2
  134. $this->assertTrue( $this->p2pBot3->uploadFile( $this->fileDir . $this->file3, $this->file, '1' ) );
  135. // test if the good file was upload on wiki2
  136. $this->assertTrue( $this->p2pBot3->getFileFeatures( $this->file, $this->file_size3 ) );
  137. // create push on wiki3
  138. $this->assertTrue( $this->p2pBot3->createPush( $this->pushName, $this->pushRequest ),
  139. 'Failed to create push : ' . $this->pushName . ' (' . $this->p2pBot3->bot->results . ')' );
  140. // push
  141. $this->assertTrue( $this->p2pBot3->push( $this->pushFeed ),
  142. 'failed to push ' . $this->pushFeed . ' (' . $this->p2pBot3->bot->results . ')' );
  143. // create pull on wiki1 from wiki3
  144. $this->assertTrue( $this->p2pBot1->createPull( $this->pullName, $this->wiki3, $this->pushName ),
  145. 'failed to create pull ' . $this->pullName . ' (' . $this->p2pBot1->bot->results . ')' );
  146. // pull
  147. $this->assertTrue( $this->p2pBot1->Pull( $this->pullFeed ),
  148. 'failed to pull ' . $this->pullFeed . ' (' . $this->p2pBot1->bot->results . ')' );
  149. // test if the good file was upload on wiki1 from wiki3
  150. $this->assertTrue( $this->p2pBot1->getFileFeatures( $this->file, $this->file_size3 ) );
  151. // push
  152. $this->assertTrue( $this->p2pBot1->push( $this->pushFeed ),
  153. 'failed to push ' . $this->pushFeed . ' (' . $this->p2pBot2->bot->results . ')' );
  154. // pull
  155. $this->assertTrue( $this->p2pBot2->Pull( $this->pullFeed ),
  156. 'failed to pull ' . $this->pullFeed . ' (' . $this->p2pBot2->bot->results . ')' );
  157. // push
  158. $this->assertTrue( $this->p2pBot2->push( $this->pushFeed ),
  159. 'failed to push ' . $this->pushFeed . ' (' . $this->p2pBot2->bot->results . ')' );
  160. // pull
  161. $this->assertTrue( $this->p2pBot3->Pull( $this->pullFeed ),
  162. 'failed to pull ' . $this->pullFeed . ' (' . $this->p2pBot3->bot->results . ')' );
  163. $PatchonWiki1 = getSemanticRequest( $this->p2pBot1->bot->wikiServer, '[[Patch:+]][[onPage::' . $this->filePage . ']]', '-3FpatchID' );
  164. $PatchonWiki1 = arraytolower( $PatchonWiki1 );
  165. $PatchonWiki2 = getSemanticRequest( $this->p2pBot2->bot->wikiServer, '[[Patch:+]][[onPage::' . $this->filePage . ']]', '-3FpatchID' );
  166. $PatchonWiki2 = arraytolower( $PatchonWiki1 );
  167. $PatchonWiki3 = getSemanticRequest( $this->p2pBot3->bot->wikiServer, '[[Patch:+]][[onPage::' . $this->filePage . ']]', '-3FpatchID' );
  168. $PatchonWiki3 = arraytolower( $PatchonWiki1 );
  169. $this->assertEquals( count( $PatchonWiki1 ), count( $PatchonWiki2 ) );
  170. $this->assertEquals( count( $PatchonWiki1 ), count( $PatchonWiki3 ) );
  171. // assert that wiki1/File:Ours == wiki2/File:Ours
  172. assertContentEquals( $this->p2pBot1->bot->wikiServer, $this->p2pBot2->bot->wikiServer, $this->filePage );
  173. assertContentEquals( $this->p2pBot1->bot->wikiServer, $this->p2pBot3->bot->wikiServer, $this->filePage );
  174. }
  175. /**
  176. * Create one page with an attachment, push it
  177. * pull it on wiki2
  178. * modify the attachment on wiki2 , push it
  179. * pull it on wiki3
  180. * modify the attachment on wiki3 , push it
  181. * pull it on wiki2, push it
  182. * pull it on wiki1
  183. * the three wiki must have the same page an attachment
  184. */
  185. public function testSimple2() {
  186. // create page
  187. $this->assertTrue( $this->p2pBot1->createPage( $this->pageName, $this->content ),
  188. 'Failed to create page ' . $this->pageName . ' (' . $this->p2pBot1->bot->results . ')' );
  189. // assert page Ours exist on wiki1
  190. assertPageExist( $this->p2pBot1->bot->wikiServer, $this->pageName );
  191. // upload the file on wiki1
  192. $this->assertTrue( $this->p2pBot1->uploadFile( $this->fileDir . $this->file1, $this->file, '0' ) );
  193. // test if the good file was upload on wiki1 from wiki3
  194. $this->assertTrue( $this->p2pBot1->getFileFeatures( $this->file, $this->file_size1 ) );
  195. // edit File:Ours.jpg on wiki1
  196. $this->assertTrue( $this->p2pBot1->editPage( $this->filePage, $this->pushRequest ),
  197. 'failed to edit page ' . $this->filePage . ' ( ' . $this->p2pBot1->bot->results . ' )' );
  198. // create push on wiki1
  199. $this->assertTrue( $this->p2pBot1->createPush( $this->pushName, $this->pushRequest ),
  200. 'Failed to create push : ' . $this->pushName . ' (' . $this->p2pBot1->bot->results . ')' );
  201. // push
  202. $this->assertTrue( $this->p2pBot1->push( $this->pushFeed ),
  203. 'failed to push ' . $this->pushFeed . ' (' . $this->p2pBot2->bot->results . ')' );
  204. // create pull on wiki2
  205. $this->assertTrue( $this->p2pBot2->createPull( $this->pullName, $this->wiki1, $this->pushName ),
  206. 'failed to create pull ' . $this->pullName . ' (' . $this->p2pBot2->bot->results . ')' );
  207. // pull
  208. $this->assertTrue( $this->p2pBot2->Pull( $this->pullFeed ),
  209. 'failed to pull ' . $this->pullFeed . ' (' . $this->p2pBot2->bot->results . ')' );
  210. // change file on wiki2
  211. $this->assertTrue( $this->p2pBot2->uploadFile( $this->fileDir . $this->file2, $this->file, '1' ) );
  212. // test if the good file was upload on wiki2
  213. $this->assertTrue( $this->p2pBot2->getFileFeatures( $this->file, $this->file_size2 ) );
  214. // create push on wiki2
  215. $this->assertTrue( $this->p2pBot2->createPush( $this->pushName, $this->pushRequest ),
  216. 'Failed to create push : ' . $this->pushName . ' (' . $this->p2pBot2->bot->results . ')' );
  217. // push
  218. $this->assertTrue( $this->p2pBot2->push( $this->pushFeed ),
  219. 'failed to push ' . $this->pushFeed . ' (' . $this->p2pBot2->bot->results . ')' );
  220. // create pull on wiki3
  221. $this->assertTrue( $this->p2pBot3->createPull( $this->pullName, $this->wiki2, $this->pushName ),
  222. 'failed to create pull ' . $this->pullName . ' (' . $this->p2pBot3->bot->results . ')' );
  223. // pull
  224. $this->assertTrue( $this->p2pBot3->Pull( $this->pullFeed ),
  225. 'failed to pull ' . $this->pullFeed . ' (' . $this->p2pBot3->bot->results . ')' );
  226. // change file on wiki2
  227. $this->assertTrue( $this->p2pBot3->uploadFile( $this->fileDir . $this->file3, $this->file, '1' ) );
  228. // test if the good file was upload on wiki2
  229. $this->assertTrue( $this->p2pBot3->getFileFeatures( $this->file, $this->file_size3 ) );
  230. // create push on wiki3
  231. $this->assertTrue( $this->p2pBot3->createPush( $this->pushName, $this->pushRequest ),
  232. 'Failed to create push : ' . $this->pushName . ' (' . $this->p2pBot3->bot->results . ')' );
  233. // push
  234. $this->assertTrue( $this->p2pBot3->push( $this->pushFeed ),
  235. 'failed to push ' . $this->pushFeed . ' (' . $this->p2pBot3->bot->results . ')' );
  236. // create pull on wiki2 from wiki3
  237. $this->assertTrue( $this->p2pBot2->createPull( $this->pullName, $this->wiki3, $this->pushName ),
  238. 'failed to create pull ' . $this->pullName . ' (' . $this->p2pBot1->bot->results . ')' );
  239. // pull
  240. $this->assertTrue( $this->p2pBot2->Pull( $this->pullFeed ),
  241. 'failed to pull ' . $this->pullFeed . ' (' . $this->p2pBot1->bot->results . ')' );
  242. // test if the good file was upload on wiki1 from wiki3
  243. $this->assertTrue( $this->p2pBot2->getFileFeatures( $this->file, $this->file_size3 ) );
  244. // push
  245. $this->assertTrue( $this->p2pBot2->push( $this->pushFeed ),
  246. 'failed to push ' . $this->pushFeed . ' (' . $this->p2pBot2->bot->results . ')' );
  247. // create pull on wiki3
  248. $this->assertTrue( $this->p2pBot1->createPull( $this->pullName, $this->wiki2, $this->pushName ),
  249. 'failed to create pull ' . $this->pullName . ' (' . $this->p2pBot1->bot->results . ')' );
  250. // pull
  251. $this->assertTrue( $this->p2pBot1->Pull( $this->pullFeed ),
  252. 'failed to pull ' . $this->pullFeed . ' (' . $this->p2pBot2->bot->results . ')' );
  253. // test if the good file was upload on wiki1 from wiki3
  254. $this->assertTrue( $this->p2pBot1->getFileFeatures( $this->file, $this->file_size3 ) );
  255. $PatchonWiki1 = getSemanticRequest( $this->p2pBot1->bot->wikiServer, '[[Patch:+]][[onPage::' . $this->filePage . ']]', '-3FpatchID' );
  256. $PatchonWiki1 = arraytolower( $PatchonWiki1 );
  257. $PatchonWiki2 = getSemanticRequest( $this->p2pBot2->bot->wikiServer, '[[Patch:+]][[onPage::' . $this->filePage . ']]', '-3FpatchID' );
  258. $PatchonWiki2 = arraytolower( $PatchonWiki2 );
  259. $PatchonWiki3 = getSemanticRequest( $this->p2pBot3->bot->wikiServer, '[[Patch:+]][[onPage::' . $this->filePage . ']]', '-3FpatchID' );
  260. $PatchonWiki3 = arraytolower( $PatchonWiki3 );
  261. $this->assertEquals( count( $PatchonWiki1 ), count( $PatchonWiki2 ) );
  262. $this->assertEquals( count( $PatchonWiki1 ), count( $PatchonWiki3 ) );
  263. // assert that wiki1/File:Ours == wiki2/File:Ours == wiki3/File:Ours
  264. assertContentEquals( $this->p2pBot1->bot->wikiServer, $this->p2pBot2->bot->wikiServer, $this->filePage );
  265. assertContentEquals( $this->p2pBot1->bot->wikiServer, $this->p2pBot3->bot->wikiServer, $this->filePage );
  266. }
  267. function viderRepertoire() {
  268. }
  269. }
  270. ?>