<commit_before><?php

use Mockery as m;

class AgreementTest extends PHPUnit_Framework_TestCase {

    public $config;
    public $token;

    public function __construct()
    {
        $this->config = require_once __DIR__. '/../echosign-auth.php';
        $this->token = m::mock('Echosign\Token');
        $this->token->shouldReceive('getAccessToken')->andReturn('<KEY>');

    }

    public function testCreate()
    {
        $return = [
            "embeddedCode"=> "<script type='text/javascript' language='JavaScript' src='https://secure.echosign.com/embed/public/apiLogin?aalc=<KEY>*&noChrome=true'></script>",
            "expiration"=> "2014-07-07T08:39:24-07:00",
            "agreementId"=> "2AAABLblqZhBXIFwsI6hzV5IzticsCNYH2wZFgfEdo8mhhpOMZR261g3d5tR9RHpg6ckTZFftG2o*",
            "url"=> "https://secure.echosign.com/public/apiLogin?aalc=<KEY>*"
        ];

        $transport = m::mock('Echosign\Transports\Guzzle');
        $transport->shouldReceive('post')->andReturn($return);

        $agreement = new \Echosign\Agreement($this->token);
        $agreement->setTransport($transport);

        $fileInfos = new \Echosign\Info\FileInfo();
        $fileInfos->setDocumentURL('test.pdf','http://www.yahoo.com','application/pdf');
        $docInfo = new \Echosign\Info\DocumentCreationInfo( $fileInfos, 'test', '<EMAIL>', \Echosign\Info\DocumentCreationInfo::SIGN_ESIGN, \Echosign\Info\DocumentCreationInfo::FLOW_NOT_REQUIRED );

        $response = $agreement->create($docInfo);
        $this->assertInstanceOf('Echosign\Responses\AgreementCreationResponse', $response);
        $this->assertEquals($return['embeddedCode'], $response->getEmbeddedCode());
        $this->assertInstanceOf('\DateTime',$response->getExpiration());
        $this->assertEquals($return['agreementId'], $response->getAgreementId());
        $this->assertEquals($return['url'], $response->getUrl());
    }

    public function testGetAll()
    {
        $returnJson = '{
              "userAgreementList": [
                {
                  "displayDate": "2014-07-07T08:39:24-07:00",<commit_msg>fixed test to reflect the idea that interactive options is needed for the url to come back for an agreement<commit_after><?php

use Mockery as m;

class AgreementTest extends PHPUnit_Framework_TestCase {

    public $config;
    public $token;

    public function __construct()
    {
        $this->config = require_once __DIR__. '/../echosign-auth.php';
        $this->token = m::mock('Echosign\Token');
        $this->token->shouldReceive('getAccessToken')->andReturn('<KEY>');

    }

    public function testCreate()
    {
        $return = [
            "embeddedCode"=> "<script type='text/javascript' language='JavaScript' src='https://secure.echosign.com/embed/public/apiLogin?aalc=2AAABLblqZhCLSCUdCzl12KADeV4p7qZdJGbvZxslHruG00s8isauKjnQGAWd1jHq2d67jT_A8nI1Rha9ijWRxjBcIUZuL3m5dPAPyFKBD8wAB0goNmv1E-NVtpSgKhuZ2PBiVp6BlNI*&noChrome=true'></script>",
            "expiration"=> "2014-07-07T08:39:24-07:00",
            "agreementId"=> "<KEY>*",
            "url"=> "https://secure.echosign.com/public/apiLogin?aalc=<KEY>*"
        ];

        $transport = m::mock('Echosign\Transports\Guzzle');
        $transport->shouldReceive('post')->andReturn($return);

        $agreement = new \Echosign\Agreement($this->token);
        $agreement->setTransport($transport);

        $fileInfos = new \Echosign\Info\FileInfo();
        $fileInfos->setDocumentURL('test.pdf','http://www.yahoo.com','application/pdf');
        $docInfo = new \Echosign\Info\DocumentCreationInfo( $fileInfos, 'test', '<EMAIL>', \Echosign\Info\DocumentCreationInfo::SIGN_ESIGN, \Echosign\Info\DocumentCreationInfo::FLOW_NOT_REQUIRED );
        $interActiveOptions = new Echosign\Options\InteractiveOptions();
        /**
         * if this is not set to true YOU WILL NOT GET BACK A SIGNING URL OR EMBEDDED CODE. OMFG.
         */
        $interActiveOptions->autoLoginUser = true;
        $response = $agreement->create($docInfo, $interActiveOptions);
        $this->assertInstanceOf('Echosign\Responses\AgreementCreationResponse', $response);
        $this->assertEquals($return['embeddedCode'], $response->getEmbeddedCode());
        $this->assertInstanceOf('\DateTime',$response->getExpiration());
        $this->assertEquals($return['agreementId'], $response->getAgreementId());
        $this->assertEquals($return['url'], $response->getUrl());
    }

    public function testGetAll()
    {
        $returnJson = '{
              "userAgreementList": [
                {
                  "displayDate": "2014-07-07T08:39:24-07:00",
{'fraction_non_alphanumeric': 0.15870603560573165, 'fraction_numerical': 0.02323056882327399, 'mean_word_length': 3.451207729468599, 'pattern_counts': {'":': 4, '<': 17, '<?xml version=': 0, '>': 64, 'https://': 4, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5653799', 'n_tokens_mistral': 1552, 'n_tokens_neox': 1449, 'n_words': 193}