Permalink
Browse files

Fix tests for adapter and mediawiki.

  • Loading branch information...
jimsafley committed Mar 14, 2012
1 parent d5bb3a2 commit d5be4ed349a8a42c3c33b6d1532e6fed8b191de8
Showing with 30 additions and 64 deletions.
  1. +1 −1 tests/adapter_test.php
  2. +29 −63 tests/mediawiki_test.php
View
@@ -73,7 +73,7 @@ public function testDocumentPagesAreValid()
// Assert document page URLs are valid. There's no consistant,
// reliable, and lightweight way to validate a URL, even with
// regular expressions, so just check to see if it returns a string.
- $documentPageImageUrl = $this->_testAdapter->getDocumentPageImageUrl($this->_testDocumentId, $pageId);
+ $documentPageImageUrl = $this->_testAdapter->getDocumentPageFileUrl($this->_testDocumentId, $pageId);
$this->assertIsA($documentPageImageUrl, 'string', "Document page image URL for page ID \"$pageId\" must be a string. " . gettype($documentPageImageUrl) . " given");
}
}
View
@@ -28,11 +28,6 @@ class TestMediawiki extends UnitTestCase
<sup>Superscript text</sup>
<sub>Subscript text</sub>
<small>Small Text</small>
-<!-- Comment -->
-<gallery>
-Image:Example.jpg|Caption1
-Image:Example.jpg|Caption2
-</gallery>
<blockquote>
Block quote
</blockquote>
@@ -58,7 +53,7 @@ class TestMediawiki extends UnitTestCase
*/
const TEST_EXPECTED_HTML = '<p><b>Bold text</b>
<i>Italic text</i>
-<a href="http://www.example.com" class="external text" rel="nofollow">link title</a>
+<a rel="nofollow" class="external text" href="http://www.example.com">link title</a>
</p>
<h2> <span class="mw-headline" id="Headline_text"> Headline text </span></h2>
<p>Insert non-formatted text here
@@ -70,43 +65,31 @@ class TestMediawiki extends UnitTestCase
<sub>Subscript text</sub>
<small>Small Text</small>
</p>
-<table class="gallery" cellspacing="0" cellpadding="0">
- <tr>
- <td><div class="gallerybox" style="width: 155px;">
- <div style="height: 152px;">Example.jpg</div>
- <div class="gallerytext">
-<p>Caption1
-</p>
- </div>
- </div></td>
- <td><div class="gallerybox" style="width: 155px;">
- <div style="height: 152px;">Example.jpg</div>
- <div class="gallerytext">
-<p>Caption2
-</p>
- </div>
- </div></td>
- </tr>
-</table>
<blockquote>
Block quote
</blockquote>
<table class="wikitable">
<tr>
<th> header 1
-</th><th> header 2
-</th><th> header 3
+</th>
+<th> header 2
+</th>
+<th> header 3
</th></tr>
<tr>
<td> row 1, cell 1
-</td><td> row 1, cell 2
-</td><td> row 1, cell 3
+</td>
+<td> row 1, cell 2
+</td>
+<td> row 1, cell 3
</td></tr>
<tr>
<td> row 2, cell 1
-</td><td> row 2, cell 2
-</td><td> row 2, cell 3
+</td>
+<td> row 2, cell 2
+</td>
+<td> row 2, cell 3
</td></tr></table>
@@ -127,65 +110,48 @@ public function __construct()
// Do not pass cookies to a browser when testing.
require_once 'Scripto/Service/MediaWiki.php';
- $this->_testMediawiki = new Scripto_Service_MediaWiki(TEST_MEDIAWIKI_API_URL,
- TEST_MEDIAWIKI_DB_NAME,
- false);
+ $this->_testMediawiki = new Scripto_Service_MediaWiki(TEST_MEDIAWIKI_API_URL, false);
}
public function testCredentials()
{
- // Assert credentials are valid.
- $editCredentials = $this->_testMediawiki->getEditCredentials(self::TEST_TITLE);
- $this->assertTrue((is_array($editCredentials) || is_null($editCredentials)), 'Edit credentials must be NULL or an array. ' . gettype($editCredentials) . ' given');
-
- // Test login and logout if credentials are required.
- if (is_null($editCredentials)) {
+ // Test login and logout if username and password is provided.
+ if (TEST_MEDIAWIKI_USERNAME && TEST_MEDIAWIKI_PASSWORD) {
- // Assert login works.
+ // Assert login works. Throws an error if login is unsuccessful.
$this->_testMediawiki->login(TEST_MEDIAWIKI_USERNAME, TEST_MEDIAWIKI_PASSWORD);
- $editCredentials = $this->_testMediawiki->getEditCredentials(self::TEST_TITLE);
- $this->assertTrue(is_array($editCredentials), 'Login did not work');
// Assert logout works.
$this->_testMediawiki->logout();
- $editCredentials = $this->_testMediawiki->getEditCredentials(self::TEST_TITLE);
- $this->assertTrue(is_null($editCredentials), 'Logout did not work');
-
- // Login and get credentials again to continue testing.
- $this->_testMediawiki->login(TEST_MEDIAWIKI_USERNAME, TEST_MEDIAWIKI_PASSWORD);
- $editCredentials = $this->_testMediawiki->getEditCredentials(self::TEST_TITLE);
+ $userInfo = $this->_testMediawiki->getUserInfo();
+ $this->assertTrue(isset($userInfo['query']['userinfo']['anon']), 'Logout unsuccessful');
}
-
- // Assert credential keys are valid.
- $this->assertTrue(array_key_exists('edittoken', $editCredentials), 'Edit credentials array must contain a "edittoken" key');
- $this->assertTrue(array_key_exists('basetimestamp', $editCredentials), 'Edit credentials array must contain a "basetimestamp" key');
}
public function testEditPage()
{
- // Assert the test page's preview is valid. Remove dynamic HTML
- // comments.
+ // Assert the test page's preview is valid. Remove dynamic HTML comments.
$testPagePreview = $this->_testMediawiki->getPreview(self::TEST_WIKITEXT);
- $this->assertTrue(self::TEST_EXPECTED_HTML == $this->_removeHtmlComments($testPagePreview), 'The test page preview HTML is invalid');
+ $this->assertEqual(self::TEST_EXPECTED_HTML, $this->_removeHtmlComments($testPagePreview), 'The test page preview HTML is invalid');
// Clear the page before testing edit page. Resetting the database or
// deleting the page is preferable, but resetting is too involved and
// Scripto_Service_MediaWiki does not implement a delete page feature
// because deleting requires special (sysops) permissions.
- $this->_testMediawiki->editPage(self::TEST_TITLE, '');
- $text = $this->_testMediawiki->getPageWikitext(self::TEST_TITLE);
- $this->assertTrue('' == $text, 'Clearing the test page did not work');
+ $this->_testMediawiki->edit(self::TEST_TITLE, '.');
+ $text = $this->_testMediawiki->getLatestRevisionWikitext(self::TEST_TITLE);
+ $this->assertEqual('.', $text, 'Clearing the test page did not work');
// Edit the page with test text.
- $this->_testMediawiki->editPage(self::TEST_TITLE, self::TEST_WIKITEXT);
+ $this->_testMediawiki->edit(self::TEST_TITLE, self::TEST_WIKITEXT);
// Assert the test page's Wikitext is valid.
- $textPageWikitext = $this->_testMediawiki->getPageWikitext(self::TEST_TITLE);
- $this->assertTrue(self::TEST_WIKITEXT == $textPageWikitext, 'Editing the test page with test wikitext did not work ');
+ $textPageWikitext = $this->_testMediawiki->getLatestRevisionWikitext(self::TEST_TITLE);
+ $this->assertEqual(self::TEST_WIKITEXT, $textPageWikitext, 'Editing the test page with test wikitext did not work ');
// Assert the test page's HTML is valid. Remove dynamic HTML comments.
- $testPageHtml = $this->_testMediawiki->getPageHtml(self::TEST_TITLE);
- $this->assertTrue(self::TEST_EXPECTED_HTML == $this->_removeHtmlComments($testPageHtml), 'The test page HTML is invalid');
+ $testPageHtml = $this->_testMediawiki->getLatestRevisionHtml(self::TEST_TITLE);
+ $this->assertEqual(self::TEST_EXPECTED_HTML, $this->_removeHtmlComments($testPageHtml), 'The test page HTML is invalid');
}

0 comments on commit d5be4ed

Please sign in to comment.