The module should have a basic test that checks the submission of translation suggestions to a l10n server.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

s_leu’s picture

Status: Active » Needs review
FileSize
6.52 KB

Here's a first patch that uses mocking of the server response to test submissions.

Berdir’s picture

Status: Needs review » Needs work
+++ b/l10n_client.testundefined
@@ -0,0 +1,121 @@
+      'source' => 'Content', // Source string that gets translated.
+      'target' => 'Translation suggestion for Content', // Translation suggestion.

Nitpick: comments should be above the code.

+++ b/l10n_client.testundefined
@@ -0,0 +1,121 @@
+    $this->resetAll();

refreshVariables() should be enough.

+++ b/l10n_client.testundefined
@@ -0,0 +1,121 @@
+    $this->assertTrue(strpos($response, 'Translation sent and accepted by') > 0, 'Translation sent abd accepted by the server.');

and

+++ b/l10n_client.testundefined
@@ -0,0 +1,121 @@
+    // Assert basic structure of the saved data.
+    $this->assertTrue(!empty($saved_xml));

I don't think that assertTrue() is necessary/can fail. If anything, it would need to check $saved. But checking the specific properties should be enough I think.

+++ b/l10n_client.testundefined
@@ -0,0 +1,121 @@
+    // Assert values in saved data.
+    $this->assertEqual((string)$saved_xml->params[0]->param[0]->value->string, 'en', 'Source language parameter is correct.');
+    $this->assertEqual((string)$saved_xml->params[0]->param[1]->value->string, $post['source'], 'Source string parameter is correct.');
+    $this->assertEqual((string)$saved_xml->params[0]->param[2]->value->string, $post['target'], 'Suggestion string parameter is correct.');

Don't know enough about xml rpc to say if it's reliable to rely on the order. I assume they also have a name? then probably rely on that using Xpath.

s_leu’s picture

Status: Needs work » Needs review
FileSize
7.17 KB

"I assume they also have a name" No they don't. The output of the saved data looks like this:

<?xml version="1.0"?>
<methodCall>
<methodName>l10n.submit.translation</methodName>
<params>
<param><value><string>en</string></value></param>
<param><value><string>Content</string></value></param>
<param><value><string>Translation suggestion for Content</string></value></param>
<param><value><int>5</int></value></param>
<param><value><string>1d4b427b4192fdfb0fde6347160785f4</string></value></param>
<param><value><string>c2d16e9ff85644ed118a8c460c5c0618</string></value></param>
</params></methodCall>'

I also added a test that checks if the translation gets stored locally.

Berdir’s picture

Test looks good to me, let's enable testbot for commits/issues to see if this works there as well.

Gábor Hojtsy’s picture

Enabled testing for issues. Lets see if that kicks in here too :)

SebCorbin’s picture

Status: Needs review » Needs work

The last submitted patch, suggestion-submission-test-2045609-3.patch, failed testing.

SebCorbin’s picture

Status: Needs work » Fixed

Re-rolled and committed, thanks!

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.