Skip to content

Commit 8295c66

Browse files
committed
Add test to blacklist urls by keywords
1 parent f94864f commit 8295c66

File tree

2 files changed

+72
-0
lines changed

2 files changed

+72
-0
lines changed

tests/UpdateUrlTest.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,40 @@ public function an_url_can_be_updated()
2929

3030
$this->assertEquals($response['url'], $url['url']);
3131
}
32+
33+
/** @test */
34+
public function an_extension_could_be_blacklisted_on_update()
35+
{
36+
\Config::set('shorturl.blacklist', '.test');
37+
38+
$url = array_merge($this->createUrl(), ['url' => 'https://laravel.test']);
39+
40+
$response = $this->putJson(route('shorturl.url.update', ['id' => $url['id']]), $url)->json();
41+
42+
$this->assertArrayHasKey('url', $response['errors']);
43+
}
44+
45+
/** @test */
46+
public function a_keyword_could_be_blacklisted_on_update()
47+
{
48+
\Config::set('shorturl.blacklist', 'test');
49+
50+
$url = array_merge($this->createUrl(), ['url' => 'https://test.com']);
51+
52+
$response = $this->putJson(route('shorturl.url.update', ['id' => $url['id']]), $url)->json();
53+
54+
$this->assertArrayHasKey('url', $response['errors']);
55+
}
56+
57+
/** @test */
58+
public function an_url_could_be_blacklisted_on_update()
59+
{
60+
\Config::set('shorturl.blacklist', '//test.com');
61+
62+
$url = array_merge($this->createUrl(), ['url' => 'https://test.com']);
63+
64+
$response = $this->putJson(route('shorturl.url.update', ['id' => $url['id']]), $url)->json();
65+
66+
$this->assertArrayHasKey('url', $response['errors']);
67+
}
3268
}

tests/UrlTest.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,4 +106,40 @@ public function title_and_description_are_fetched_on_creation()
106106
$this->assertEquals($url['title'], 'a test title');
107107
$this->assertEquals($url['description'], 'a test description');
108108
}
109+
110+
/** @test */
111+
public function an_extension_could_be_blacklisted()
112+
{
113+
\Config::set('shorturl.blacklist', '.test');
114+
115+
$url = ['url' => 'https://laravel.test'];
116+
117+
$response = $this->createUrl($url);
118+
119+
$this->assertArrayHasKey('url', $response['errors']);
120+
}
121+
122+
/** @test */
123+
public function a_keyword_could_be_blacklisted()
124+
{
125+
\Config::set('shorturl.blacklist', 'test');
126+
127+
$url = ['url' => 'https://test.com'];
128+
129+
$response = $this->createUrl($url);
130+
131+
$this->assertArrayHasKey('url', $response['errors']);
132+
}
133+
134+
/** @test */
135+
public function an_url_could_be_blacklisted()
136+
{
137+
\Config::set('shorturl.blacklist', '//test.com');
138+
139+
$url = ['url' => 'https://test.com'];
140+
141+
$response = $this->createUrl($url);
142+
143+
$this->assertArrayHasKey('url', $response['errors']);
144+
}
109145
}

0 commit comments

Comments
 (0)