예제 #1
0
function qtranxf_test_date($ds)
{
    $cnt = 0;
    foreach ($ds as $fmt => $date_expected) {
        $d = get_the_date($fmt, 1);
        qtranxf_tst_log('qtranxf_test_date: get_the_date(' . $fmt . '): ', $d);
        if (!qtranxf_check_test($d, $date_expected, basename(__FILE__))) {
            ++$cnt;
        }
    }
    return $cnt;
}
function qtranxf_run_test_convertURL($url_mode, $lang)
{
    global $q_config;
    $homeinfo = qtranxf_get_home_info();
    $p = $homeinfo['path'];
    $h = $homeinfo['scheme'] . '://' . $homeinfo['host'] . $p;
    $b = trailingslashit($p);
    //$lang = qtranxf_getLanguage();
    //common tests
    $urls = array('#' => '#', '#tag' => '#tag', 'http://external.domain.com' => 'http://external.domain.com', 'http://external.domain.com/' => 'http://external.domain.com/', 'http://external.domain.com?tr=123#tag' => 'http://external.domain.com?tr=123#tag', 'http://external.domain.com/?tr=123#tag' => 'http://external.domain.com/?tr=123#tag', 'http://external.domain.com?tr=123' => 'http://external.domain.com?tr=123', 'http://external.domain.com/?tr=123' => 'http://external.domain.com/?tr=123', 'http://external.domain.com#tag' => 'http://external.domain.com#tag', 'http://external.domain.com/#tag' => 'http://external.domain.com/#tag');
    $cnt = qtranxf_test_convertURL('Common', $urls, $lang, true);
    $cnt = qtranxf_test_convertURL('Common', $urls, $lang, false);
    $q_config['url_mode'] = $url_mode;
    switch ($url_mode) {
        case QTX_URL_QUERY:
            //qtranxf_tst_log('qtx-test-convertURL: $url_mode=QTX_URL_QUERY: $p=',$p);
            $urls = array($b . '?lang=fr' => $h . '/?lang=' . $lang, $b . '#' => $h . '/?lang=' . $lang, $b . '#tag' => $h . '/?lang=' . $lang . '#tag', $h . '#tag' => $h . '?lang=' . $lang . '#tag', $h . '?lang=fr#tag' => $h . '?lang=' . $lang . '#tag', $b . '?lang=fr&page_id=123#tag' => $h . '/?page_id=123&lang=' . $lang . '#tag', $h . '?page_id=123&lang=fr' => $h . '?page_id=123&lang=' . $lang . '', $h . '?page_id=123&lang=fr#tag' => $h . '?page_id=123&lang=' . $lang . '#tag', $b . '?page_id=123&lang=fr&tab=tab3' => $h . '/?page_id=123&tab=tab3&lang=' . $lang . '', $h . '?page_id=123&lang=fr&tab=tab3#tag' => $h . '?page_id=123&tab=tab3&lang=' . $lang . '#tag');
            $cnt = qtranxf_test_convertURL('QTX_URL_QUERY', $urls, $lang, true);
            $urls = array($b . '?lang=fr' => $h . '/', $b . '#' => $h . '/', $b . '#tag' => $h . '/#tag', $h . '#tag' => $h . '#tag', $h . '?lang=fr#tag' => $h . '#tag', $b . '?lang=fr&page_id=123#tag' => $h . '/?page_id=123#tag', $h . '?page_id=123&lang=fr' => $h . '?page_id=123', $h . '?page_id=123&lang=fr#tag' => $h . '?page_id=123#tag', $b . '?page_id=123&lang=fr&tab=tab3' => $h . '/?page_id=123&tab=tab3', $h . '?page_id=123&lang=fr&tab=tab3#tag' => $h . '?page_id=123&tab=tab3#tag');
            $cnt = qtranxf_test_convertURL('QTX_URL_QUERY', $urls, $lang, false);
            break;
        case QTX_URL_PATH:
            //qtranxf_tst_log('qtx-test-convertURL: $url_mode=QTX_URL_PATH');
            $hp = $h . '/' . $lang;
            $urls = array($b . 'fr' => $hp . '', $h . '/fr' => $hp . '', $b . 'fr/' => $hp . '/', $h . '/fr/' => $hp . '/', $b . '#' => $hp . '/', $b . '#tag' => $hp . '/#tag', $h . '#tag' => $hp . '#tag', $b . 'fr/?lang=fr' => $hp . '/', $h . '/fr?lang=fr#tag' => $hp . '#tag', $b . 'fr/?lang=fr&page_id=123#tag' => $hp . '/?page_id=123#tag', $h . '?page_id=123&lang=fr' => $hp . '?page_id=123', $h . '/fr?page_id=123&lang=fr#tag' => $hp . '?page_id=123#tag', $b . '?page_id=123&lang=fr&tab=tab3' => $hp . '/?page_id=123&tab=tab3', $h . '/fr/?page_id=123&lang=fr&lang=xx&tab=tab3#tag' => $hp . '/?page_id=123&tab=tab3#tag');
            $cnt = qtranxf_test_convertURL('QTX_URL_PATH', $urls, $lang, true);
            $urls = array($b . 'fr' => $h . '', $h . '/fr' => $h . '', $b . 'fr/' => $h . '/', $h . '/fr/' => $h . '/', $b . '#' => $h . '/', $b . '#tag' => $h . '/#tag', $h . '#tag' => $h . '#tag', $b . '?lang=fr' => $h . '/', $h . '?lang=fr' => $h . '', $h . '/fr?lang=fr#tag' => $h . '#tag', $b . 'fr/?lang=fr&page_id=123#tag' => $h . '/?page_id=123#tag', $h . '?page_id=123&lang=fr' => $h . '?page_id=123', $h . '?page_id=123&lang=fr#tag' => $h . '?page_id=123#tag', $b . 'fr/?page_id=123&lang=fr&tab=tab3' => $h . '/?page_id=123&tab=tab3', $h . '/fr/?page_id=123&lang=fr&tab=tab3#tag' => $h . '/?page_id=123&tab=tab3#tag');
            $cnt = qtranxf_test_convertURL('QTX_URL_PATH', $urls, $lang, false);
            break;
        case QTX_URL_DOMAIN:
            //qtranxf_tst_log('qtx-test-convertURL: $url_mode=QTX_URL_DOMAIN');
            $hp = $homeinfo['scheme'] . '://' . $lang . '.' . $homeinfo['host'] . $p;
            $urls = array($b . '?lang=fr' => $hp . '/', $b . '#' => $hp . '/', $h . '?lang=fr#tag' => $hp . '#tag', $b . '?lang=fr&page_id=123#tag' => $hp . '/?page_id=123#tag', $h . '?page_id=123&lang=fr' => $hp . '?page_id=123', $h . '?page_id=123&lang=fr#tag' => $hp . '?page_id=123#tag', $b . '?page_id=123&lang=fr&tab=tab3' => $hp . '/?page_id=123&tab=tab3', $h . '?page_id=123&lang=fr&tab=tab3#tag' => $hp . '?page_id=123&tab=tab3#tag');
            $cnt = qtranxf_test_convertURL('QTX_URL_DOMAIN', $urls, $lang, true);
            $urls = array($b . '?lang=fr' => $h . '/', $b . '#' => $h . '/', $h . '?lang=fr#tag' => $h . '#tag', $b . '?lang=fr&page_id=123#tag' => $h . '/?page_id=123#tag', $h . '?page_id=123&lang=fr' => $h . '?page_id=123', $h . '?page_id=123&lang=fr#tag' => $h . '?page_id=123#tag', $b . '?page_id=123&lang=fr&tab=tab3' => $h . '/?page_id=123&tab=tab3', $h . '?page_id=123&lang=fr&tab=tab3#tag' => $h . '?page_id=123&tab=tab3#tag');
            $cnt = qtranxf_test_convertURL('QTX_URL_DOMAIN', $urls, $lang, false);
            break;
        case QTX_URL_DOMAINS:
            //qtranxf_tst_log('qtx-test-convertURL: $url_mode=QTX_URL_DOMAINS');
            $h = $homeinfo['scheme'] . '://' . $q_config['domains'][$q_config['default_language']] . $p;
            $hp = $homeinfo['scheme'] . '://' . $q_config['domains'][$lang] . $p;
            $urls = array($b . '?lang=fr' => $hp . '/', $b . '#' => $hp . '/', $h . '?lang=fr#tag' => $hp . '#tag', $b . '?lang=fr&page_id=123#tag' => $hp . '/?page_id=123#tag', $h . '?page_id=123&lang=fr' => $hp . '?page_id=123', $h . '?page_id=123&lang=fr#tag' => $hp . '?page_id=123#tag', $b . '?page_id=123&lang=fr&tab=tab3' => $hp . '/?page_id=123&tab=tab3', $h . '?page_id=123&lang=fr&tab=tab3#tag' => $hp . '?page_id=123&tab=tab3#tag');
            $cnt = qtranxf_test_convertURL('QTX_URL_DOMAINS', $urls, $lang, true);
            $urls = array($b . '?lang=fr' => $h . '/', $b . '#' => $h . '/', $h . '?lang=fr#tag' => $h . '#tag', $b . '?lang=fr&page_id=123#tag' => $h . '/?page_id=123#tag', $h . '?page_id=123&lang=fr' => $h . '?page_id=123', $h . '?page_id=123&lang=fr#tag' => $h . '?page_id=123#tag', $b . '?page_id=123&lang=fr&tab=tab3' => $h . '/?page_id=123&tab=tab3', $h . '?page_id=123&lang=fr&tab=tab3#tag' => $h . '?page_id=123&tab=tab3#tag');
            $cnt = qtranxf_test_convertURL('QTX_URL_DOMAINS', $urls, $lang, false);
            break;
        default:
            qtranxf_tst_log('qtx-test-convertURL: unknown $url_mode=', $url_mode);
            return;
    }
}
예제 #3
0
function qtranxf_test_meta_cache()
{
    global $post;
    if (!is_singular() || !$post || 'post' != $post->post_type) {
        qtranxf_tst_log('qtranxf_test_meta_cache: return');
        return;
    }
    $views = get_post_meta($post->ID, 'views', true);
    $views = $views ? $views : 0;
    $views++;
    update_post_meta($post->ID, 'views', $views);
    $views_fetched = get_post_meta($post->ID, 'views', true);
    if (qtranxf_check_test($views_fetched, $views, 'qtranxf_test_meta_cache')) {
        qtranxf_tst_log('qtranxf_test_meta_cache: ok');
    }
    //qtranxf_tst_log('qtranxf_test_meta_cache: views_expected='.$views.'; $views_fetched=',$views_fetched);
}