Skip to content

Commit

Permalink
Merge pull request #30 from madewithlove/add-user-agent
Browse files Browse the repository at this point in the history
Add HTTP_USER_AGENT
  • Loading branch information
jdrieghe authored Oct 15, 2021
2 parents 7ab6646 + 69cec55 commit af69117
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ Htaccess Tester supports passing a predefined set of server variables to be eval
We currently support the following variables.
```
HTTP_REFERER
HTTP_USER_AGENT
SERVER_NAME
```

Expand Down
2 changes: 2 additions & 0 deletions src/ServerVariable.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
final class ServerVariable
{
public const HTTP_REFERER = 'HTTP_REFERER';
public const HTTP_USER_AGENT = 'HTTP_USER_AGENT';
public const SERVER_NAME = 'SERVER_NAME';

public const ALL = [
self::HTTP_REFERER,
self::HTTP_USER_AGENT,
self::SERVER_NAME,
];
}
30 changes: 30 additions & 0 deletions tests/HtaccessClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,36 @@ public function it allows for passing a server name(): void
$this->assertTrue($response->getLines()[0]->isSupported());
}

/** @test */
public function it allows for passing an http user agent(): void
{
$client = new HtaccessClient(
new Client(),
new ServerRequestFactory()
);

$response = $client->test(
'http://localhost',
'RewriteCond %{HTTP_USER_AGENT} (iPhone|Android)
RewriteRule .* /example-page [L]',
ServerVariables::default()->with(
ServerVariable::HTTP_USER_AGENT,
'Android'
)
);

$this->assertEquals(
'http://localhost/example-page',
$response->getOutputUrl()
);
$this->assertEquals('RewriteCond %{HTTP_USER_AGENT} (iPhone|Android)', $response->getLines()[0]->getLine());
$this->assertStringContainsString('condition was met', $response->getLines()[0]->getMessage());
$this->assertTrue($response->getLines()[0]->isMet());
$this->assertTrue($response->getLines()[0]->isValid());
$this->assertTrue($response->getLines()[0]->wasReached());
$this->assertTrue($response->getLines()[0]->isSupported());
}

/** @test */
public function it throws an exception when we pass an invalid url(): void
{
Expand Down

0 comments on commit af69117

Please sign in to comment.