Subversion Repository Public Repository

Nextrek

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<?php

require_once __DIR__ . '/AbstractTestHttpClient.php';

use Mockery as m;
use Facebook\HttpClients\FacebookStreamHttpClient;

class FacebookStreamHttpClientTest extends AbstractTestHttpClient
{

  protected $streamMock;
  protected $streamClient;

  public function setUp()
  {
    $this->streamMock = m::mock('Facebook\HttpClients\FacebookStream');
    $this->streamClient = new FacebookStreamHttpClient($this->streamMock);
  }

  public function tearDown()
  {
    m::close();
    (new FacebookStreamHttpClient()); // Resets the static dependency injection
  }

  public function testCanCompileHeader()
  {
    $this->streamClient->addRequestHeader('X-foo', 'bar');
    $this->streamClient->addRequestHeader('X-bar', 'faz');
    $header = $this->streamClient->compileHeader();
    $this->assertEquals("X-foo: bar\r\nX-bar: faz", $header);
  }

  public function testCanFormatHeadersToArray()
  {
    $raw_header_array = explode("\n", trim($this->fakeRawHeader));
    $header_array = FacebookStreamHttpClient::formatHeadersToArray($raw_header_array);
    $this->assertEquals($this->fakeHeadersAsArray, $header_array);
  }

  public function testCanGetHttpStatusCodeFromResponseHeader()
  {
    $http_code = FacebookStreamHttpClient::getStatusCodeFromHeader('HTTP/1.1 123 Foo Response');
    $this->assertEquals('123', $http_code);
  }

  public function testCanSendNormalRequest()
  {
    $this->streamMock
      ->shouldReceive('streamContextCreate')
      ->once()
      ->with(m::on(function($arg) {
            if ( ! isset($arg['http']) || ! isset($arg['ssl'])) {
              return false;
            }

            if ($arg['http'] !== [
                'method' => 'GET',
                'timeout' => 60,
                'ignore_errors' => true,
                'header' => 'X-foo: bar',
              ]) {
              return false;
            }

            $caInfo = array_diff_assoc($arg['ssl'], [
                'verify_peer' => true,
                'verify_peer_name' => true,
                'allow_self_signed' => true,
              ]);

            if (count($caInfo) !== 1) {
              return false;
            }

            if (1 !== preg_match('/.+\/certs\/DigiCertHighAssuranceEVRootCA\.pem$/', $caInfo['cafile'])) {
              return false;
            }

            return true;
          }))
      ->andReturn(null);
    $this->streamMock
      ->shouldReceive('getResponseHeaders')
      ->once()
      ->andReturn(explode("\n", trim($this->fakeRawHeader)));
    $this->streamMock
      ->shouldReceive('fileGetContents')
      ->once()
      ->with('http://foo.com/')
      ->andReturn($this->fakeRawBody);

    $this->streamClient->addRequestHeader('X-foo', 'bar');
    $responseBody = $this->streamClient->send('http://foo.com/');

    $this->assertEquals($responseBody, $this->fakeRawBody);
    $this->assertEquals($this->streamClient->getResponseHeaders(), $this->fakeHeadersAsArray);
    $this->assertEquals(200, $this->streamClient->getResponseHttpStatusCode());
  }

  /**
   * @expectedException \Facebook\FacebookSDKException
   */
  public function testThrowsExceptionOnClientError()
  {
    $this->streamMock
      ->shouldReceive('streamContextCreate')
      ->once()
      ->andReturn(null);
    $this->streamMock
      ->shouldReceive('getResponseHeaders')
      ->once()
      ->andReturn(null);
    $this->streamMock
      ->shouldReceive('fileGetContents')
      ->once()
      ->with('http://foo.com/')
      ->andReturn(false);

    $this->streamClient->send('http://foo.com/');
  }

}

Commits for Nextrek/Android/SmartCharging/endPoints/nightly/fb_SDK/tests/HttpClients/FacebookStreamHttpClientTest.php

Diff revisions: vs.
Revision Author Commited Message
461 FSallustio picture FSallustio Mon 03 Aug, 2015 10:04:56 +0000

Aggiunto supporto login Facebook, logout utente e modifiche (solo lato repo) all’utente e al locale.