public function test_progres_trace_buffer()
 {
     $this->resetAfterTest(false);
     $trace = new progress_trace_buffer(new html_progress_trace());
     ob_start();
     $trace->output('do');
     $trace->output('re', 1);
     $trace->output('mi', 2);
     $trace->finished();
     $output = ob_get_contents();
     ob_end_clean();
     $this->assertSame("<p>do</p>\n<p>&#160;&#160;re</p>\n<p>&#160;&#160;&#160;&#160;mi</p>\n", $output);
     $this->assertSame($output, $trace->get_buffer());
     $trace = new progress_trace_buffer(new html_progress_trace(), false);
     $trace->output('do');
     $trace->output('re', 1);
     $trace->output('mi', 2);
     $trace->finished();
     $this->assertSame("<p>do</p>\n<p>&#160;&#160;re</p>\n<p>&#160;&#160;&#160;&#160;mi</p>\n", $trace->get_buffer());
     $this->assertSame("<p>do</p>\n<p>&#160;&#160;re</p>\n<p>&#160;&#160;&#160;&#160;mi</p>\n", $trace->get_buffer());
     $trace->reset_buffer();
     $this->assertSame('', $trace->get_buffer());
     $this->expectOutputString('');
 }
Esempio n. 2
0
 /**
  * Execute synchronisation.
  * @param progress_trace
  * @return int exit code, 0 means ok, 2 means plugin disabled
  */
 public function sync(progress_trace $trace)
 {
     if (!enrol_is_enabled('flatfile')) {
         return 2;
     }
     $mailadmins = $this->get_config('mailadmins', 0);
     if ($mailadmins) {
         $buffer = new progress_trace_buffer(new text_progress_trace(), false);
         $trace = new combined_progress_trace(array($trace, $buffer));
     }
     $processed = false;
     $processed = $this->process_file($trace) || $processed;
     $processed = $this->process_buffer($trace) || $processed;
     $processed = $this->process_expirations($trace) || $processed;
     if ($processed and $mailadmins) {
         if ($log = $buffer->get_buffer()) {
             $eventdata = new stdClass();
             $eventdata->modulename = 'moodle';
             $eventdata->component = 'enrol_flatfile';
             $eventdata->name = 'flatfile_enrolment';
             $eventdata->userfrom = get_admin();
             $eventdata->userto = get_admin();
             $eventdata->subject = 'Flatfile Enrolment Log';
             $eventdata->fullmessage = $log;
             $eventdata->fullmessageformat = FORMAT_PLAIN;
             $eventdata->fullmessagehtml = '';
             $eventdata->smallmessage = '';
             message_send($eventdata);
         }
         $buffer->reset_buffer();
     }
     return 0;
 }