Commit a4249d41 authored by Chris Graham's avatar Chris Graham
Browse files

Fixed MANTIS-4534 (Various language string fixes)

parent a89d4b15
Loading
Loading
Loading
Loading
+110 −0
Original line number Diff line number Diff line
<?php /*

 Composr
 Copyright (c) ocProducts, 2004-2016

 See text/EN/licence.txt for full licencing information.

*/

/**
 * @license    http://opensource.org/licenses/cpal_1.0 Common Public Attribution License
 * @copyright  ocProducts Ltd
 * @package    testing_platform
 */

/**
 * Composr test case class (unit testing).
 */
class lang_missing_parameters_test_set extends cms_test_case
{
    public function testNoMissingParams()
    {
        disable_php_memory_limit();

        require_code('files2');

        require_all_lang();

        // Can only test simple call patterns

        $files = get_directory_contents(get_file_base(), get_file_base()); // TODO: In v11 specify only .php files
        foreach ($files as $path) {
            // TODO: Not needed in v11
            if (substr($path, -4) != '.php') {
                continue;
            }
            if (strpos($path, '/exports/') !== false) {
                continue;
            }

            $c = file_get_contents($path);

            // Regexps cannot do nesting, so strip common stuff that gets in our way
            $c = preg_replace('#\[\'\w+\'\]#', '', $c);
            $c = preg_replace('#is_object\(\$\w+\) \? \$\w+->evaluate\(\) : (\$\w+)#', '$1', $c);
            if (strpos($c, '()') !== false) {
                $c = str_replace('()', '', $c);
            }
            foreach (array('get_username', 'integer_format', 'float_format', 'strval', 'strip_comcode', 'escape_html') as $strippable_func) {
                if (strpos($c, $strippable_func) !== false) {
                    $c = preg_replace('#' . $strippable_func . '\(([^()]*)\)#', '$1', $c);
                }
            }

            $matches = array();
            $num_matches = preg_match_all('#do_lang(_tempcode)?\(\'(\w+)\'(, [^(),]*)?(, [^(),]*)?(, [^(),]*)?\)#', $c, $matches, PREG_SET_ORDER | PREG_OFFSET_CAPTURE);
            for ($i = 0; $i < $num_matches; $i++) {
                $num_params = 0;
                if (!empty($matches[$i][3][0])) {
                    $num_params++;
                    if (!empty($matches[$i][4][0])) {
                        $num_params++;
                        if (!empty($matches[$i][5][0])) {
                            $num_params++;
                        }
                    }
                }
                $pass = $this->_test_lang_string($matches[$i][2][0], $num_params, $matches[$i][0][1], $c, $path);
                if ((!empty($_GET['debug'])) && (!$pass)) { // TODO: Use $this->debug in v11
                    exit();
                }
            }

            $matches = array();
            $num_matches = preg_match_all('#do_lang(_tempcode)?\(\'(\w+)\', [^(),]*, [^(),]*, array\(([^(),]*(, [^(),]*)*)\)\)#s', $c, $matches, PREG_SET_ORDER | PREG_OFFSET_CAPTURE); // TODO: New array syntax in v11
            for ($i = 0; $i < $num_matches; $i++) {
                $num_params = 2 + substr_count($matches[$i][3][0], ',') + 1;
                $pass = $this->_test_lang_string($matches[$i][2][0], $num_params, $matches[$i][0][1], $c, $path);
                if ((!empty($_GET['debug'])) && (!$pass)) { // TODO: Use $this->debug in v11
                    exit();
                }
            }
        }
    }

