Example #1
0
 function testScreenPreview()
 {
     require_code('validation');
     require_lang('validation');
     global $DONE_HEADER, $RECORD_TEMPLATES_USED, $RECORDED_TEMPLATES_USED;
     $RECORD_TEMPLATES_USED = true;
     $only_do_these = array();
     $lists = find_all_previews__by_template();
     foreach ($lists as $template => $list) {
         $temp_name = basename($template, '.tpl');
         if (count($only_do_these) != 0) {
             if (!in_array($temp_name, $only_do_these)) {
                 continue;
             }
         }
         if ($temp_name == 'tempcode_test') {
             continue;
         }
         if (is_plain_text_template($temp_name)) {
             continue;
         }
         $hook = $list[0];
         $function = $list[1];
         if (is_file(get_file_base() . '/_tests/screens_tested/' . $function)) {
             continue;
         }
         // To make easier to debug through
         if (function_exists('set_time_limit')) {
             @set_time_limit(0);
         }
         $DONE_HEADER = false;
         $RECORDED_TEMPLATES_USED = array();
         $out = render_screen_preview($template, $hook, $function);
         $flag = false;
         foreach ($lists as $template_2 => $list_2) {
             $temp_name_2 = basename($template_2, '.tpl');
             if (count($only_do_these) != 0) {
                 if (!in_array($temp_name_2, $only_do_these)) {
                     continue;
                 }
             }
             if ($temp_name_2 == 'tempcode_test') {
                 continue;
             }
             if (is_plain_text_template($temp_name_2)) {
                 continue;
             }
             if ($list_2[1] == $function) {
                 if ($temp_name_2 == 'FORM_STANDARD_END' || $temp_name_2 == 'MENU_LINK_PROPERTIES') {
                     continue;
                 }
                 $this->assertTrue(in_array($temp_name_2, $RECORDED_TEMPLATES_USED), $template_2 . ' not used in preview as claimed in ' . $hook . '/' . $function);
                 if (!in_array($temp_name_2, $RECORDED_TEMPLATES_USED)) {
                     $flag = true;
                 }
             }
         }
         if (!is_object($out)) {
             fatal_exit('Claimed screen for ' . $template . ' is not defined');
         }
         $_out = $out->evaluate();
         $result = check_xhtml($_out, false, false, false, true, true, false, false);
         if (!is_null($result) && count($result['errors']) == 0) {
             $result = NULL;
         }
         $this->assertTrue(is_null($result), $hook . '/' . $temp_name);
         if (!is_null($result)) {
             require_code('view_modes');
             display_validation_results($_out, $result, false, false);
         } else {
             if (!$flag) {
                 fclose(fopen(get_file_base() . '/_tests/screens_tested/' . $function, 'wb'));
                 sync_file(get_file_base() . '/_tests/screens_tested/' . $function);
                 fix_permissions(get_file_base() . '/_tests/screens_tested/' . $function);
             }
         }
     }
 }
Example #2
0
 /**
  * Shows the list of templates
  *
  * @return tempcode		The UI
  */
 function list_screen_previews()
 {
     $title = get_page_title('SCREEN_PREVIEWS');
     $GLOBALS['HELPER_PANEL_PIC'] = '';
     $GLOBALS['HELPER_PANEL_TUTORIAL'] = '';
     if (function_exists('set_time_limit')) {
         @set_time_limit(120);
     }
     require_code('lorem');
     // Find all templates
     $templates = array();
     $dh = opendir(get_file_base() . '/themes/default/templates');
     while (($f = readdir($dh)) !== false) {
         if (strtolower(substr($f, -4)) == '.tpl') {
             $templates[] = $f;
         }
     }
     sort($templates);
     // Find all previews (map of templates to previews)
     $all_previews = find_all_previews__by_template();
     // And by screen
     $all_previews__by_screen = find_all_previews__by_screen();
     // Find other things we may want to preview
     $comcode_files = find_comcodes();
     $html_files = find_html();
     // Loop over to display it all
     $displayed_already = array();
     $lis = new ocp_tempcode();
     $lis_admin = new ocp_tempcode();
     foreach ($templates as $t) {
         // If we have a preview for it
         if (array_key_exists($t, $all_previews)) {
             if (!array_key_exists($all_previews[$t][1], $displayed_already)) {
                 $func = $all_previews[$t][1];
                 $preview_url = build_url(array('page' => '_SELF', 'type' => 'view', 'id' => $t, 'hook' => $all_previews[$t][0], 'function' => $func), '_SELF');
                 $template_used = "(" . implode(', ', $all_previews__by_screen[$func]) . ")";
                 $tpl_x = do_template('TEMPLATE_LIST', array('URL' => $preview_url, 'COLOR' => 'green', 'TEMPLATE' => preg_replace('#^tpl_preview\\_\\_#', '', $func), 'LIST' => $template_used));
                 if (preg_match('#^tpl_preview\\_\\_administrative\\_\\_#', $func) != 0) {
                     $lis_admin->attach($tpl_x);
                 } else {
                     $lis->attach($tpl_x);
                 }
                 $displayed_already[$func] = true;
             }
         } elseif (substr($t, 0, 11) != 'JAVASCRIPT_' && $t != 'JAVASCRIPT.tpl') {
             $tpl_x = do_template('TEMPLATE_LIST', array('URL' => '', 'COLOR' => 'red', 'TEMPLATE' => $t, 'LIST' => ''));
             $lis->attach($tpl_x);
         }
     }
     // Prepare all to display...
     $post = new ocp_tempcode();
     /* $lis (the main previews) will be displayed in the main INDEX_SCREEN content */
     /* LISTING ADMIN PREVIEWS */
     $post->attach(do_template('TEMPLATE_LIST_WRAP', array('LI' => $lis_admin, 'TITLE' => do_lang('ADMIN_SCREENS'))));
     /* LISTING COMCODE FILES   */
     $com_li = new ocp_tempcode();
     foreach ($comcode_files as $zone => $pages) {
         if ($zone == 'pages') {
             $zone = "";
         }
         foreach ($pages as $page => $type) {
             if (!is_string($page)) {
                 $page = strval($page);
             }
             $file = $page . '.txt';
             $url = build_url(array('page' => $page), $zone);
             $com_li->attach(do_template('TEMPLATE_LIST', array('URL' => $url, 'COLOR' => '', 'TEMPLATE' => $file, 'LIST' => '')));
         }
     }
     $post->attach(do_template('TEMPLATE_LIST_WRAP', array('LI' => $com_li, 'TITLE' => do_lang('COMCODE_PAGES'))));
     /* LISTING HTML FILES   */
     $htm_li = new ocp_tempcode();
     foreach ($html_files as $zone => $pages) {
         foreach ($pages as $page => $type) {
             $file = $page . '.htm';
             $url = build_url(array('page' => $page), $zone);
             $htm_li->attach(do_template('TEMPLATE_LIST', array('URL' => $url, 'COLOR' => '', 'TEMPLATE' => $file, 'LIST' => '')));
         }
     }
     $post->attach(do_template('TEMPLATE_LIST_WRAP', array('LI' => $htm_li, 'TITLE' => do_lang('HTML_PAGES'))));
     return do_template('INDEX_SCREEN', array('TITLE' => $title, 'CONTENT' => $lis, 'POST' => $post, 'PRE' => ''));
 }