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
|
<?php
namespace Illuminate\Tests\Foundation\Testing\Concerns;
use Orchestra\Testbench\TestCase;
class MakesHttpRequestsTest extends TestCase
{
public function testFromSetsHeaderAndSession()
{
$this->from('previous/url');
$this->assertSame('previous/url', $this->defaultHeaders['referer']);
$this->assertSame('previous/url', $this->app['session']->previousUrl());
}
public function testWithoutAndWithMiddleware()
{
$this->assertFalse($this->app->has('middleware.disable'));
$this->withoutMiddleware();
$this->assertTrue($this->app->has('middleware.disable'));
$this->assertTrue($this->app->make('middleware.disable'));
$this->withMiddleware();
$this->assertFalse($this->app->has('middleware.disable'));
}
public function testWithoutAndWithMiddlewareWithParameter()
{
$next = function ($request) {
return $request;
};
$this->assertFalse($this->app->has(MyMiddleware::class));
$this->assertSame(
'fooWithMiddleware',
$this->app->make(MyMiddleware::class)->handle('foo', $next)
);
$this->withoutMiddleware(MyMiddleware::class);
$this->assertTrue($this->app->has(MyMiddleware::class));
$this->assertSame(
'foo',
$this->app->make(MyMiddleware::class)->handle('foo', $next)
);
$this->withMiddleware(MyMiddleware::class);
$this->assertFalse($this->app->has(MyMiddleware::class));
$this->assertSame(
'fooWithMiddleware',
$this->app->make(MyMiddleware::class)->handle('foo', $next)
);
}
public function testWithCookieSetCookie()
{
$this->withCookie('foo', 'bar');
$this->assertCount(1, $this->defaultCookies);
$this->assertSame('bar', $this->defaultCookies['foo']);
}
public function testWithCookiesSetsCookiesAndOverwritesPreviousValues()
{
$this->withCookie('foo', 'bar');
$this->withCookies([
'foo' => 'baz',
'new-cookie' => 'new-value',
]);
$this->assertCount(2, $this->defaultCookies);
$this->assertSame('baz', $this->defaultCookies['foo']);
$this->assertSame('new-value', $this->defaultCookies['new-cookie']);
}
public function testWithUnencryptedCookieSetCookie()
{
$this->withUnencryptedCookie('foo', 'bar');
$this->assertCount(1, $this->unencryptedCookies);
$this->assertSame('bar', $this->unencryptedCookies['foo']);
}
public function testWithUnencryptedCookiesSetsCookiesAndOverwritesPreviousValues()
{
$this->withUnencryptedCookie('foo', 'bar');
$this->withUnencryptedCookies([
'foo' => 'baz',
'new-cookie' => 'new-value',
]);
$this->assertCount(2, $this->unencryptedCookies);
$this->assertSame('baz', $this->unencryptedCookies['foo']);
$this->assertSame('new-value', $this->unencryptedCookies['new-cookie']);
}
}
class MyMiddleware
{
public function handle($request, $next)
{
return $next($request.'WithMiddleware');
}
}
|