    protected function _test_lang_string($string_codename, $num_params, $offset, $c, $path)
    {
        // Exceptions
        if (in_array($string_codename, array(
            'AUTO_SPACER_TAKE_RESPONSIBILITY',
            'FLOOD_CONTROL_BLOCKED',
            'INTRO_POST_DEFAULT',
        ))) {
            return true;
        }

        $line_num = substr_count($c, "\n", 0, $offset) + 1;

        $params = array_fill(1, $num_params, 'xxx');
        $params[0] = $string_codename;
        ksort($params);

        $result = call_user_func_array('do_lang', $params);

        $pass = preg_match('#\{\d+\}#', $result) == 0;
        $this->assertTrue($pass, 'Issue with call to \'' . $string_codename . '\' in ' . $path . ' on line ' . strval($line_num));

        return $pass;
    }
}
+1 −1
Original line number Diff line number Diff line
@@ -547,7 +547,7 @@ class Module_cms_galleries extends Standard_crud_module
                                $more = zip_entry_read($entry);
                                if ($more !== false) {
                                    if (fwrite($myfile2, $more) < strlen($more)) {
                                        warn_exit(do_lang_tempcode('COULD_NOT_SAVE_FILE_TMP'));
                                        warn_exit(do_lang_tempcode('COULD_NOT_SAVE_FILE', escape_html($tmp_name_2)));
                                    }
                                }
                            } while (($more !== false) && ($more != ''));
+1 −1
Original line number Diff line number Diff line
@@ -944,7 +944,7 @@ class Module_cms_booking_bookings extends Standard_crud_module
     */
    public function create_selection_list_choose_table($url_map)
    {
        attach_message(do_lang_tempcode('EASIER_TO_EDIT_BOOKING_VIA_MEMBER'), 'inform', true);
        attach_message(do_lang_tempcode('EASIER_TO_EDIT_BOOKING_VIA_MEMBER', escape_html(static_evaluate_tempcode(build_url(array('page' => 'members'), get_module_zone('members'))))), 'inform', true);

        require_code('templates_results_table');

+1 −1
Original line number Diff line number Diff line
@@ -216,7 +216,7 @@ CUSTOM_FIELDS_FOR=Custom fields for: {1}
EDITING_CUSTOM_FIELDS_HELP=You are editing the custom fields of a content type ({1}). Custom fields work by automatically binding a catalogue with a content type: each entry of the content type gets an auto-associated entry in the catalogue. Fields you create here will appear on the add/edit form for the content type.
NOTIFICATION_TYPE_catalogue_view_reports=View reports for my {1} entries
NOTIFICATION_TYPE_catalogue_entry=New {1} entry added
CATALOGUE_ENTRY_NOTIFICATION_MAIL_SUBJECT=New {4} entry, {2}
CATALOGUE_ENTRY_NOTIFICATION_MAIL_SUBJECT=New {3} entry, {2}
CATALOGUE_ENTRY_NOTIFICATION_MAIL=A new {4} entry, {2}, has been added to {1}. You can view it from the following URL:\n[url="{3}"]{3}[/url]
ACTIVITY_CATALOGUE_GENERIC_ADD=Added {1|a|an} {1} entry, <a href="{4}">{2}</a>
ACTIVITY_VALIDATE_CATALOGUE_GENERIC=Approved {1|a|an} {1} entry, <a href="{4}">{2}</a>
+1 −1
Original line number Diff line number Diff line
@@ -189,7 +189,7 @@ OPEN_CHATROOMS_IN_TABS=Enter more than one chatroom at once by opening in differ
CHATTING=Chatting
LOWLEVEL_PERMISSIONS=Low-level permissions
Q_SURE_BAN=Are you sure you want to proceed with banning <strong>{1}</strong> from this chatroom?
Q_SURE_UNBAN=Are you sure you want to proceed with unbanning <strong>{2}</strong> from this chatroom?
Q_SURE_UNBAN=Are you sure you want to proceed with unbanning <strong>{1}</strong> from this chatroom?
MUST_ADD_CONTACTS=If you want to invite a user who is not listed under your contacts type in their name and add them below&hellip;
CONFIG_OPTION_group_private_chatrooms=Enable members to limit private chatrooms by usergroup.
GROUP_PRIVATE_CHATROOMS=Access-restricted private chatrooms
Loading