<commit_before><?php

namespace Kajona\System\Tests;

use Kajona\System\Admin\AdminInterface;
use Kajona\System\Portal\PortalInterface;
use Kajona\System\System\AdminskinHelper;
use Kajona\System\System\Carrier;
use Kajona\System\System\Classloader;
use Kajona\System\System\Reflection;
use Kajona\System\System\Resourceloader;
use Kajona\System\System\StringUtil;
use ReflectionClass;
use ReflectionMethod;

class GeneralActionTest extends Testbase
{


    public function testAdminModules()
    {

        AdminskinHelper::defineSkinWebpath();
        Carrier::getInstance()->getObjRights()->setBitTestMode(true);

        //load all admin-classes
        $arrFiles = Resourceloader::getInstance()->getFolderContent("/admin", array(".php"), false, null,
            function (&$strOneFile, $strPath) {
                $strOneFile = Classloader::getInstance()->getInstanceFromFilename($strPath, "Kajona\\System\\Admin\\AdminController", null, array(), true);
            });

        foreach ($arrFiles as $objAdminInstance) {
            if ($objAdminInstance !== null) {
                $this->runSingleFile($objAdminInstance);
            }
        }

        Carrier::getInstance()->getObjRights()->setBitTestMode(false);

    }


    public function testPortalModules()
    {


        Carrier::getInstance()->getObjRights()->setBitTestMode(true);

        //load all admin-classes
        $arrFiles = Resourceloader::getInstance()->getFolderContent("/portal", array(".php"), false, null,
            function (&$strOneFile, $strPath) {
                if($strOneFile == "global_includes.php") {
                    $strOneFile = null;
                    return;
                }
                $strOneFile = Classloader::getInstance()->getInstanceFromFilename($strPath, "Kajona\\System\\Portal\\PortalController", null, array(), true);
            });

        foreach ($arrFiles as $objPortalInstance) {
            if ($objPortalInstance !== null) {
                $this->runSingleFile($objPortalInstance);
            }
        }

        Carrier::getInstance()->getObjRights()->setBitTestMode(false);

    }


    /**
     * @param AdminInterface|PortalInterface $objViewInstance
     */
    private function runSingleFile($objViewInstance)
    {

        $objReflection = new ReflectionClass($objViewInstance);
        $arrMethods = $objReflection->getMethods();

        $objAnnotations = new Reflection(get_class($objViewInstance));

        //collect the autotestable annotations located on class-level
        foreach ($objAnnotations->getAnnotationValuesFromClass("@autoTestable") as $strValue) {
            foreach (explode(",", $strValue) as $strOneMethod) {
                //echo "found method " . get_class($objViewInstance) . "@" . $strOneMethod . " marked as class-based @autoTestable, preparing call\n";
                //echo "   calling via action() method\n";
                $objViewInstance->action($strOneMethod);
            }
        }


        /** @var ReflectionMethod $objOneMethod */
        foreach ($arrMethods as $objOneMethod) {

            if ($objAnnotations->hasMethodAnnotation($objOneMethod->getName(), "@autoTestable")) {
                //echo "found method " . get_class($objViewInstance) . "@" . $objOneMethod->getName() . " marked as @autoTestable, preparing call\n";

                if (StringUtil::substring($objOneMethod->getName(), 0, 6) == "action" && $objReflection->hasMethod("action")) {
                    //echo "   calling via action() method\n";
                    $objViewInstance->action(StringUtil::substring($objOneMethod->getName(), 6));
                } else {
                    //echo "   direct call";
                    $objOneMethod->invoke($objViewInstance);
                }
            }
        }

    }

}
<commit_msg>UPDATE: module_system | GeneralActionTest > allow exception handling<commit_after><?php

namespace Kajona\System\Tests;

use Kajona\System\Admin\AdminInterface;
use Kajona\System\Portal\PortalInterface;
use Kajona\System\System\AdminskinHelper;
use Kajona\System\System\Carrier;
use Kajona\System\System\Classloader;
use Kajona\System\System\RedirectException;
use Kajona\System\System\Reflection;
use Kajona\System\System\Resourceloader;
use Kajona\System\System\StringUtil;
use ReflectionClass;
use ReflectionMethod;

class GeneralActionTest extends Testbase
{


    public function testAdminModules()
    {

        AdminskinHelper::defineSkinWebpath();
        Carrier::getInstance()->getObjRights()->setBitTestMode(true);

        //load all admin-classes
        $arrFiles = Resourceloader::getInstance()->getFolderContent("/admin", array(".php"), false, null,
            function (&$strOneFile, $strPath) {
                $strOneFile = Classloader::getInstance()->getInstanceFromFilename($strPath, "Kajona\\System\\Admin\\AdminController", null, array(), true);
            });

        foreach ($arrFiles as $objAdminInstance) {
            if ($objAdminInstance !== null) {
                $this->runSingleFile($objAdminInstance);
            }
        }

        Carrier::getInstance()->getObjRights()->setBitTestMode(false);

    }


    public function testPortalModules()
    {


        Carrier::getInstance()->getObjRights()->setBitTestMode(true);

        //load all admin-classes
        $arrFiles = Resourceloader::getInstance()->getFolderContent("/portal", array(".php"), false, null,
            function (&$strOneFile, $strPath) {
                if($strOneFile == "global_includes.php") {
                    $strOneFile = null;
                    return;
                }
                $strOneFile = Classloader::getInstance()->getInstanceFromFilename($strPath, "Kajona\\System\\Portal\\PortalController", null, array(), true);
            });

        foreach ($arrFiles as $objPortalInstance) {
            if ($objPortalInstance !== null) {
                $this->runSingleFile($objPortalInstance);
            }
        }

        Carrier::getInstance()->getObjRights()->setBitTestMode(false);

    }


    /**
     * @param AdminInterface|PortalInterface $objViewInstance
     */
    private function runSingleFile($objViewInstance)
    {

        $objReflection = new ReflectionClass($objViewInstance);
        $arrMethods = $objReflection->getMethods();

        $objAnnotations = new Reflection(get_class($objViewInstance));

        //collect the autotestable annotations located on class-level
        foreach ($objAnnotations->getAnnotationValuesFromClass("@autoTestable") as $strValue) {
            foreach (explode(",", $strValue) as $strOneMethod) {
                //echo "found method " . get_class($objViewInstance) . "@" . $strOneMethod . " marked as class-based @autoTestable, preparing call\n";
                //echo "   calling via action() method\n";
                try {
                    $objViewInstance->action($strOneMethod);
                } catch (RedirectException $e) {
                    // redirect exceptions are allowed
                }
            }
        }


        /** @var ReflectionMethod $objOneMethod */
        foreach ($arrMethods as $objOneMethod) {

            if ($objAnnotations->hasMethodAnnotation($objOneMethod->getName(), "@autoTestable")) {
                //echo "found method " . get_class($objViewInstance) . "@" . $objOneMethod->getName() . " marked as @autoTestable, preparing call\n";

                if (StringUtil::substring($objOneMethod->getName(), 0, 6) == "action" && $objReflection->hasMethod("action")) {
                    //echo "   calling via action() method\n";
                    $objViewInstance->action(StringUtil::substring($objOneMethod->getName(), 6));
                } else {
                    //echo "   direct call";
                    $objOneMethod->invoke($objViewInstance);
                }
            }
        }

    }

}

{'fraction_non_alphanumeric': 0.13114754098360656, 'fraction_numerical': 0.0007624857033930614, 'mean_word_length': 2.4700176366843034, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 54, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3618452', 'n_tokens_mistral': 2147, 'n_tokens_neox': 2062, 'n_words': 371}