MessagePreview.php
[Pman.Core] / MessagePreview.php
index 70d412a..03354d7 100644 (file)
@@ -40,8 +40,8 @@ class Pman_Core_MessagePreview extends Pman
             $this->jerr('Missing Options');
         }
         
-        if(!empty($_REQUEST['_send_test']) && $_REQUEST['core_email'])){
-            $this->sendTest();
+        if($_REQUEST['_table'] == 'core_email'){
+            $this->coreEmailSendTest();
         }
         
         $mid = $_REQUEST['_id'];
@@ -65,16 +65,40 @@ class Pman_Core_MessagePreview extends Pman
         
     }
     
-    function sendTest()
+    function coreEmailSendTest()
     {
-        $table = DB_DataObject::factory($_REQUEST['_table']);
+        $core_email = DB_DataObject::factory('core_email');
         
-        if($table->get($_REQUEST['_id'])){
+        if(!$core_email->get($_REQUEST['_id'])){
             $this->jerr('Invalid Message ID');
         }
         
-        if(empty($table->test_class)){
-            
+        if(empty($core_email->test_class)){
+            $this->jerr("[{$core_email->name}] does not has test class");
         }
+        
+        require_once "{$core_email->test_class}.php";
+        
+        $cls = str_replace('/', '_', $core_email->test_class);
+        
+        $x = new $cls;
+        
+        $method = "test_{$core_email->name}";
+        
+        if(!method_exists($x, $method)){
+            $this->jerr("{$method} does not exists in {$cls}");
+        }
+        
+        $content = $x->{$method}($this, $this->authUser);
+        
+        $sent = $this->send($content);
+        
+        if(!is_object($sent)){
+            $this->jok('SUCCESS');
+        }
+        
+        $this->jerr('error!!:' . $sent->toString());
+        
+        
     }
 }