Commit 3fb01267 authored by Alexey Beloglazov's avatar Alexey Beloglazov Committed by Ev Maslovskiy
Browse files

Issue #3313237: Cover linear progress within lessons with tests

parent b3b5f54b
Loading
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -50,3 +50,7 @@ dist-folder-outdated:
    # Successful status code (0) if dist folder doesn't contain any changes.
    - git status --porcelain | grep "js/dist/" || exit 0 && exit 123

# Install required packages to run testing.
phpunit:
  before_script:
    - composer require --prefer-stable drupal/range drupal/views_data_export drupal/xls_serialization
+1 −1
Original line number Diff line number Diff line
@@ -9,7 +9,7 @@ use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
 *
 * @group anu_lms
 */
class CoursesPageCreationTest extends WebDriverTestBase {
class CoursePageTest extends WebDriverTestBase {

  /**
   * {@inheritdoc}
+115 −1
Original line number Diff line number Diff line
@@ -9,7 +9,7 @@ use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
 *
 * @group anu_lms
 */
class CoursesCreationTest extends WebDriverTestBase {
class CourseTest extends WebDriverTestBase {

  /**
   * {@inheritdoc}
@@ -42,6 +42,120 @@ class CoursesCreationTest extends WebDriverTestBase {
    $this->container->get('router.builder')->rebuild();
  }

  /**
   * Test linear progress feature for courses.
   */
  public function testLinearProgressForCourses() {
    $account = $this->drupalCreateUser([], 'test', TRUE);
    $this->drupalLogin($account);

    $assert = $this->assertSession();
    $page = $this->getSession()->getPage();

    // 1. Create a course with "linear progress".
    $this->drupalGet('node/add/course');
    $page->fillField('Title', 'Linear progress course demo');

    // Upload image.
    $imagePath = __DIR__ . '/assets/example.png';
    $page->attachFileToField('Add a new file', $imagePath);
    $assert->assertWaitOnAjaxRequest();
    $page->fillField('Alternative text', 'Example image');

    // Set alias.
    $page->findById('edit-path-0')->click();
    $page->fillField('URL alias', '/course/linear');

    // Go to "Modules" tab.
    $page->findLink('Modules')->click();

    // Set module name.
    $page->fillField('field_course_module[0][subform][field_module_title][0][value]', 'Demo Module');

    // Add lessons.
    $this->addLesson('Lesson 1', 'new');
    $this->addLesson('Lesson 2', 'new');
    $this->addLesson('Lesson 3', 'new');

    // Go to "Settings" tab.
    $page->findLink('Settings')->click();

    // Enable linear progress.
    $page->checkField('Enable linear progress');

    // Create the course.
    $page->pressButton('Save');

    // 2. Attempt to open 2nd lesson directly. It should be rejected because
    // that lesson is restricted for the current user.
    $lesson2 = $this->drupalGetNodeByTitle('Lesson 2');
    $lesson2Url = $lesson2->toUrl()->toString();
    $this->drupalGet($lesson2Url);

    // Make sure that the user was redirected to the user page.
    $this->assertStringEndsWith('/user/2', $this->getUrl());

    // 3. Attempt to open 3rd lesson directly. It should be rejected because
    // that lesson is restricted for the current user.
    $lesson3 = $this->drupalGetNodeByTitle('Lesson 3');
    $lesson3Url = $lesson3->toUrl()->toString();
    $this->drupalGet($lesson3Url);

    // 4. Go to 1st lesson.
    $lesson1 = $this->drupalGetNodeByTitle('Lesson 1');
    $lesson1Url = $lesson1->toUrl()->toString();
    $this->drupalGet($lesson1Url);

    // Tap "Next".
    $assert->waitForElementVisible('css', '[data-test=anu-lms-navigation-next]')->click();

    // Make sure that "Lesson 2" is opened.
    $currentLesson = $assert->waitForElementVisible('css', 'h6:contains("Lesson 2")');
    $this->assertNotEmpty($currentLesson);

    // Make sure that the user is located on "Lesson 2".
    $this->assertStringEndsWith($lesson2Url . '#page-1', $this->getUrl());

    // Tap "Next".
    $assert->waitForElementVisible('css', '[data-test=anu-lms-navigation-next]')->click();

    // Make sure that "Lesson 3" is opened.
    $currentLesson = $assert->waitForElementVisible('css', 'h6:contains("Lesson 3")');
    $this->assertNotEmpty($currentLesson);

    // Make sure that the user is located on "Lesson 3".
    $this->assertStringEndsWith($lesson3Url . '#page-1', $this->getUrl());

    // 5. Disable "Enable linear progress" for the course.
    $course = $this->drupalGetNodeByTitle('Linear progress course demo');
    $this->drupalGet('node/' . $course->id() . '/edit');

    // Go to "Settings" tab.
    $page->findLink('Settings')->click();

    // Enable linear progress.
    $page->uncheckField('Enable linear progress');

    // Save the course.
    $page->pressButton('Save');

    // 6. Create a new user.
    $account = $this->drupalCreateUser([], 'student');
    $this->drupalLogin($account);

    // 7. Attempt to open 2nd lesson directly. Now it should be available.
    $this->drupalGet($lesson2Url);

    // Make sure that the user is on the "Lesson 2" page.
    $this->assertStringEndsWith($lesson2Url . '#page-1', $this->getUrl());

    // 8. Attempt to open 3rd lesson directly. Now it should be available.
    $this->drupalGet($lesson3Url);

    // Make sure that the user is on the "Lesson 3" page.
    $this->assertStringEndsWith($lesson3Url . '#page-1', $this->getUrl());
  }

  /**
   * Test "courses creation" for the general case.
   */