You are here

public function TrainingCompleteTest::testTrainingComplete in Opigno Learning path 8

Same name and namespace in other branches
  1. 3.x tests/src/Functional/TrainingCompleteTest.php \Drupal\Tests\opigno_learning_path\Functional\TrainingCompleteTest::testTrainingComplete()

Tests training visibility for users.

File

tests/src/Functional/TrainingCompleteTest.php, line 20

Class

TrainingCompleteTest
Tests for training complete process.

Namespace

Drupal\Tests\opigno_learning_path\Functional

Code

public function testTrainingComplete() {

  // Create a new training.
  $training = $this
    ->createGroup([
    'field_learning_path_visibility' => 'public',
    'field_learning_path_published' => TRUE,
  ]);
  $training
    ->addMember($this->groupCreator);

  // Create module and add to a training.
  $mandatory_module = $this
    ->createOpignoModule();
  $child_module_1 = $this
    ->createOpignoModule();
  $child_module_2 = $this
    ->createOpignoModule();

  // Add modules to training.
  $this
    ->addModuleToTraining($training, $mandatory_module);
  $this
    ->addModuleToTraining($training, $child_module_1, 0);
  $this
    ->addModuleToTraining($training, $child_module_2, 0);

  // Create links.
  $content_mandatory_module = OpignoGroupManagedContent::loadByProperties([
    'group_content_type_id' => 'ContentTypeModule',
    'entity_id' => $mandatory_module
      ->id(),
  ]);
  $content_mandatory_module = reset($content_mandatory_module);
  $content_child_module_1 = OpignoGroupManagedContent::loadByProperties([
    'group_content_type_id' => 'ContentTypeModule',
    'entity_id' => $child_module_1
      ->id(),
  ]);
  $content_child_module_1 = reset($content_child_module_1);
  $content_child_module_2 = OpignoGroupManagedContent::loadByProperties([
    'group_content_type_id' => 'ContentTypeModule',
    'entity_id' => $child_module_2
      ->id(),
  ]);
  $content_child_module_2 = reset($content_child_module_2);
  $link_1 = OpignoGroupManagedLink::createWithValues($content_child_module_1
    ->getGroupId(), $content_mandatory_module
    ->id(), $content_child_module_1
    ->id(), 50);
  $link_1
    ->save();
  $link_2 = OpignoGroupManagedLink::createWithValues($content_child_module_2
    ->getGroupId(), $content_mandatory_module
    ->id(), $content_child_module_2
    ->id(), 0);
  $link_2
    ->save();
  $this
    ->createAnswersAndAttempt($training, $mandatory_module, $this->groupCreator, 100);
  $this
    ->createAnswersAndAttempt($training, $child_module_1, $this->groupCreator, 100);

  // Check the status of the training. Should be completed, because all mandatory modules are completed.
  $is_complated = opigno_learning_path_completed_on($training
    ->id(), $this->groupCreator
    ->id());
  $is_complated = $is_complated > 0;
  $this
    ->assertTrue($is_complated, 'The training is completed.');

  // Check achievements.
  $this
    ->drupalGet('/achievements', [
    'query' => [
      'preload-progress' => 'true',
    ],
  ]);

  // Check if Training has passed status on the achievements page.
  $content = $this
    ->getSession()
    ->getPage()
    ->find('css', '.lp_summary_step_state_passed');
  $this
    ->assertNotEmpty($content, 'Training status is "Passed" on achievements page');
}