edemo / Joomla_oauth_plugin

Joomla plugin for logging in with eDemo SSO service
1 stars 1 forks source link

Segitség kérés #14

Closed utopszkij closed 7 years ago

utopszkij commented 7 years ago

Ha az alabbi file-t beteszem a "develop" branch test konyvtaraba akkor a UNIT Test "PHP Fatal error AdaloginController undefined..." hibauzenetet ad. En ha a szemem kinezem akkor sem latok benne hibat. Enelkul a file nelkul a unittest lemegy. Az ott leve adminControlleTestr file is teljesen hasonlo szerkezetu, es azt elfogadja. Nem ertem.

<?php
require_once "tests/testJoomlaFramework.php";

class adaloginControllerTest extends PHPUnit_Framework_TestCase {
    function __construct() {
        global $testData,$componentName,$viewName;
        $componentName = 'Adalogin';
        $viewName = 'adalogin';
        define('JPATH_COMPONENT', 'adalogin/site');
        require_once "adalogin/site/controller.php";
    }
    protected function setupConfig() {
        global $testData,$componentName;
        $testData->clear();
        $testData->addDbResult(JSON_decode('{
        "id":1, 
        "ADA_AUTH_URI":"https://adatom.hu/ada/v1/oauth2/auth", 
        "ADA_USER_URI":"https://adatom.hu/ada/v1/users/me", 
        "ADA_TOKEN_URI":"https://adatom.hu/ada/v1/oauth2/token", 
        "appkey":"APP_ID_COMES_HERE", 
        "secret":"secret_comes_here", 
        "joomla_psw":"joomla_psw_comes_here"
        }'));
    }

    public function test_loginform()  {
        global $testData,$componentName;
        $this->setupConfig();
        $controller = new AdaloginController();
        $controller->loginform();
        $this->assertEquals(
            'https://adatom.hu/ada/v1/oauth2/auth?response_type=code&client_id=APP_ID_COMES_HERE&redirect_uri=https%3A%2F%2Flocalhost%2Fcomponents%2Fcom_adalogin%2Findex.php%3Fredi%3DaHR0cDovL2xvY2FsaG9zdC8%3D',
            $testData->mock_data['redirectURI']);
    }
    public function test_dologin_new_user()  {
        global $testData,$componentName;
        $this->setupConfig();
        $testData->addDbResult(false);
        $testData->setInput('adaid',123);
        $testData->setInput('adaemail','test@test.hu');
        $testData->setInput('assurance','["magyar"]');
        $testData->setInput('redi','');
        $controller = new AdaloginController();
        $controller->dologin();
        $this->expectOutputRegex('/testJoomlaFramwork view\.display regist/');   
    } 
    public function test_dologin_user_exists()  {
        global $testData,$componentName;
        $this->setupConfig();
        $testData->addDbResult(JSON_decode('{
        "id":1, 
        "username":"testElek" 
        }'));
        $testData->setInput('adaid',123);
        $testData->setInput('adaemail','test@test.hu');
        $testData->setInput('assurance','["magyar"]');
        $testData->setInput('redi',base64_encode('http://localhost/redi.php'));
        $controller = new AdaloginController();
        $controller->dologin();
        $this->assertEquals(
            'http://localhost/redi.php',
            $testData->mock_data['redirectURI']);
    } 
    public function test_processform_ok()  {
        global $testData,$componentName;
        $this->setupConfig();
        $testData->addDbResult(false);

        $testData->setInput('adaid',123);
        $testData->setInput('adaemail','test@test.hu');
        $testData->setInput('assurance','["magyar"]');
        $testData->setInput('nick','testElek');
        $testData->setInput('redi',base64_encode('http://localhost/redi.php'));
        $controller = new AdaloginController();
        $controller->processform();
        $this->assertEquals(
            'http://localhost/redi.php',
            $testData->mock_data['redirectURI']);
    } 
    public function test_processform_nick_empty()  {
        global $testData,$componentName;
        $this->setupConfig();
        $testData->addDbResult(false);
        $testData->setInput('adaid',123);
        $testData->setInput('adaemail','test@test.hu');
        $testData->setInput('assurance','["magyar"]');
        $testData->setInput('nick','');
        $testData->setInput('redi',base64_encode('http://localhost/redi.php'));
        $controller = new AdaloginController();
        $controller->processform();
        $this->expectOutputRegex('/testJoomlaFramwork view\.display regist/');   
    } 
    public function test_processform_nick_used()  {
        global $testData,$componentName;
        $this->setupConfig();
        $testData->addDbResult(JSON_encode('{"id":2,"username":"testElek"}'));
        $testData->setInput('adaid',123);
        $testData->setInput('adaemail','test@test.hu');
        $testData->setInput('assurance','["magyar"]');
        $testData->setInput('nick','testElek');
        $testData->setInput('redi',base64_encode('http://localhost/redi.php'));
        $controller = new AdaloginController();
        $controller->processform();
        $this->expectOutputRegex('/testJoomlaFramwork view\.display regist/');   
    } 

}
?>
magwas commented 7 years ago

tudnál csinálni egy külön branchet, amelyikben ez benne van?

utopszkij commented 7 years ago

megprobálom...

utopszkij commented 7 years ago

megvan a branch: develop-unittest-gond. S commit ugyan zöldnek látszik, de ha megynitod a snippable log file-t akkor abban látszik a fatal error (a build_ci reszben)

magwas commented 7 years ago

az a probléma, hogy két AdaloginController osztályod van. Az egyis a site-ban, a másik az admin-ban. A unit tesztek között pedig van olyan, amelyik a site-ot, és olyan is, amelyik az admin-t require-eli. Emiatt névütközés van. Vagy nevezd át az egyiket, vagy tedd őket külön namespace-be.

utopszkij commented 7 years ago

Hát ez bizony lehet. Viszont a joomlának sajnos ez a név konvenciója. esetleg a az unittest két teljesen külön menetben testekne két külön test könyvtárat: test-site és test-admin ?

utopszkij commented 7 years ago

nekem mondjuk az is fura, hogy ha az unittest fatál erroral elszáll akkor zöld lesz a branch commit.....

utopszkij commented 7 years ago

sajnos a namespace kezelés nagyon szar a php -ban. Minden egyes fileba be kellene irni ehez egy sort. Ez nem megoldás.

utopszkij commented 7 years ago

a test két külön álló phpunittest futásra bontása megoldotta a gondot. :)

utopszkij commented 7 years ago

Megoldva.