GHOP task #130: Write Simpletest tests for Content translation module

Gábor Hojtsy - January 7, 2008 - 20:11
Project:SimpleTest
Version:6.x-1.x-dev
Component:Code
Category:task
Priority:normal
Assigned:Unassigned
Status:closed
Issue tags:GHOP
Description

On request from chx based on http://code.google.com/p/google-highly-open-participation-drupal/issues/...

Drupal 6 supports content (node) translation out of the box with the included
content translation module. This task is to write unit tests to ensure this
functionality works.

The Simpletest module provides a framework for running automated unit
tests in Drupal. Unit testing involves taking a small portion of code, a
unit, and subjecting it to programmatic tests to prove its correctness.
This can be extremely useful to help insure that new code does not
introduce bugs into existing functionality. Thus, having a full suite of
unit tests for Drupal 6.x core functionality using the Simpletest module
would be a major step forward for the project and would help insure that
only high-quality code is committed. In addition to helping developers
test their code, new tests for core Drupal functionality will be used for
automated testing by http://testing.drupal.org.

For this task, you need to first install and familiarize yourself with the
simpletest module (use the cvs HEAD version with Drupal HEAD/6.x RC):
http://drupal.org/project/simpletest
http://drupal.org/simpletest
http://www.lullabot.com/articles/introduction-unit-testing

The main work for this task is to write a small suite of tests to check
the functionality of translation module with a test site setup to have at
least two languages and both locale and translation module enabled. The
test case should:
* set the Story content type to be multilanguage enabled with translation
* create a story in one of the languages
* submit a translation of the story in one of the other languages
* update the original story and mark the translation outdated
* update the translation and mark it as up-to-date

Proper validation of your new tests will ideally include changing the
Drupal core code to break the tested functionality and then confirming
that your tests report a failure. Ideally, post each such change as a
patch to help the reviewers.

This suite should be written as a single .test file and should achieve
RTBC status in the Simpletest module issue queue.

#1

chx - January 7, 2008 - 21:30
Title:Write Simpletest tests for Content translation module» GHOP task #130: Write Simpletest tests for Content translation module

#2

aclight - January 7, 2008 - 21:33

The official GHOP task related to this issue can be found at:
http://code.google.com/p/google-highly-open-participation-drupal/issues/...

#3

webchick - January 8, 2008 - 03:36
Project:Google Highly Open Participation Contest (GHOP)» SimpleTest
Version:<none>» 6.x-1.x-dev
Component:Task idea» Code

Moving to SimpleTest queue.

#4

boombatower - January 12, 2008 - 06:01
Status:active» needs review

After having a few problems I was able to come up with a solution, in part thanks to figuring out what wasn't causing it with cwgordon7 in IRC. To complete my task I created a patch for the drupal_test_case.php file.

I believe the submission meets all the requirements, but I am not sure if there is a way to do it without the patch.

AttachmentSize
drupal_test_case.php_.patch 881 bytes
translation_module.test_.txt 4.76 KB

#5

Rok Žlender - January 12, 2008 - 20:36
Status:needs review» needs work

As always you have produced a great test. My comments:

  • you can use $this->assertTrue(TRUE, "") to output a log msg, your way works too its just harder to read. I tested it and it worked.
  • On line 107 and 131 of your test file you complicate things a bit too much. You can simply do $this->assertTrue($node, 'Node found in database.'); if node is not found it will be set to false and this assertions will catch it
  • I'd like to see more assertions, after every drupalPostRequest drupal output some sort of notice please use $this->assertText() to see if that is really the case i.e. after creating node $this->assertText("Story $title has been created.") it is much easier to find errrors if there are more assertions and log msgs.

I've put your drupalGet change into its own issue so it doesn't get overlooked. I'll commit it together with your test when you fix ^^.

#6

boombatower - January 12, 2008 - 21:04
Status:needs work» needs review

I believe I fixed everything you requested.

I didn't use $this->assertText() since I used the t() around the messages since they are core messages are translated depending on the environment. t() adds HTML so I used $this->assertWantedRaw().

AttachmentSize
translation_module3.test_.txt 5.72 KB

#7

Gábor Hojtsy - January 13, 2008 - 21:48
Status:needs review» needs work

Some comments:

- code looks good
- there are some coding stye mistakes (dots and whitespace; comments should start with capital letters and end in a dot)
- "create store in english" :)
- after you edit the translation, let's check the translations tab and see whether it shows that the translation was marked outdated, this is quite important functionality to validate
- You use t() like t('The language %lang has been created and can now be used.', ...) but my quick grep did not show and such string in Drupal 6. I found t('The language %language has been created and can now be used. More information is available on the help screen.', ...) though. When you use t(), if you intend to actually get a translation, you should use the exact same string, or your test will fail unless it runs on an English interface. (Looks like your test does not make sure it runs on an English site, rightly so :) Note that I did not check all strings but this caught my attention.

#8

boombatower - January 14, 2008 - 02:05
Status:needs work» needs review

I believe I fixed all the requested items.

  • Fixed comments.
  • Check that the translation was market as outdated.
  • Fixed partial interface text.

Just as a note the accompanying patch is located here: http://drupal.org/node/209297.

AttachmentSize
translation_module4.test_.txt 6.06 KB

#9

Gábor Hojtsy - January 16, 2008 - 20:04
Status:needs review» needs work

There are still coding style issues in the test (just run coder module on it), but otherwise looks good to me on review. As far as I see, just fix the style issues and then get this RTBC.

#10

boombatower - January 16, 2008 - 22:30
Status:needs work» needs review

I downloaded and ran the Coder module on my test case and it returned the following results.

No Problems Found

So I am not sure what I need to fix.

#11

Gábor Hojtsy - January 17, 2008 - 01:50
Status:needs review» needs work

Stuff like $this->drupalPostRequest('node/' . $node->nid . '/edit', $edit, 'Save'); is not comformant to our coding style, please use coder module's more sensitive checking (which is not enabled by default AFAIR).

#12

boombatower - January 17, 2008 - 02:24
Status:needs work» needs review

I fixed the small appending dot style issues.

AttachmentSize
translation_module5.test_.txt 6.06 KB

#13

Gábor Hojtsy - January 17, 2008 - 11:30

I did not have the opportunity to test, but otherwise this all looks good to me now. Thanks for your work!

#14

Rok Žlender - January 17, 2008 - 22:19

Committed. Thanks boombatower for your code and thanks Gabor for your reviews.

#15

Rok Žlender - January 17, 2008 - 22:22
Status:needs review» fixed

#16

Anonymous (not verified) - January 31, 2008 - 22:34
Status:fixed» closed

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

 
 

Drupal is a registered trademark of Dries Buytaert.