function MigrateCommentTest::setUp in Migrate 6
Generates a random database prefix, runs the install scripts on the prefixed database and enable the specified modules. After installation many caches are flushed and the internal browser is setup so that the page requests will run on the new prefix. A temporary files directory is created with the same name as the database prefix.
Parameters
...: List of modules to enable for the duration of the test. This can be either a single array or a variable number of string arguments.
Overrides DrupalWebTestCase::setUp
File
- tests/
modules/ core/ migrate_comment.test, line 17 - Tests for comment migration
Class
- MigrateCommentTest
- @file Tests for comment migration
Code
function setUp() {
// Somehow, we're running in E_STRICT, and Views generates notices.
// Also, with PHP 5.3 deprecated notices can get in the way
error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED);
parent::setUp('views', 'schema', 'tw', 'migrate', 'comment');
// Create and login user
$migrate_user = $this
->drupalCreateUser(array(
'access administration pages',
MIGRATE_ACCESS_BASIC,
MIGRATE_ACCESS_ADVANCED,
));
$this
->drupalLogin($migrate_user);
// Create test tables
$ret = array();
$schema = array(
'fields' => array(
'id' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
),
'title' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
),
'body' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
),
),
'primary key' => array(
'id',
),
);
$this->storytable = 'migrate_simpletest_story';
db_create_table($ret, $this->storytable, $schema);
$sql = "INSERT INTO {" . $this->storytable . "} (id, title, body) VALUES(%d, '%s', '%s')";
db_query($sql, 893, 'Title 1', 'This is a body');
db_query($sql, 1027, 'Title 2', 'This is another body');
db_query($sql, 653223, 'Title 3', 'This is yet another body');
tw_add_tables($this->storytable, TRUE);
$schema = array(
'fields' => array(
'id' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
),
'username' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
),
'email' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
),
),
'primary key' => array(
'id',
),
);
$this->usertable = 'migrate_simpletest_user';
db_create_table($ret, $this->usertable, $schema);
$sql = "INSERT INTO {" . $this->usertable . "} (id, username, email) VALUES(%d, '%s', '%s')";
db_query($sql, 51, 'user1', 'user1@example.com');
db_query($sql, 831, 'user2', 'user2@example.com');
db_query($sql, 98374, 'user3', 'user3@example.com');
tw_add_tables($this->usertable, TRUE);
$schema = array(
'fields' => array(
'id' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
),
'storyid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
),
'userid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
),
'parentid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
),
'comment_text' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
),
'status' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
),
),
'primary key' => array(
'id',
),
);
$this->commenttable = 'migrate_simpletest_comment';
db_create_table($ret, $this->commenttable, $schema);
$sql = "INSERT INTO {" . $this->commenttable . "}\n (id, storyid, userid, parentid, comment_text, status)\n VALUES(%d, %d, %d, %d, '%s', %d)";
db_query($sql, 52, 893, 51, 0, 'Comment by user1 on Title 1', 0);
db_query($sql, 38383, 1027, 831, 0, 'Comment by user2 on Title 2', 1);
db_query($sql, 41893, 1027, 51, 38383, 'Reply by user1 to user2 on Title 2', 0);
db_query($sql, 123483, 653223, 98374, 0, 'Comment by user3 on Title 3', 1);
tw_add_tables($this->commenttable, TRUE);
}