[TYPO3-german] Wie kann ich einen Test für Hook-Funktionen schreiben?

Alexander Averbukh alav at gmx.net
Tue Feb 18 09:23:29 CET 2014


Hallo zusammen,

Ich habe 2 Hook-Funktionen für RealURL geschrieben.
Die Klasse mit den beiden Funktionen sieht so aus:

<?php
class tx_xmrealurl extends tx_realurl {
    var $articleRegex = '/([^\/]*?-\d{4}-\d{2}-\d{2}-a(\d+)\.html)/';

    /*
    * Hook for decodeSpURL_preProc
    * adds the "article" to the path to an article. The realurl-extension needs it to resolve the path
    */
    public function addArticleToPath($params, $obj)
    {
        if (preg_match($this->articleRegex, $params['URL'], $m)) {
            $articleUID = intval($m[2]);
            // retrieve the actual URL-part of the article 
            $res = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('value_alias', 'tx_realurl_uniqalias', 
                                                            'value_id=' . $articleUID . ' AND tablename="tx_news_domain_model_news"', '', 'tstamp DESC', 1);

            // if the requested URL is not match with the URL in the table tx_realurl_uniqalias, do the 301-redirect to URL from the table
            if (is_array($res) && isset($res[0]["value_alias"])) {
                $value_alias = $res[0]["value_alias"] . '.html';
                if ($value_alias != $m[1]) {
                    header('Location: ' . $value_alias, TRUE, 301);
                    exit;
                }
            }
            else {
                // if there is no article with the UID, show the 404-page
                $GLOBALS['TSFE']->pageNotFoundAndExit('Der Artikel mit der UID: ' . $articleUID . ' existiert nicht.');
                return;
            }
        }
        $params['pObj']->extConf['init']['enableCHashCache'] = FALSE;
        $params['URL'] = preg_replace($this->articleRegex, 'artikel/${1}', $params['URL']);
    }


    /*
    * Hook for encodeSpURL_postProc
    * removes "article" from the path to an article
    * the links look like this: http://domain/mannheim/johanniter-grosseinsatz-in-seniorenheim-2014-02-04-a9.html
    */
    public function removeArticleFromPath($params)
    {
        if (preg_match($this->articleRegex, $params['URL'])) {
		    $params['URL'] = str_replace('artikel/', '', $params['URL']);
        }
    }
}
?>

Wie kann ich einen Test schreiben, um die Funktionen zu testen? Das sind keine static-Funktionen, das heißt, man muss eine Instanz der Klasse tx_xmrealurl erstellen. Wie mache ich das? Ich muss dann den Konstruktor von tx_realurl aufrufen und alle benötigten Parameter übergeben. Oder geht es anders? 

Vielen Dank.



More information about the TYPO3-german mailing list