-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Check if the field is a url and check that
- Loading branch information
1 parent
93c224f
commit e346e52
Showing
13 changed files
with
87 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?php | ||
|
||
use ChrisRhymes\LinkChecker\Jobs\CheckModelForBrokenLinks; | ||
use ChrisRhymes\LinkChecker\Models\BrokenLink; | ||
use ChrisRhymes\LinkChecker\Test\Models\Post; | ||
use Illuminate\Support\Facades\Http; | ||
|
||
beforeEach(function () { | ||
Http::fake([ | ||
'https://this-is-broken.com' => Http::response(null, 404), | ||
]); | ||
|
||
$this->post = Post::factory() | ||
->create([ | ||
'content' => '<a href="https://this-is-broken.com">Broken link</a>', | ||
'url' => 'https://this-is-broken.com', | ||
]); | ||
}); | ||
|
||
it('checks a url not in html', function () { | ||
CheckModelForBrokenLinks::dispatch($this->post, ['url']); | ||
|
||
$this->assertDatabaseHas('broken_links', [ | ||
'linkable_id' => $this->post->id, | ||
'linkable_type' => 'ChrisRhymes\LinkChecker\Test\Models\Post', | ||
'broken_link' => 'https://this-is-broken.com', | ||
'link_text' => 'https://this-is-broken.com', | ||
'exception_message' => '404 Status Code', | ||
]); | ||
}); | ||
|
||
it('checks for broken links in both specified fields', function () { | ||
CheckModelForBrokenLinks::dispatch($this->post, ['content', 'url']); | ||
|
||
expect(BrokenLink::count()) | ||
->toEqual(2); | ||
|
||
$this->assertDatabaseHas('broken_links', [ | ||
'linkable_id' => $this->post->id, | ||
'linkable_type' => 'ChrisRhymes\LinkChecker\Test\Models\Post', | ||
'broken_link' => 'https://this-is-broken.com', | ||
'link_text' => 'https://this-is-broken.com', | ||
'exception_message' => '404 Status Code', | ||
]); | ||
|
||
$this->assertDatabaseHas('broken_links', [ | ||
'linkable_id' => $this->post->id, | ||
'linkable_type' => 'ChrisRhymes\LinkChecker\Test\Models\Post', | ||
'broken_link' => 'https://this-is-broken.com', | ||
'link_text' => 'Broken link', | ||
'exception_message' => '404 Status Code', | ||
]); | ||
}); | ||
|
||
it('ignores invalid url value', function () { | ||
$postWithInvalidUrl = Post::factory()->create([ | ||
'url' => 'not a link', | ||
]); | ||
|
||
CheckModelForBrokenLinks::dispatch($postWithInvalidUrl, ['url']); | ||
|
||
Http::assertNothingSent(); | ||
|
||
expect(BrokenLink::count()) | ||
->toEqual(0); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters