Merge branch 'MDL-57455_master' of git://github.com/markn86/moodle
authorJake Dallimore <jake@moodle.com>
Mon, 16 Oct 2017 02:34:01 +0000 (10:34 +0800)
committerJake Dallimore <jake@moodle.com>
Mon, 16 Oct 2017 02:34:01 +0000 (10:34 +0800)
1  2 
mod/data/tests/search_test.php

@@@ -257,6 -257,40 +257,40 @@@ class mod_data_search_test extends adva
          $this->assertEquals($this->approvedatarecordcount, count($recordids));
      }
  
+     public function test_advanced_search_tags() {
+         $this->resetAfterTest();
+         $this->setAdminUser();
+         // Setup test data.
+         $datagenerator = $this->getDataGenerator()->get_plugin_generator('mod_data');
+         $course1 = $this->getDataGenerator()->create_course();
+         $fieldrecord = new StdClass();
+         $fieldrecord->name = 'field-1';
+         $fieldrecord->type = 'text';
+         $fieldrecord->titlefield = true;
+         $data1 = $this->getDataGenerator()->create_module('data', array('course' => $course1->id, 'approval' => true));
+         $field1 = $datagenerator->create_field($fieldrecord, $data1);
+         $record11 = $datagenerator->create_entry($data1, [$field1->field->id => 'value11'], 0, ['Cats', 'Dogs']);
+         $record12 = $datagenerator->create_entry($data1, [$field1->field->id => 'value12'], 0, ['Cats', 'mice']);
+         $record13 = $datagenerator->create_entry($data1, [$field1->field->id => 'value13'], 0, ['Bats']);
+         $searcharray = [];
+         $searcharray[DATA_TAGS] = new stdClass();
+         $searcharray[DATA_TAGS]->params = [];
+         $searcharray[DATA_TAGS]->rawtagnames = ['Cats'];
+         $searcharray[DATA_TAGS]->sql = '';
+         $recordids = data_get_all_recordids($data1->id);
+         $newrecordids = data_get_advance_search_ids($recordids, $searcharray, $data1->id);
+         $this->assertContains($record11, $newrecordids);
+         $this->assertContains($record12, $newrecordids);
+         $this->assertNotContains($record13, $newrecordids);
+     }
      /**
       * Indexing database entries contents.
       *
          // No new records.
          $this->assertFalse($recordset->valid());
          $recordset->close();
 +
 +        // Create a second database, also with one record.
 +        $data2 = $this->getDataGenerator()->create_module('data', ['course' => $course1->id]);
 +        $this->create_default_data_fields($fieldtypes, $data2);
 +        $this->create_default_data_record($data2);
 +
 +        // Test indexing with contexts.
 +        $rs = $searcharea->get_document_recordset(0, context_module::instance($data1->cmid));
 +        $this->assertEquals(1, iterator_count($rs));
 +        $rs->close();
 +        $rs = $searcharea->get_document_recordset(0, context_module::instance($data2->cmid));
 +        $this->assertEquals(1, iterator_count($rs));
 +        $rs->close();
 +        $rs = $searcharea->get_document_recordset(0, context_course::instance($course1->id));
 +        $this->assertEquals(2, iterator_count($rs));
 +        $rs->close();
      }
  
      /**