| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  | namespace Unit\OAuth2\Service; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use Dotenv\Dotenv; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use OAuth\Common\Consumer\Credentials; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use OAuth\Common\Storage\Session; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use OAuth\OAuth2\Service\MicrosoftGraph; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | use OAuth\OAuth2\Token\TokenInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  * Class MicrosoftGraph | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  * @package Unit\OAuth2\Service | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  * @author Juan Diaz - FuriosoJack <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | class MicrosoftGraphTest extends \PHPUnit_Framework_TestCase | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |      * Test para correcta construccion con interfaces | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 21 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 22 |  |  |     public function testConstructCorrectInterfaceWithoutCustomUri() | 
            
                                                                        
                            
            
                                    
            
            
                | 23 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 24 |  |  |         $service = new MicrosoftGraph( | 
            
                                                                        
                            
            
                                    
            
            
                | 25 |  |  |             $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), | 
            
                                                                        
                            
            
                                    
            
            
                | 26 |  |  |             $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), | 
            
                                                                        
                            
            
                                    
            
            
                | 27 |  |  |             $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') | 
            
                                                                        
                            
            
                                    
            
            
                | 28 |  |  |         ); | 
            
                                                                        
                            
            
                                    
            
            
                | 29 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 30 |  |  |         $this->assertInstanceOf('\\OAuth\\OAuth2\\Service\\ServiceInterface', $service); | 
            
                                                                        
                            
            
                                    
            
            
                | 31 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |      * Test para correcta construccion de la instancia como servicio abstracto | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |     public function testConstructCorrectInstanceWithoutCustomUri() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |         $service = new MicrosoftGraph( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |             $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |             $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |             $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |         $this->assertInstanceOf('\\OAuth\\OAuth2\\Service\\AbstractService', $service); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |      * Test para correcta construccion de la instancia con scopes y uriApi interface | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |     public function testConstructCorrectInstanceWithCustomUri() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |         $service = new MicrosoftGraph( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |             $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |             $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |             $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |             array(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |             $this->getMock('\\OAuth\\Common\\Http\\Uri\\UriInterface') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |         $this->assertInstanceOf('\\OAuth\\OAuth2\\Service\\AbstractService', $service); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |      * Test de obtenecion de url de autorizacion | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |     public function testGetAuthorizationEndpoint() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |         $service = new MicrosoftGraph( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |             $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |             $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |             $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |         $this->assertSame('https://login.microsoftonline.com/common/oauth2/authorize', $service->getAuthorizationEndpoint()->getAbsoluteUri()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |      * Test para obtencion de url de endpoint del token | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |     public function testGetAccessTokenEndpoint() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |         $service = new MicrosoftGraph( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |             $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |             $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |             $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |         $this->assertSame('https://login.microsoftonline.com/common/oauth2/token', $service->getAccessTokenEndpoint()->getAbsoluteUri()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |  | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 91 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 92 |  |  | } |