faker->word(); $validator = Validator::make( [$attribute => $this->faker->url()], [$attribute => new ResourceLinkFormatRule()], ); static::assertTrue($validator->passes()); } /** * The Resource Link Format Rule shall pass for sites with no expected pattern. * * @return void */ public function testPassesForNoPattern(): void { $attribute = $this->faker->word(); $validator = Validator::make( [$attribute => $this->faker->url()], [$attribute => new ResourceLinkFormatRule(ResourceSite::OFFICIAL_SITE)], ); static::assertTrue($validator->passes()); } /** * The Resource Link Format Rule shall pass for anime resources. * * @return void */ public function testPassesForAnimeResource(): void { /** @var ResourceSite $site */ $site = Arr::random([ ResourceSite::TWITTER, ResourceSite::ANIDB, ResourceSite::ANILIST, ResourceSite::ANIME_PLANET, ResourceSite::ANN, ResourceSite::KITSU, ResourceSite::MAL, ResourceSite::YOUTUBE, ]); $url = $site->formatResourceLink(Anime::class, $this->faker->randomDigitNotNull(), $this->faker->word()); $attribute = $this->faker->word(); $validator = Validator::make( [$attribute => $url], [$attribute => new ResourceLinkFormatRule($site)], ); static::assertTrue($validator->passes()); } /** * The Resource Link Format Rule shall pass for artist resources. * * @return void */ public function testPassesForArtistResource(): void { /** @var ResourceSite $site */ $site = Arr::random([ ResourceSite::TWITTER, ResourceSite::ANIDB, ResourceSite::ANILIST, ResourceSite::ANIME_PLANET, ResourceSite::ANN, ResourceSite::MAL, ResourceSite::SPOTIFY, ResourceSite::YOUTUBE ]); $url = $site->formatResourceLink(Artist::class, $this->faker->randomDigitNotNull(), $this->faker->word()); $attribute = $this->faker->word(); $validator = Validator::make( [$attribute => $url], [$attribute => new ResourceLinkFormatRule($site)], ); static::assertTrue($validator->passes()); } /** * The Resource Link Format Rule shall pass for song resources. * * @return void */ public function testPassesForSongResource(): void { /** @var ResourceSite $site */ $site = Arr::random([ ResourceSite::SPOTIFY, ResourceSite::YOUTUBE_MUSIC, ResourceSite::YOUTUBE, ResourceSite::APPLE_MUSIC, ResourceSite::AMAZON_MUSIC, ]); $url = $site->formatResourceLink(Song::class, $this->faker->randomDigitNotNull(), $this->faker->word()); $attribute = $this->faker->word(); $validator = Validator::make( [$attribute => $url], [$attribute => new ResourceLinkFormatRule($site)], ); static::assertTrue($validator->passes()); } /** * The Resource Link Format Rule shall pass for studio resources. * * @return void */ public function testPassesForStudioResource(): void { /** @var ResourceSite $site */ $site = Arr::random([ ResourceSite::TWITTER, ResourceSite::ANIDB, ResourceSite::ANILIST, ResourceSite::ANIME_PLANET, ResourceSite::ANN, ResourceSite::MAL, ]); $url = $site->formatResourceLink(Studio::class, $this->faker->randomDigitNotNull(), $this->faker->word()); $attribute = $this->faker->word(); $validator = Validator::make( [$attribute => $url], [$attribute => new ResourceLinkFormatRule($site)], ); static::assertTrue($validator->passes()); } /** * The Resource Link Format Rule shall fail for trailing slashes in URLs with defined patterns. * * @return void */ public function testFailsForTrailingSlash(): void { // Resource sites that can be attached for all models. $site = Arr::random([ ResourceSite::ANIDB, ]); $url = $site->formatResourceLink(Anime::class, $this->faker->randomDigitNotNull(), $this->faker->word()); $url = Str::of($url) ->append('/') ->__toString(); $attribute = $this->faker->word(); $validator = Validator::make( [$attribute => $url], [$attribute => new ResourceLinkFormatRule($site)], ); static::assertFalse($validator->passes()); } }