I think it is important to test the main regex expression in this module for all possible situations to make sure it always works correctly.
We can gather test cases in collection, create a unit test and attach it to this module. If it will be one more issue with problem of this regex, we could add another test case to automatic tests and so on.
Will it be okey if i help you with it?
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | smiley-adds-automatic-tests-to-the-module-2186169-2.patch | 3.67 KB | nikita petrov |
Comments
Comment #1
fizk commentedThanks Nikita, that's a great idea. In fact, I don't think the next release will be made without automated testing being done first.
Comment #2
nikita petrov commentedI think the best approach for testing smiley text filter (function smiley_filter_process) is the Unit testing (DrupalUnitTestCase), not Functional testing (DrupalWebTestCase), because in fact it is a unit - we should give it an input (text with smileys codes) and get an output (text with smiles converted into images). But we have a problem -
current version of this function requires a database to fetch an array of smileys objects (function smiley_get_all()). So we need to slightly refactor this function like this:
After thaе we should define an array with objects of smiles in our test cases manually, like this:
and then we could run tests:
How do you think, is my approach ok? Should i further work in that direction?
I attached my current working code for you for better understanding what i mean.
Comment #3
fizk commentedThat looks like a great place to start. I've committed it here:
http://drupalcode.org/project/smiley.git/commit/b6b6f83cef1f6dc47ef77cf8...
If we're going to use
<img[^>]*>to match the image tag, we should do one test that specifically checks that the img src attribute is correct.A few other checks we could do are:
:)),:))), etc, assuming$smileysonly contains:).Comment #4
fizk commentedI just noticed that we have to use DrupalWebTestCase to enable the smiley module before running test cases.
Comment #5
fizk commentedSeveral test cases have been committed.