You are here

function MigrateFunctionalTest::testContentSetsPages in Migrate 6

Test UI for listing/creating/editing content sets

File

tests/migrate_ui.test, line 89
Tests for the Migrate UI.

Class

MigrateFunctionalTest
UI tests for the Migrate module

Code

function testContentSetsPages() {

  // Create content set - missing description
  $edit = array();

  // TODO: test validation of machine_name
  $edit['machine_name'] = 'simple_page_test';
  $edit['contenttype'] = 'node/page';
  $edit['view_name'] = $this->tablename;
  $edit['weight'] = 5;
  $this
    ->drupalPost('admin/content/migrate', $edit, t('Add'));
  $this
    ->assertText(t('Content set description is required'), t('Post with no description'));
  $edit['description'] = t('Simple page test');
  $this
    ->drupalPost(NULL, $edit, t('Add'));
  $mcsid = db_result(db_query("SELECT mcsid FROM {migrate_content_sets} WHERE view_name='%s'", $this->tablename));
  if ($this
    ->assertNotNull($mcsid, t('Create simple page content set'))) {
    $path = parse_url($this
      ->getUrl(), PHP_URL_PATH);
    if ($this
      ->assertEqual($path, "/admin/content/migrate/content_set/{$mcsid}", t('Redirected to content set edit page'))) {
      $edit = array();
      $edit['weight'] = 'abc';
      $this
        ->drupalPost(NULL, $edit, t('Submit changes'));
      $this
        ->assertText(t('Weight must be an integer value (positive or negative)'), t('Non-numeric weight'));
      $edit = array();
      $edit['weight'] = 5.8;
      $this
        ->drupalPost(NULL, $edit, t('Submit changes'));
      $this
        ->assertText(t('Weight must be an integer value (positive or negative)'), t('Floating-point weight'));
      $edit = array();
      $edit['weight'] = -3;
      $this
        ->drupalPost(NULL, $edit, t('Submit changes'));
      $this
        ->assertText(t('Changes saved'), t('Negative integer weight'));

      // Add mappings to content set
      $edit = array();
      $edit['srcfield[title]'] = $this->tablename . '_title';
      $edit['srcfield[body]'] = $this->tablename . '_body';
      $this
        ->drupalPost("/admin/content/migrate/content_set/{$mcsid}", $edit, t('Submit changes'));
      if ($this
        ->assertText(t('Changes saved'), t('Create field mappings'))) {
        $sql = "SELECT mcmid FROM {migrate_content_mappings}\n                  WHERE mcsid=%d AND destfield='%s'";
        $mcmid = db_result(db_query($sql, $mcsid, 'title'));
        if (!$this
          ->assertTrue($mcmid, t('Title mapping saved'))) {
          return;
        }
        $mcmid = db_result(db_query($sql, $mcsid, 'body'));
        if (!$this
          ->assertTrue($mcmid, t('Body mapping saved'))) {
          return;
        }
      }
    }
    else {
      $this
        ->error(t('Post went to page !url, mcsid=!mcsid', array(
        '!url' => $path,
        '!mcsid' => $mcsid,
      )));
    }
  }
}