You are here

public function OpignoQuizImportAppWebTestCase::testGlobalImport in Opigno Quiz Import App 7

Test importing a quiz in global context.

File

tests/OpignoQuizImportAppWebTestCase.test, line 32
Defines the unit tests for the Opigno Quiz Import app.

Class

OpignoQuizImportAppWebTestCase
@file Defines the unit tests for the Opigno Quiz Import app.

Code

public function testGlobalImport() {

  // Create an admin to simplify checking.
  $admin = $this
    ->drupalCreateUser(array_keys(module_invoke_all('permission')));
  $course = $this
    ->createCourse('Course', $admin);

  // Create a user for checking the import.
  $importer = $this
    ->drupalCreateUser(array(
    'import quiz questions xls',
  ));

  // Login importer.
  $this
    ->drupalLogin($importer);

  // Check import.
  $title = "imported quiz";
  $this
    ->drupalPost('admin/quiz/import/xls', array(
    'files[import_file]' => realpath(drupal_get_path('module', 'opigno_quiz_import_app') . '/tests/fixture/quiz.xlsx'),
    'title' => $title,
  ), t("Import"));
  $this
    ->assertText(t("Your new quiz was imported."));

  // Check the questions. Make sure their settings are correct.
  $this
    ->clickLink(t("here"));
  $this
    ->assertText($title);
  $questions_url = $this
    ->getUrl();

  // Check Quiz was assigned to correct author.
  $nid = $this
    ->_getNid($questions_url);
  $this
    ->_checkNodeAuthor($nid, $importer->uid);

  // Login admin - will make checking question settings much simpler.
  $this
    ->drupalLogin($admin);

  // Check OG ref field.
  $this
    ->drupalGet($questions_url . '/edit');
  $this
    ->assertNoOptionSelected('edit-og-group-ref-und-0-default', $course->nid, "Was not linked to any group.");

  // Check the questions.
  $this
    ->drupalGet($questions_url . '/questions');
  $this
    ->assertText("Who is Shröder ?", "The first question was correctly linked.");
  $this
    ->assertText("Who is Einstein ?", "The second question was correctly linked.");

  // Check the first question settings.
  $this
    ->clickLink("Who is Shröder ?");

  // Check question was assigned to correct author.
  $nid = $this
    ->_getNid($this
    ->getUrl());
  $this
    ->_checkNodeAuthor($nid, $importer->uid);

  // Check question settings.
  $this
    ->drupalGet($this
    ->getUrl() . '/edit');
  $this
    ->_testFirstQuestionSettings();
  $this
    ->drupalGet($questions_url . '/questions');
  $this
    ->clickLink("Who is Einstein ?");

  // Check question was assigned to correct author.
  $nid = $this
    ->_getNid($this
    ->getUrl());
  $this
    ->_checkNodeAuthor($nid, $importer->uid);

  // Check question settings.
  $this
    ->drupalGet($this
    ->getUrl() . '/edit');
  $this
    ->_testSecondQuestionSettings();
}