upgrade.poll.test 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. /**
  3. * Upgrade test for poll.module.
  4. *
  5. * Load a bare installation of Drupal 6 and run the upgrade process on it.
  6. *
  7. * The install only contains dblog (although it's optional, it's only so that
  8. * another hook_watchdog module can take its place, the site is not functional
  9. * without watchdog) and update.
  10. */
  11. class PollUpgradePathTestCase extends UpgradePathTestCase {
  12. public static function getInfo() {
  13. return array(
  14. 'name' => 'Poll upgrade path',
  15. 'description' => 'Poll upgrade path tests.',
  16. 'group' => 'Upgrade path',
  17. );
  18. }
  19. public function setUp() {
  20. // Path to the database dump files.
  21. $this->databaseDumpFiles = array(
  22. drupal_get_path('module', 'simpletest') . '/tests/upgrade/drupal-6.filled.database.php',
  23. );
  24. parent::setUp();
  25. $this->uninstallModulesExcept(array('poll'));
  26. }
  27. /**
  28. * Test a successful upgrade.
  29. */
  30. public function testPollUpgrade() {
  31. $this->assertTrue($this->performUpgrade(), t('The upgrade was completed successfully.'));
  32. // Check modules page for poll
  33. $this->drupalGet('admin/modules');
  34. // Verify that the poll data is still correctly available
  35. for ($i = 0; $i < 12; $i++) {
  36. $this->drupalGet("content/poll/$i");
  37. $nbchoices = ($i % 4) + 2;
  38. for ($c = 0; $c < $nbchoices; $c++) {
  39. $this->assertText("Choice $c for poll $i", t('Choice text is displayed correctly on poll view'));
  40. }
  41. // Now check that the votes are correct
  42. $this->clickLink(t('Results'));
  43. for ($c = 0; $c < $nbchoices; $c++) {
  44. $this->assertText("Choice $c for poll $i", t('Choice text is displayed correctly on result view'));
  45. }
  46. $nbvotes = floor (($i % 4) + 5);
  47. $elements = $this->xpath("//div[@class='percent']");
  48. for ($c = 0; $c < $nbchoices; $c++) {
  49. $votes = floor($nbvotes / $nbchoices);
  50. if (($nbvotes % $nbchoices) > $c) $votes++;
  51. $this->assertTrue(preg_match("/$votes vote/", $elements[$c]), t('The number of votes is displayed correctly: expected ' . $votes . ', got ' . $elements[$c]));
  52. }
  53. }
  54. }
  55. }