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::TokenError ); } public function testConstructInvalidToken(){ $_SERVER['PHP_AUTH_DIGEST'] = str_repeat('f', 40); $_SESSION['permission'] = array(); $postdata = array( 'path' => 'module/method' ); $req = \manager\ModuleRequest::fromPost( $postdata ); $this->assertEquals( $req->error, \manager\ManagerError::TokenError ); } } ?>