assertEquals( $req->error, \manager\ManagerError::Success ); } public function testConstructNoPath(){ $req = new \manager\ModuleRequest(); $this->assertEquals( $req->error, \manager\ManagerError::MissingPath ); } public function testConstructIncorrectPathType(){ $reqArray = new \manager\ModuleRequest( array(1) ); $this->assertEquals( $reqArray->error, \manager\ManagerError::WrongPathModule ); $reqNumber = new \manager\ModuleRequest( 10 ); $this->assertEquals( $reqNumber->error, \manager\ManagerError::WrongPathModule ); } public function testConstructIncorrectPathSyntax(){ $req = new \manager\ModuleRequest('wrong.syntax'); $this->assertEquals( $req->error, \manager\ManagerError::WrongPathModule ); } public function testConstructIncorrectPathModule(){ $req = new \manager\ModuleRequest( 'unknownModule/method' ); $this->assertEquals( $req->error, \manager\ManagerError::UnknownModule ); } public function testConstructIncorrectPathMethod(){ $req = new \manager\ModuleRequest( 'module/unknownMethod' ); $this->assertEquals( $req->error, \manager\ManagerError::UnknownMethod ); } /* (2) Tests des permissions */ // {1} Gestion des permissions quand l'utilisateur est connecté // public function testConstructNoPermissionsRequired(){ $_SESSION['permission'] = array(); $req = new \manager\ModuleRequest( 'module/method' ); $this->assertEquals( $req->error, \manager\ManagerError::Success ); } public function testConstructPermissionsMissing(){ $_SESSION['permission'] = array(); $req = new \manager\ModuleRequest( 'module/phpunitPermissions' ); $this->assertEquals( $req->error, \manager\ManagerError::PermissionError ); } public function testConstructPermissionsMatch(){ $_SESSION['permission'] = array('a'); $req = new \manager\ModuleRequest( 'module/phpunitPermissions' ); $this->assertEquals( $req->error, \manager\ManagerError::Success ); } public function testConstructPermissionsMatchOther(){ $_SESSION['permission'] = array('b'); $req = new \manager\ModuleRequest( 'module/phpunitPermissions' ); $this->assertEquals( $req->error, \manager\ManagerError::Success ); } public function testConstructPermissionsMatchAll(){ $_SESSION['permission'] = array('a', 'b'); $req = new \manager\ModuleRequest( 'module/phpunitPermissions' ); $this->assertEquals( $req->error, \manager\ManagerError::Success ); } public function testConstructPermissionsDontMatch(){ $_SESSION['permission'] = array('c'); $req = new \manager\ModuleRequest( 'module/phpunitPermissions' ); $this->assertEquals( $req->error, \manager\ManagerError::PermissionError ); } // {2} Gestion des permissions quand un token est joint // public function testConstructNoTokenAndNoConnection(){ // $_SESSION['permission'] = array(); $postdata = array( 'path' => 'module/method' ); $req = \manager\ModuleRequest::fromPost( $postdata ); $this->assertEquals( $req->error, \manager\ManagerError::PermissionError ); } public function testConstructInvalidTokenType(){ $_SERVER['PHP_AUTH_DIGEST'] = str_repeat('f', 10); $postdata = array( 'path' => 'module/method' ); $req = \manager\ModuleRequest::fromPost( $postdata ); $this->assertEquals( $req->error, \manager\ManagerError::PermissionError ); } public function testConstructInvalidTokenValue(){ $_SERVER['PHP_AUTH_DIGEST'] = str_repeat('f', 40); $postdata = array( 'path' => 'module/method' ); $req = \manager\ModuleRequest::fromPost( $postdata ); $this->assertEquals( $req->error, \manager\ManagerError::TokenError ); } public function testConstructValidTokenInBdd(){ $_SERVER['PHP_AUTH_DIGEST'] = '52945efbed43b50c12413f2f0e9519bfd9e98ce8'; $postdata = array( 'path' => 'module/method' ); $req = \manager\ModuleRequest::fromPost( $postdata ); $this->assertEquals( $req->error, \manager\ManagerError::Success ); } /* (3) Gestion des paramètres */ public function testConstructNoParamRequired(){ $_SESSION['permission'] = array(); $req = new \manager\ModuleRequest( 'module/method', array('useless') ); $this->assertEquals( $req->error, \manager\ManagerError::Success ); } public function testConstructMissingParam(){ $_SESSION['permission'] = array(); $req = new \manager\ModuleRequest( 'module/phpunitParams', array() ); $this->assertEquals( $req->error, \manager\ManagerError::ParamError ); } public function testConstructWrongParamType(){ $_SESSION['permission'] = array(); $params = array( 'p1' => 'sometext', 'p2' => 'sometext' ); $req = new \manager\ModuleRequest( 'module/phpunitParams', $params ); $this->assertEquals( $req->error, \manager\ManagerError::ParamError ); } public function testConstructWrongParamTypeOther(){ $_SESSION['permission'] = array(); $params = array( 'p1' => 10, 'p2' => 'sometext' ); $req = new \manager\ModuleRequest( 'module/phpunitParams', $params ); $this->assertEquals( $req->error, \manager\ManagerError::ParamError ); } public function testConstructCorrectParams(){ $_SESSION['permission'] = array(); $params = array( 'p1' => 'sometext', 'p2' => 10 ); $req = new \manager\ModuleRequest( 'module/phpunitParams', $params ); $this->assertEquals( $req->error, \manager\ManagerError::Success ); } public function testConstructParamOrdered(){ $_SESSION['permission'] = array(); $params = array( 'p1' => 'sometext', 'p2' => 10 ); $req = new \manager\ModuleRequest( 'module/phpunitParams', $params ); $ans = $req->dispatch(); $this->assertEquals( $ans->get('p1'), $params['p1'] ); $this->assertEquals( $ans->get('p2'), $params['p2'] ); } public function testConstructParamUnordered(){ $_SESSION['permission'] = array(); $params = array( 'p2' => 10, 'p1' => 'sometext' ); $req = new \manager\ModuleRequest( 'module/phpunitParams', $params ); $ans = $req->dispatch(); $this->assertEquals( $ans->get('p1'), $params['p1'] ); $this->assertEquals( $ans->get('p2'), $params['p2'] ); } } ?>