PHP Classes

File: tests/Auth1Test.php

Recommend this page to a friend!
  Classes of Daniel  >  ohmy-auth  >  tests/Auth1Test.php  >  Download  
File: tests/Auth1Test.php
Role: Unit test script
Content type: text/plain
Description: Unit test script
Class: ohmy-auth
Obtain authorization to access APIs using OAuth
Author: By
Last change: fixed assert
attempt to fix unit test
removed token_secret from tests
fixed classname
added leg static function; organized http and sesssion code into components
Date: 8 months ago
Size: 3,871 bytes
 

Contents

Class file image Download
<?php

/*
 * Copyright (c) 2014, Yahoo! Inc. All rights reserved.
 * Copyrights licensed under the New BSD License.
 * See the accompanying LICENSE file for terms.
 */

use ohmy\Auth1,
   
ohmy\Auth1\Auth1Flow;

class
Auth1Test extends PHPUnit_Framework_TestCase {

    public function
setUp() {}
    public function
tearDown() {}
    public function
testInitTwoLegged() {
       
$phpunit = $this;
       
Auth1::init(2)
             ->
then(function($data) use($phpunit) {
               
$phpunit->assertArrayHasKey('oauth_callback', $data);
               
$phpunit->assertArrayHasKey('oauth_consumer_key', $data);
               
$phpunit->assertArrayHasKey('oauth_consumer_secret', $data);
               
$phpunit->assertArrayHasKey('oauth_nonce', $data);
               
$phpunit->assertArrayHasKey('oauth_signature_method', $data);
               
$phpunit->assertArrayHasKey('oauth_timestamp', $data);
               
$phpunit->assertArrayHasKey('oauth_token', $data);
               
$phpunit->assertArrayHasKey('oauth_verifier', $data);
               
$phpunit->assertArrayHasKey('oauth_version', $data);
            });
    }
    public function
testLegsTwoLegged() {
       
$phpunit = $this;
       
Auth1::legs(2)
            ->
then(function($data) use($phpunit) {
               
$phpunit->assertArrayHasKey('oauth_callback', $data);
               
$phpunit->assertArrayHasKey('oauth_consumer_key', $data);
               
$phpunit->assertArrayHasKey('oauth_consumer_secret', $data);
               
$phpunit->assertArrayHasKey('oauth_nonce', $data);
               
$phpunit->assertArrayHasKey('oauth_signature_method', $data);
               
$phpunit->assertArrayHasKey('oauth_timestamp', $data);
               
$phpunit->assertArrayHasKey('oauth_token', $data);
               
$phpunit->assertArrayHasKey('oauth_verifier', $data);
               
$phpunit->assertArrayHasKey('oauth_version', $data);
            });
    }
    public function
testInitThreeLegged() {
       
$phpunit = $this;
       
Auth1::init(3)
            ->
then(function($data) use($phpunit) {
               
$phpunit->assertArrayHasKey('oauth_callback', $data);
               
$phpunit->assertArrayHasKey('oauth_consumer_key', $data);
               
$phpunit->assertArrayHasKey('oauth_consumer_secret', $data);
               
$phpunit->assertArrayHasKey('oauth_nonce', $data);
               
$phpunit->assertArrayHasKey('oauth_signature_method', $data);
               
$phpunit->assertArrayHasKey('oauth_timestamp', $data);
               
$phpunit->assertArrayHasKey('oauth_token', $data);
               
$phpunit->assertArrayHasKey('oauth_verifier', $data);
               
$phpunit->assertArrayHasKey('oauth_version', $data);
            });
    }
    public function
testLegsThreeLegged() {
       
$phpunit = $this;
       
Auth1::legs(3)
            ->
then(function($data) use($phpunit) {
               
$phpunit->assertArrayHasKey('oauth_callback', $data);
               
$phpunit->assertArrayHasKey('oauth_consumer_key', $data);
               
$phpunit->assertArrayHasKey('oauth_consumer_secret', $data);
               
$phpunit->assertArrayHasKey('oauth_nonce', $data);
               
$phpunit->assertArrayHasKey('oauth_signature_method', $data);
               
$phpunit->assertArrayHasKey('oauth_timestamp', $data);
               
$phpunit->assertArrayHasKey('oauth_token', $data);
               
$phpunit->assertArrayHasKey('oauth_verifier', $data);
               
$phpunit->assertArrayHasKey('oauth_version', $data);
            });
    }

    public function
testFlowSet() {
       
$phpunit = $this;
       
$flow = new Auth1Flow(function($resolve) { $resolve(array()); });
       
$flow->set('foo', 'bar')
             ->
then(function($data) use($phpunit) {
               
$phpunit->assertArrayHasKey('foo', $data);
             });
    }

}

For more information send a message to info at phpclasses dot org.