Page MenuHomePhabricator

[Unit testing] Add unit tests to Newsletter validations
Closed, ResolvedPublic

Description

There are several validations now enforced, such as:

  1. The description should be larger than x length
  2. The main page should exist
  3. The main page should be unique per newsletter
  4. The newsletter name should be unique

How to write the test:

  1. First, take a look at the behavior while creating a newsletter at Special:CreateNewsletter
  2. Take a look at the function being called on clicking submit button - and in this case its https://github.com/wikimedia/mediawiki-extensions-Newsletter/blob/master/includes/specials/SpecialNewsletterCreate.php#L74
  3. Then take a look at https://gerrit.wikimedia.org/r/#/c/399995/3/tests/specials/SpecialNewsletterCreateTest.php and see how exactly we are testing it.
  4. Understand what validation you are going to test, and write a new function in the file SpecialNewsletterCreateTest.phpwith a new payload ($input) that can mock it. For eg: with a faulty description or bad main page, etc. For debugging, you can always use var_dump( $res ); as in the example gerrit change line 31
  5. Execute all the tests, make sure things are green, and push.

Bonus: Think about adding an extra test that makes sure that the newsletter was not created (and saved in the database) after each of these conditions fail.

Event Timeline

Change 399995 had a related patch set uploaded (by 01tonythomas; owner: 01tonythomas):
[mediawiki/extensions/Newsletter@master] Add a unit test to check newsletter creation validation

https://gerrit.wikimedia.org/r/399995

Change 400137 had a related patch set uploaded (by Ryan10145; owner: Ryan10145):
[mediawiki/extensions/Newsletter@master] Added a unit test to check that the main page exists

https://gerrit.wikimedia.org/r/400137

Change 400137 merged by jenkins-bot:
[mediawiki/extensions/Newsletter@master] Added a unit test to check that the main page exists

https://gerrit.wikimedia.org/r/400137

Change 400192 had a related patch set uploaded (by Pppery; owner: Pppery):
[mediawiki/extensions/Newsletter@master] Add a unit test to check that the main page must be unique per newsletter

https://gerrit.wikimedia.org/r/400192

Change 400192 merged by jenkins-bot:
[mediawiki/extensions/Newsletter@master] Add a unit test to check that the main page must be unique per newsletter

https://gerrit.wikimedia.org/r/400192

Change 400242 had a related patch set uploaded (by Ryan10145; owner: Ryan10145):
[mediawiki/extensions/Newsletter@master] Added a unit test to check that the name must be unique per newsletter

https://gerrit.wikimedia.org/r/400242

Change 400242 merged by jenkins-bot:
[mediawiki/extensions/Newsletter@master] Added a unit test to check that the name must be unique per newsletter

https://gerrit.wikimedia.org/r/400242

Pppery subscribed.

Closing task as resolved because all subtasks have been done

01tonythomas claimed this task.

All patch sets are merged. This is good to go.

Thank you! 👍

Change 399995 merged by jenkins-bot:
[mediawiki/extensions/Newsletter@master] Add a unit test to check newsletter creation validation

https://gerrit.wikimedia.org/r/399995