Projet

Général

Profil

Paste
Télécharger (5,34 ko) Statistiques
| Branche: | Révision:

root / drupal7 / modules / simpletest / tests / upgrade / upgrade.node.test @ 1afa1695

1
<?php
2

    
3
/**
4
 * Upgrade test for node bodies.
5
 *
6
 * Load a filled installation of Drupal 6 and run the upgrade process on it.
7
 */
8
class NodeBodyUpgradePathTestCase extends UpgradePathTestCase {
9
  public static function getInfo() {
10
    return array(
11
      'name'  => 'Node body upgrade path',
12
      'description'  => 'Node body upgrade path tests.',
13
      'group' => 'Upgrade path',
14
    );
15
  }
16

    
17
  public function setUp() {
18
    // Path to the database dump.
19
    $this->databaseDumpFiles = array(
20
      drupal_get_path('module', 'simpletest') . '/tests/upgrade/drupal-6.filled.database.php',
21
    );
22
    parent::setUp();
23
  }
24

    
25
  /**
26
   * Test a successful upgrade.
27
   */
28
  public function testNodeBodyUpgrade() {
29
    $this->assertTrue($this->performUpgrade(), 'The upgrade was completed successfully.');
30

    
31
    $instance = field_info_instance('node', 'body', 'story');
32
    $this->assertIdentical($instance['required'], 0, 'The required setting was preserved during the upgrade path.');
33
    $this->assertTrue($instance['description'], 'The description was preserved during the upgrade path');
34

    
35
    $this->drupalGet("content/1263769200");
36
    $this->assertText('node body (broken) - 37');
37

    
38
    // Find a published node revision and make sure it still has a body.
39
    $revision = db_query_range("SELECT r.nid, r.vid FROM {node_revision} r JOIN {node} n ON n.nid = r.nid WHERE n.status = 1 AND n.type <> 'poll' AND n.vid <> r.vid", 0, 1)->fetch();
40
    $revision = node_load($revision->nid, $revision->vid);
41
    $this->assertTrue(!empty($revision->body), 'Non-current node revisions still have a node body.');
42
    // Find an unpublished node revision and make sure it still has a body.
43
    $revision = db_query_range("SELECT r.nid, r.vid FROM {node_revision} r JOIN {node} n ON n.nid = r.nid WHERE n.status = 0 AND n.type <> 'poll' AND n.vid <> r.vid", 0, 1)->fetch();
44
    $revision = node_load($revision->nid, $revision->vid);
45
    $this->assertTrue(!empty($revision->body), 'Unpublished non-current node revisions still have a node body.');
46

    
47
    // Check that fields created during the upgrade can be edited and resaved
48
    // in the UI.
49
    $this->drupalPost('admin/structure/types/manage/story/fields/body', array(), t('Save settings'));
50
  }
51
}
52

    
53
/**
54
 * Tests the upgrade path for node disabled node types.
55
 *
56
 * Load a filled installation of Drupal 6 and run the upgrade process on it.
57
 */
58
class DisabledNodeTypeTestCase extends UpgradePathTestCase {
59
  public static function getInfo() {
60
    return array(
61
      'name'  => 'Disabled node type upgrade path',
62
      'description'  => 'Disabled node type upgrade path tests.',
63
      'group' => 'Upgrade path',
64
    );
65
  }
66

    
67
  public function setUp() {
68
    // Path to the database dump.
69
    $this->databaseDumpFiles = array(
70
      drupal_get_path('module', 'simpletest') . '/tests/upgrade/drupal-6.filled.database.php',
71
      drupal_get_path('module', 'simpletest') . '/tests/upgrade/drupal-6.node_type_broken.database.php',
72
    );
73
    parent::setUp();
74
  }
75

    
76
  /**
77
   * Tests a successful upgrade.
78
   */
79
  public function testDisabledNodeTypeUpgrade() {
80
    $this->assertTrue($this->performUpgrade(), 'The upgrade was completed successfully.');
81
    $this->assertTrue(field_info_instance('comment', 'comment_body', 'comment_node_broken'), 'Comment body field instance was created for comments attached to the disabled broken node type');
82
  }
83
}
84

    
85
/**
86
 * Upgrade test for node type poll.
87
 *
88
 * Load a bare installation of Drupal 6 and run the upgrade process on it.
89
 *
90
 * The install only contains dblog (although it's optional, it's only so that
91
 * another hook_watchdog module can take its place, the site is not functional
92
 * without watchdog) and update.
93
 */
94
class PollUpgradePathTestCase extends UpgradePathTestCase {
95
  public static function getInfo() {
96
    return array(
97
      'name'  => 'Poll upgrade path',
98
      'description'  => 'Poll upgrade path tests.',
99
      'group' => 'Upgrade path',
100
    );
101
  }
102

    
103
  public function setUp() {
104
    // Path to the database dump.
105
    $this->databaseDumpFiles = array(
106
      drupal_get_path('module', 'simpletest') . '/tests/upgrade/drupal-6.filled.database.php',
107
    );
108
    parent::setUp();
109

    
110
    $this->uninstallModulesExcept(array('poll'));
111
  }
112

    
113
  /**
114
   * Test a successful upgrade.
115
   */
116
  public function testPollUpgrade() {
117
    $this->assertTrue($this->performUpgrade(), 'The upgrade was completed successfully.');
118

    
119
    // Check modules page for poll
120
    $this->drupalGet('admin/modules');
121

    
122
    // Verify that the poll data is still correctly available
123
    for ($i = 0; $i < 12; $i++) {
124
      $this->drupalGet("content/poll/$i");
125

    
126
      $nbchoices = ($i % 4) + 2;
127

    
128
      for ($c = 0; $c < $nbchoices; $c++) {
129
        $this->assertText("Choice $c for poll $i", 'Choice text is displayed correctly on poll view');
130
      }
131

    
132
      // Now check that the votes are correct
133
      $this->clickLink(t('Results'));
134

    
135
      for ($c = 0; $c < $nbchoices; $c++) {
136
        $this->assertText("Choice $c for poll $i", 'Choice text is displayed correctly on result view');
137
      }
138

    
139
      $nbvotes = floor (($i % 4) + 5);
140
      $elements = $this->xpath("//div[@class='percent']");
141
      for ($c = 0; $c < $nbchoices; $c++) {
142
        $votes = floor($nbvotes / $nbchoices);
143
        if (($nbvotes % $nbchoices) > $c) $votes++;
144
        $this->assertTrue(preg_match("/$votes vote/", $elements[$c]), 'The number of votes is displayed correctly: expected ' . $votes . ', got ' . $elements[$c]);
145
      }
146
    }
147
  }
148
}