server/src/tests/Libraries/Handle/HandleClientIntegrationTest.php
author ymh <ymh.work@gmail.com>
Tue, 08 Nov 2016 18:23:01 +0100
changeset 405 f239c8c5bb94
parent 153 338bcc78d431
child 552 2c579ea45608
permissions -rw-r--r--
migrate to rdf4j (2.1.1) from sesame (4.1.1)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
153
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
     1
<?php
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
     2
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
     3
use Illuminate\Foundation\Testing\WithoutMiddleware;
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
     4
use Illuminate\Foundation\Testing\DatabaseMigrations;
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
     5
use Illuminate\Foundation\Testing\DatabaseTransactions;
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
     6
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
     7
use GuzzleHttp\Client;
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
     8
use GuzzleHttp\Middleware;
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
     9
use GuzzleHttp\HandlerStack;
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    10
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    11
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    12
use CorpusParole\Libraries\Handle\HandleClient;
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    13
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    14
class HandleClientIntegrationTest extends TestCase
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    15
{
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    16
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    17
    public function setUp() {
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    18
        parent::setUp();
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    19
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    20
        $this->handleHost = env('HANDLE_HOST', null);
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    21
        $this->handlePort = env('HANDLE_PORT', 8000);
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    22
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    23
        if(empty($this->handleHost)) {
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    24
            $this->markTestSkipped('Handle host empty');
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    25
        }
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    26
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    27
        $this->testPrefix = env('HANDLE_TEST_PREFIX', null);
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    28
        if(empty($this->testPrefix)) {
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    29
            $this->markTestSkipped('Handle test prefix not defined');
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    30
        }
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    31
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    32
        $certPem = env('HANDLE_TEST_CERT', null);
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    33
        $this->certPemPassword = env('HANDLE_TEST_CERT_PASSWORD', null);
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    34
        $this->certAdminHandle = env('HANDLE_TEST_CERT_ADMIN_HANDLE', null);
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    35
        if(empty($certPem) || empty($this->certAdminHandle)) {
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    36
            $this->markTestSkipped('Handle test certificate or user is empty');
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    37
        }
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    38
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    39
        $dsaPem = env('HANDLE_TEST_DSA_KEY', null);
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    40
        $this->dsaPemPassword = env('HANDLE_TEST_DSA_PASSWORD', null);
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    41
        $this->dsaAdminHandle = env('HANDLE_TEST_DSA_ADMIN_HANDLE', null);
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    42
        if(empty($dsaPem) || empty($this->dsaAdminHandle)) {
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    43
            $this->markTestSkipped('Handle dsa key or user not set');
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    44
        }
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    45
        $this->dsaAdminRawHandle = str_replace("300:", "", $this->dsaAdminHandle);
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    46
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    47
        $rsaPem = env('HANDLE_TEST_RSA_KEY', null);
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    48
        $this->rsaPemPassword = env('HANDLE_TEST_RSA_PASSWORD', null);
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    49
        $this->rsaAdminHandle = env('HANDLE_TEST_RSA_ADMIN_HANDLE', null);
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    50
        if(empty($rsaPem) || empty($this->rsaAdminHandle)) {
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    51
            $this->markTestSkipped('Handle rsa key or user not set');
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    52
        }
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    53
        $this->rsaAdminRawHandle = str_replace("300:", "", $this->rsaAdminHandle);
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    54
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    55
        $this->filesToDelete = [];
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    56
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    57
        if(is_file($certPem)) {
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    58
            $this->certTmpPath = $certPem;
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    59
        } else {
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    60
            $this->certTmpPath = tempnam("/tmp", "CERT_TEST");
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    61
            array_push($this->filesToDelete,$this->certTmpPath);
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    62
            file_put_contents($this->certTmpPath, $certPem);
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    63
        }
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    64
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    65
        if(is_file($dsaPem)) {
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    66
            $this->dsaTmpPath = $dsaPem;
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    67
        } else {
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    68
            $this->dsaTmpPath = tempnam("/tmp", "DSA_TEST");
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    69
            array_push($this->filesToDelete,$this->dsaTmpPath);
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    70
            file_put_contents($this->dsaTmpPath, $dsaPem);
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    71
        }
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    72
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    73
        if(is_file($rsaPem)) {
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    74
            $this->rsaTmpPath = $rsaPem;
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    75
        } else {
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    76
            $this->rsaTmpPath = tempnam("/tmp", "RSA_TEST");
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    77
            array_push($this->filesToDelete,$this->rsaTmpPath);
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    78
            file_put_contents($this->rsaTmpPath, $rsaPem);
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    79
        }
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    80
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    81
        // Create a middleware that echoes parts of the request.
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    82
        // $tapMiddleware = Middleware::tap(function ($request) {
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    83
        //     echo "\n+++++++++++++++++\nREQ HEADERS : ".print_r($request->getHeaders(), true)."\n+++++++++++++++++++\n";
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    84
        //     echo "\n------------------\nREQ BODY : ".$request->getBody()."\n-------------------\n";
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    85
        // });
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    86
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    87
        // $stack = HandlerStack::create();
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    88
        // $stack->push(Middleware::mapResponse(function ($response) {
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    89
        //     echo "\n+++++++++++++++++\nRESP HEADERS : ".print_r($response->getHeaders(), true)."\n+++++++++++++++++++\n";
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    90
        //     echo "\n------------------\nRESP BODY : ".$response->getBody()."\n-------------------\n";
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    91
        //     return $response;
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    92
        // }));
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    93
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    94
        // $this->httpClient = new Client(['debug' => true, 'handler' => $tapMiddleware($stack)]);
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    95
        $this->httpClient = new Client();
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    96
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    97
    }
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    98
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    99
    public function tearDown() {
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
   100
        foreach($this->filesToDelete as $ftd) {
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
   101
            unlink($ftd);
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
   102
        }
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
   103
405
f239c8c5bb94 migrate to rdf4j (2.1.1) from sesame (4.1.1)
ymh <ymh.work@gmail.com>
parents: 153
diff changeset
   104
        //$this->httpClient->delete("repositories/$this->rdf4jRepository");
153
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
   105
        parent::tearDown();
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
   106
    }
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
   107
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
   108
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
   109
    /**
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
   110
     * Test Pagination with DSA key.
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
   111
     *
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
   112
     * @return void
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
   113
     */
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
   114
    public function testPaginateDSA()
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
   115
    {
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
   116
        $handleClient = new HandleClient('file://'.$this->dsaTmpPath, $this->dsaPemPassword, $this->dsaAdminHandle, $this->handleHost, $this->handlePort, $this->httpClient);
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
   117
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
   118
        $pagination = $handleClient->paginateAll($this->testPrefix);
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
   119
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
   120
        $this->assertNotNull($pagination);
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
   121
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
   122
        $this->assertInstanceOf("Illuminate\Pagination\LengthAwarePaginator", $pagination, "Must be a LengthAwarePaginator");
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
   123
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
   124
        $this->assertGreaterThanOrEqual(1, $pagination->count(), "Must have at least 1 handle");
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
   125
        $this->assertGreaterThanOrEqual(1, $pagination->total(), "Total is at least 1");
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
   126
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
   127
    }
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
   128
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
   129
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
   130
    /**
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
   131
     * Test Pagination with RSA key.
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
   132
     *
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
   133
     * @return void
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
   134
     */
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
   135
    public function testPaginateRSA()
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
   136
    {
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
   137
        $handleClient = new HandleClient('file://'.$this->rsaTmpPath, $this->rsaPemPassword, $this->rsaAdminHandle, $this->handleHost, $this->handlePort, $this->httpClient);
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
   138
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
   139
        $pagination = $handleClient->paginateAll($this->testPrefix);
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
   140
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
   141
        $this->assertNotNull($pagination);
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
   142
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
   143
        $this->assertInstanceOf("Illuminate\Pagination\LengthAwarePaginator", $pagination, "Must be a LengthAwarePaginator");
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
   144
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
   145
        $this->assertGreaterThanOrEqual(1, $pagination->count(), "Must have at least 1 handle");
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
   146
        $this->assertGreaterThanOrEqual(1, $pagination->total(), "Total is at least 1");
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
   147
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
   148
    }
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
   149
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
   150
    /**
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
   151
     * Test Pagination with Client Certificate.
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
   152
     *
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
   153
     * @return void
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
   154
     */
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
   155
    public function testPaginateCert()
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
   156
    {
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
   157
        $handleClient = new HandleClient($this->certTmpPath, $this->certPemPassword, $this->certAdminHandle, $this->handleHost, $this->handlePort, $this->httpClient);
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
   158
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
   159
        $pagination = $handleClient->paginateAll($this->testPrefix);
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
   160
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
   161
        $this->assertNotNull($pagination);
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
   162
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
   163
        $this->assertInstanceOf("Illuminate\Pagination\LengthAwarePaginator", $pagination, "Must be a LengthAwarePaginator");
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
   164
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
   165
        $this->assertGreaterThanOrEqual(1, $pagination->count(), "Must have at least 1 handle");
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
   166
        $this->assertGreaterThanOrEqual(1, $pagination->total(), "Total is at least 1");
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
   167
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
   168
    }
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
   169
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
   170
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
   171
    /**
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
   172
     * Test Handle creation
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
   173
     */
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
   174
    public function testCreateHandleUrl() {
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
   175
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
   176
        $handleClient = new HandleClient('file://'.$this->rsaTmpPath, $this->rsaPemPassword, $this->rsaAdminHandle, $this->handleHost, $this->handlePort, $this->httpClient);
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
   177
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
   178
        $pagination = $handleClient->paginateAll($this->testPrefix);
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
   179
        $totalPrev = $pagination->total();
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
   180
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
   181
        $handle = strtoupper(uniqid("$this->testPrefix/TEST_HANDLE_CLIENT_"));
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
   182
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
   183
        //$handle = "$this->testPrefix/TEST_HANDLE_CLIENT_";
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
   184
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
   185
        $handleClient->createHandleUrlRecord($handle, "http://www.example.com");
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
   186
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
   187
        $pagination = $handleClient->paginateAll($this->testPrefix);
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
   188
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
   189
        $this->assertEquals($totalPrev + 1, $pagination->total(), "Must have one more handle");
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
   190
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
   191
        $this->assertContains($handle, $pagination);
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
   192
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
   193
        $handleClient->deleteHandle($handle);
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
   194
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
   195
    }
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
   196
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
   197
    /**
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
   198
     * Test Handle delete
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
   199
     */
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
   200
    public function testDeleteHandle() {
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
   201
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
   202
        $handleClient = new HandleClient('file://'.$this->rsaTmpPath, $this->rsaPemPassword, $this->rsaAdminHandle, $this->handleHost, $this->handlePort, $this->httpClient);
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
   203
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
   204
        $pagination = $handleClient->paginateAll($this->testPrefix);
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
   205
        $totalPrev = $pagination->total();
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
   206
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
   207
        $handle = strtoupper(uniqid("$this->testPrefix/TEST_HANDLE_CLIENT_"));
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
   208
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
   209
        $handleClient->createHandleUrlRecord($handle, "http://www.example.com");
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
   210
        $handleClient->deleteHandle($handle);
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
   211
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
   212
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
   213
        $pagination = $handleClient->paginateAll($this->testPrefix);
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
   214
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
   215
        $this->assertEquals($totalPrev, $pagination->total(), "Must have one more handle");
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
   216
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
   217
        $this->assertNotContains($handle, $pagination);
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
   218
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
   219
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
   220
    }
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
   221
338bcc78d431 add HandleClient implementation + configuration + tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
   222
}