00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010 class SimpleTestController extends ControllerBase {
00011
00012
00013
00014 public function get_routes() {
00015 return array(
00016 new ExactMatchRoute('simpletest/run', $this, 'run_tests', new NoCacheCacheManager()),
00017 new ExactMatchRoute('simpletest/send_test_mail', $this, 'simpletest_send_test_mail', new NoCacheCacheManager())
00018 );
00019 }
00020
00021
00022
00023
00024
00025
00026 public function action_run_tests($page_data) {
00027 ob_start();
00028 Load::components('GyroUnitTestCase');
00029
00030
00031 $suite = new TestSuite('Gyro Tests');
00032 $base_dirs = Load::get_base_directories();
00033 foreach($base_dirs as $dir) {
00034 foreach (gyro_glob($dir . 'simpletests/*.test.php') as $inc) {
00035 $suite->addFile($inc);
00036 }
00037 }
00038
00039 Load::directories('simpletests/mocks');
00040 $suite->run(new DefaultReporter());
00041 ob_flush();
00042 exit();
00043 }
00044
00045
00046
00047
00048
00049
00050
00051 public function action_simpletest_send_test_mail(PageData $page_data) {
00052 $err = new Status();
00053 Load::components('mailmessage');
00054
00055
00056 $text = 'This is a text message with ümlauts';
00057 $mail = new MailMessage('Testmail 1 (Plain) with Ümlauts', $text, Config::get_value(Config::MAIL_ADMIN));
00058 $err->merge($mail->send());
00059
00060
00061 $text = html::h('Heading', 1) . html::p('This is a HTML message with ümlauts');
00062 $mail = new MailMessage('Testmail 2 (HTML)', $text, Config::get_value(Config::MAIL_ADMIN), '', MailMessage::MIME_HTML);
00063 $err->merge($mail->send());
00064
00065
00066 $text = html::h('Heading', 1) . html::p('This is a HTML message with ümlauts and 1 Attachment');
00067 $mail = new MailMessage('Testmail 3 (HTML + Attachment)', $text, Config::get_value(Config::MAIL_ADMIN), '', MailMessage::MIME_HTML);
00068 $mail->add_attachment(dirname(__FILE__) . '/test.pdf', 'a_test.pdf');
00069 $err->merge($mail->send());
00070
00071
00072 $text = html::h('Heading', 1) . html::p('This is the HTML part of a alternate message');
00073 $mail = new MailMessage('Testmail 4 (HTML + Alternate + Attachment)', $text, Config::get_value(Config::MAIL_ADMIN), '', MailMessage::MIME_HTML);
00074 $mail->set_alt_message('This is the plain text alternative text.');
00075 $mail->add_attachment(dirname(__FILE__) . '/test.pdf', 'a_test.pdf');
00076 $err->merge($mail->send());
00077
00078 if ($err->is_ok()) {
00079 $err = new Message('OK. Mail was probably send successful');
00080 }
00081 $page_data->status = $err;
00082 }
00083 }