[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/mod/assign/submission/onlinetext/tests/ -> locallib_test.php (source)

   1  <?php
   2  // This file is part of Moodle - http://moodle.org/
   3  //
   4  // Moodle is free software: you can redistribute it and/or modify
   5  // it under the terms of the GNU General Public License as published by
   6  // the Free Software Foundation, either version 3 of the License, or
   7  // (at your option) any later version.
   8  //
   9  // Moodle is distributed in the hope that it will be useful,
  10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12  // GNU General Public License for more details.
  13  //
  14  // You should have received a copy of the GNU General Public License
  15  // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
  16  
  17  /**
  18   * Tests for mod/assign/submission/onlinetext/locallib.php
  19   *
  20   * @package   assignsubmission_onlinetext
  21   * @copyright 2016 Cameron Ball
  22   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  defined('MOODLE_INTERNAL') || die();
  26  
  27  global $CFG;
  28  require_once($CFG->dirroot . '/mod/assign/tests/base_test.php');
  29  
  30  /**
  31   * Unit tests for mod/assign/submission/onlinetext/locallib.php
  32   *
  33   * @copyright  2016 Cameron Ball
  34   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  35   */
  36  class assignsubmission_onlinetext_locallib_testcase extends advanced_testcase {
  37  
  38      /** @var stdClass $user A user to submit an assignment. */
  39      protected $user;
  40  
  41      /** @var stdClass $course New course created to hold the assignment activity. */
  42      protected $course;
  43  
  44      /** @var stdClass $cm A context module object. */
  45      protected $cm;
  46  
  47      /** @var stdClass $context Context of the assignment activity. */
  48      protected $context;
  49  
  50      /** @var stdClass $assign The assignment object. */
  51      protected $assign;
  52  
  53      /**
  54       * Setup all the various parts of an assignment activity including creating an onlinetext submission.
  55       */
  56      protected function setUp() {
  57          $this->user = $this->getDataGenerator()->create_user();
  58          $this->course = $this->getDataGenerator()->create_course();
  59          $generator = $this->getDataGenerator()->get_plugin_generator('mod_assign');
  60          $params = ['course' => $this->course->id, 'assignsubmission_onlinetext_enabled' => 1];
  61          $instance = $generator->create_instance($params);
  62          $this->cm = get_coursemodule_from_instance('assign', $instance->id);
  63          $this->context = context_module::instance($this->cm->id);
  64          $this->assign = new testable_assign($this->context, $this->cm, $this->course);
  65          $this->setUser($this->user->id);
  66      }
  67  
  68      /**
  69       * Test submission_is_empty
  70       *
  71       * @dataProvider submission_is_empty_testcases
  72       * @param string $submissiontext The online text submission text
  73       * @param bool $expected The expected return value
  74       */
  75      public function test_submission_is_empty($submissiontext, $expected) {
  76          $this->resetAfterTest();
  77  
  78          $plugin = $this->assign->get_submission_plugin_by_type('onlinetext');
  79          $data = new stdClass();
  80          $data->onlinetext_editor = ['text' => $submissiontext];
  81  
  82          $result = $plugin->submission_is_empty($data);
  83          $this->assertTrue($result === $expected);
  84      }
  85  
  86      /**
  87       * Test new_submission_empty
  88       *
  89       * @dataProvider submission_is_empty_testcases
  90       * @param string $submissiontext The file submission data
  91       * @param bool $expected The expected return value
  92       */
  93      public function test_new_submission_empty($submissiontext, $expected) {
  94          $this->resetAfterTest();
  95          $data = new stdClass();
  96          $data->onlinetext_editor = ['text' => $submissiontext];
  97  
  98          $result = $this->assign->new_submission_empty($data);
  99          $this->assertTrue($result === $expected);
 100      }
 101  
 102      /**
 103       * Dataprovider for the test_submission_is_empty testcase
 104       *
 105       * @return array of testcases
 106       */
 107      public function submission_is_empty_testcases() {
 108          return [
 109              'Empty submission string' => ['', true],
 110              'Empty submission null' => [null, true],
 111              'Value 0' => [0, false],
 112              'String 0' => ['0', false],
 113              'Text' => ['Ai! laurië lantar lassi súrinen, yéni únótimë ve rámar aldaron!', false]
 114          ];
 115      }
 116  }


Generated: Thu Aug 11 10:00:09 2016 Cross-referenced by PHPXref 0.7.1