Skip to content

Commit

Permalink
browser have setters
Browse files Browse the repository at this point in the history
  • Loading branch information
gsouf committed May 1, 2017
1 parent 08f59b8 commit a016dc3
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/Core/Browser/Browser.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
namespace Serps\Core\Browser;

use Psr\Http\Message\RequestInterface;
use Serps\Core\Cookie\Cookie;
use Serps\Core\Cookie\CookieJarInterface;
use Serps\Core\Http\HttpClientInterface;
use Serps\Core\Http\ProxyInterface;
Expand Down Expand Up @@ -92,4 +93,36 @@ public function getHttpClient()
{
return $this->httpClient;
}

/**
* @param null|string $acceptLanguage
*/
public function setAcceptLanguage($acceptLanguage)
{
$this->acceptLanguage = $acceptLanguage;
}

/**
* @param null|string $userAgent
*/
public function setUserAgent($userAgent)
{
$this->userAgent = $userAgent;
}

/**
* @param null|CookieJarInterface $cookieJar
*/
public function setCookieJar(CookieJarInterface $cookieJar = null)
{
$this->cookieJar = $cookieJar;
}

/**
* @param null|ProxyInterface $proxy
*/
public function setProxy(ProxyInterface $proxy = null)
{
$this->proxy = $proxy;
}
}
36 changes: 36 additions & 0 deletions test/suites/TDD/Core/Browser/BrowserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

namespace Serps\Test\Core\Browser;

use Serps\Core\Cookie\ArrayCookieJar;
use Serps\Core\Http\Proxy;
use Serps\Core\Http\StackingHttpClient;
use Serps\Core\Browser\Browser;
use Serps\Core\Psr7\RequestBuilder;
Expand Down Expand Up @@ -90,4 +92,38 @@ public function testSendRequest()
$this->assertEquals('POST', strtoupper($httpClient->getStack()[0]->request->getMethod()));
$this->assertEquals('a=b', (string) $httpClient->getStack()[0]->request->getBody());
}

public function testAccessors()
{

$userAgent= 'bar';
$language = 'foo';
$cookieJar = new ArrayCookieJar();
$proxy = Proxy::createFromString('localhost:80');

$browser = new Browser(new StackingHttpClient(), $userAgent, $language, $cookieJar, $proxy);

$this->assertEquals('foo', $browser->getAcceptLanguage());
$this->assertEquals('bar', $browser->getUserAgent());
$this->assertSame($cookieJar, $browser->getCookieJar());
$this->assertSame($proxy, $browser->getProxy());


$cookieJar2 = new ArrayCookieJar();
$proxy2 = Proxy::createFromString('localhost:90');
$browser->setAcceptLanguage('baz');
$browser->setUserAgent('qux');
$browser->setCookieJar($cookieJar2);
$browser->setProxy($proxy2);

$this->assertEquals('baz', $browser->getAcceptLanguage());
$this->assertEquals('qux', $browser->getUserAgent());
$this->assertSame($cookieJar2, $browser->getCookieJar());
$this->assertSame($proxy2, $browser->getProxy());

$browser->setCookieJar(null);
$browser->setProxy(null);
$this->assertNull($browser->getCookieJar());
$this->assertNull($browser->getProxy());
}
}

0 comments on commit a016dc3

Please sign in to comment.