diff --git a/mod/data/tests/generator/lib.php b/mod/data/tests/generator/lib.php
index 4996bc8b8b5ff..dbc9411fe5a5e 100644
--- a/mod/data/tests/generator/lib.php
+++ b/mod/data/tests/generator/lib.php
@@ -15,8 +15,7 @@
// along with Moodle. If not, see .
/**
- * mod_data data generator class
- * Currently, the field types in the ignoredfieldtypes array aren't supported.
+ * Data generator class for mod_data.
*
* @package mod_data
* @category test
@@ -28,7 +27,8 @@
/**
- * Database module data generator class
+ * Data generator class for mod_data.
+ *
* Currently, the field types in the ignoredfieldtypes array aren't supported.
*
* @package mod_data
@@ -86,7 +86,6 @@ public function create_instance($record = null, array $options = null) {
return parent::create_instance($record, (array)$options);
}
-
/**
* Creates a field for a mod_data instance.
* Currently, the field types in the ignoredfieldtypes array aren't supported.
@@ -96,8 +95,6 @@ public function create_instance($record = null, array $options = null) {
* @return data_field_{type}
*/
public function create_field($record = null, $data = null) {
- global $DB;
-
$record = (array) $record;
if (in_array($record['type'], $this->ignoredfieldtypes)) {
@@ -212,7 +209,7 @@ public function create_entry($data, $contents) {
$recordid = data_add_record($data);
- $fields = $DB->get_records('data_fields', array( 'dataid' => $data->id));
+ $fields = $DB->get_records('data_fields', array('dataid' => $data->id));
// Validating whether required field are filled.
foreach ($fields as $field) {
@@ -231,9 +228,9 @@ public function create_entry($data, $contents) {
$temp = explode('-', $contents[$fieldid], 3);
- $values['field_'.$fieldid.'_day'] = $temp[0];
- $values['field_'.$fieldid.'_month'] = $temp[1];
- $values['field_'.$fieldid.'_year'] = $temp[2];
+ $values['field_' . $fieldid . '_day'] = $temp[0];
+ $values['field_' . $fieldid . '_month'] = $temp[1];
+ $values['field_' . $fieldid . '_year'] = $temp[2];
foreach ($values as $fieldname => $value) {
if ($field->notemptyfield($value, $fieldname)) {
@@ -243,11 +240,11 @@ public function create_entry($data, $contents) {
} else if ($field->type === 'textarea') {
$values = array();
- $values['field_'.$fieldid] = $contents[$fieldid];
- $values['field_'.$fieldid.'_content1'] = 1;
+ $values['field_' . $fieldid] = $contents[$fieldid];
+ $values['field_' . $fieldid . '_content1'] = 1;
foreach ($values as $fieldname => $value) {
- if ($field->notemptyfield ($value, $fieldname)) {
+ if ($field->notemptyfield($value, $fieldname)) {
continue 2;
}
}
@@ -256,20 +253,20 @@ public function create_entry($data, $contents) {
if (is_array($contents[$fieldid])) {
foreach ($contents[$fieldid] as $key => $value) {
- $values['field_'.$fieldid.'_'.$key] = $value;
+ $values['field_' . $fieldid . '_' . $key] = $value;
}
} else {
- $values['field_'.$fieldid.'_0'] = $contents[$fieldid];
+ $values['field_' . $fieldid . '_0'] = $contents[$fieldid];
}
foreach ($values as $fieldname => $value) {
- if ($field->notemptyfield ($value, $fieldname)) {
+ if ($field->notemptyfield($value, $fieldname)) {
continue 2;
}
}
} else {
- if ($field->notemptyfield ($contents[$fieldid], 'field_'.$fieldid.'_0')) {
+ if ($field->notemptyfield($contents[$fieldid], 'field_' . $fieldid . '_0')) {
continue;
}
}
@@ -281,7 +278,7 @@ public function create_entry($data, $contents) {
foreach ($contents as $fieldid => $content) {
- $field = $DB->get_record('data_fields', array( 'id' => $fieldid));
+ $field = $DB->get_record('data_fields', array('id' => $fieldid));
$field = data_get_field($field, $data);
if (in_array($field->field->type, $this->ignoredfieldtypes)) {
@@ -293,13 +290,13 @@ public function create_entry($data, $contents) {
$temp = explode('-', $content, 3);
- $values['field_'.$fieldid.'_day'] = (int)trim($temp[0]);
- $values['field_'.$fieldid.'_month'] = (int)trim($temp[1]);
- $values['field_'.$fieldid.'_year'] = (int)trim($temp[2]);
+ $values['field_' . $fieldid . '_day'] = (int)trim($temp[0]);
+ $values['field_' . $fieldid . '_month'] = (int)trim($temp[1]);
+ $values['field_' . $fieldid . '_year'] = (int)trim($temp[2]);
// Year should be less than 2038, so it can be handled by 32 bit windows.
- if ($values['field_'.$fieldid.'_year'] > 2038) {
- throw new coding_exception('DateTime::getTimestamp resturns false on 32 bit win for year beyond '.
+ if ($values['field_' . $fieldid . '_year'] > 2038) {
+ throw new coding_exception('DateTime::getTimestamp resturns false on 32 bit win for year beyond ' .
'2038. Please use year less than 2038.');
}
@@ -313,8 +310,8 @@ public function create_entry($data, $contents) {
if ($field->type === 'textarea') {
$values = array();
- $values['field_'.$fieldid] = $content;
- $values['field_'.$fieldid.'_content1'] = 1;
+ $values['field_' . $fieldid] = $content;
+ $values['field_' . $fieldid . '_content1'] = 1;
foreach ($values as $fieldname => $value) {
$field->update_content($recordid, $value, $fieldname);
@@ -328,10 +325,10 @@ public function create_entry($data, $contents) {
if (is_array($content)) {
foreach ($content as $key => $value) {
- $values['field_'.$fieldid.'_'.$key] = $value;
+ $values['field_' . $fieldid . '_' . $key] = $value;
}
} else {
- $values['field_'.$fieldid.'_0'] = $content;
+ $values['field_' . $fieldid . '_0'] = $content;
}
foreach ($values as $fieldname => $value) {
diff --git a/mod/data/tests/generator_test.php b/mod/data/tests/generator_test.php
index be201cfba0dbb..c554423f66fa7 100644
--- a/mod/data/tests/generator_test.php
+++ b/mod/data/tests/generator_test.php
@@ -15,7 +15,7 @@
// along with Moodle. If not, see .
/**
- * PHPUnit data generator tests
+ * PHPUnit data generator tests.
*
* @package mod_data
* @category phpunit
@@ -27,7 +27,7 @@
/**
- * PHPUnit data generator testcase
+ * PHPUnit data generator testcase.
*
* @package mod_data
* @category phpunit
@@ -70,10 +70,8 @@ public function test_generator() {
$this->assertEquals(100, $gitem->grademax);
$this->assertEquals(0, $gitem->grademin);
$this->assertEquals(GRADE_TYPE_VALUE, $gitem->gradetype);
-
}
-
public function test_create_field() {
global $DB;
@@ -100,7 +98,7 @@ public function test_create_field() {
$context = context_module::instance($cm->id);
$this->assertEquals($data->cmid, $context->instanceid);
- $fieldtypes = array( 'checkbox', 'date', 'menu', 'multimenu', 'number', 'radiobutton', 'text', 'textarea', 'url' );
+ $fieldtypes = array('checkbox', 'date', 'menu', 'multimenu', 'number', 'radiobutton', 'text', 'textarea', 'url');
$count = 1;
@@ -108,29 +106,28 @@ public function test_create_field() {
foreach ($fieldtypes as $fieldtype) {
// Creating variables dynamically.
- $fieldname = 'field-'.$count;
+ $fieldname = 'field-' . $count;
$record = new StdClass();
$record->name = $fieldname;
$record->type = $fieldtype;
${$fieldname} = $this->getDataGenerator()->get_plugin_generator('mod_data')->create_field($record, $data);
- $this->assertInstanceOf('data_field_'.$fieldtype , ${$fieldname});
+ $this->assertInstanceOf('data_field_' . $fieldtype, ${$fieldname});
$count++;
}
- $this->assertEquals(count($fieldtypes), $DB->count_records('data_fields', array( 'dataid' => $data->id )));
+ $this->assertEquals(count($fieldtypes), $DB->count_records('data_fields', array('dataid' => $data->id)));
- $addtemplate = $DB->get_record('data', array( 'id' => $data->id ), 'addtemplate');
+ $addtemplate = $DB->get_record('data', array('id' => $data->id), 'addtemplate');
$addtemplate = $addtemplate->addtemplate;
for ($i = 1; $i < $count; $i++) {
- $fieldname = 'field-'.$i;
- $this->assertTrue(strpos($addtemplate, '[['.$fieldname.']]') >= 0);
+ $fieldname = 'field-' . $i;
+ $this->assertTrue(strpos($addtemplate, '[[' . $fieldname . ']]') >= 0);
}
}
-
public function test_create_entry() {
global $DB;
@@ -157,7 +154,7 @@ public function test_create_entry() {
$context = context_module::instance($cm->id);
$this->assertEquals($data->cmid, $context->instanceid);
- $fieldtypes = array( 'checkbox', 'date', 'menu', 'multimenu', 'number', 'radiobutton', 'text', 'textarea', 'url' );
+ $fieldtypes = array('checkbox', 'date', 'menu', 'multimenu', 'number', 'radiobutton', 'text', 'textarea', 'url');
$count = 1;
@@ -165,17 +162,17 @@ public function test_create_entry() {
foreach ($fieldtypes as $fieldtype) {
// Creating variables dynamically.
- $fieldname = 'field-'.$count;
+ $fieldname = 'field-' . $count;
$record = new StdClass();
$record->name = $fieldname;
$record->type = $fieldtype;
${$fieldname} = $this->getDataGenerator()->get_plugin_generator('mod_data')->create_field($record, $data);
- $this->assertInstanceOf('data_field_'.$fieldtype , ${$fieldname});
+ $this->assertInstanceOf('data_field_' . $fieldtype, ${$fieldname});
$count++;
}
- $this->assertEquals(count($fieldtypes), $DB->count_records('data_fields', array( 'dataid' => $data->id )));
+ $this->assertEquals(count($fieldtypes), $DB->count_records('data_fields', array('dataid' => $data->id)));
$fields = $DB->get_records('data_fields', array('dataid' => $data->id), 'id');
@@ -197,10 +194,7 @@ public function test_create_entry() {
$datarecordid = $this->getDataGenerator()->get_plugin_generator('mod_data')->create_entry($data, $fieldcontents);
- $this->assertEquals(1, $DB->count_records('data_records', array( 'dataid' => $data->id )));
-
+ $this->assertEquals(1, $DB->count_records('data_records', array('dataid' => $data->id)));
$this->assertEquals(count($contents), $DB->count_records('data_content', array('recordid' => $datarecordid)));
-
}
-
-}
\ No newline at end of file
+}