|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Tests\Unit; |
| 4 | + |
| 5 | +use Tests\TestCase; |
| 6 | +use Oneofftech\Identities\Facades\Identity; |
| 7 | +use Illuminate\Foundation\Testing\DatabaseMigrations; |
| 8 | +use InvalidArgumentException; |
| 9 | +use Illuminate\Support\Facades\View; |
| 10 | +use Illuminate\View\Component; |
| 11 | +use Oneofftech\Identities\View\Components\IdentityLink; |
| 12 | + |
| 13 | +class IdentityLinkTest extends TestCase |
| 14 | +{ |
| 15 | + use DatabaseMigrations; |
| 16 | + |
| 17 | + public function setUp(): void |
| 18 | + { |
| 19 | + parent::setUp(); |
| 20 | + |
| 21 | + Identity::routes(); |
| 22 | + } |
| 23 | + |
| 24 | + public function test_unsupported_action_throws() |
| 25 | + { |
| 26 | + $this->expectException(InvalidArgumentException::class); |
| 27 | + $this->expectExceptionMessage("Specified action [dance] is not supported."); |
| 28 | + |
| 29 | + new IdentityLink('gitlab', 'dance'); |
| 30 | + } |
| 31 | + |
| 32 | + public function test_component_uses_default_label() |
| 33 | + { |
| 34 | + $component = new IdentityLink('gitlab', 'register'); |
| 35 | + |
| 36 | + $this->assertEquals('gitlab', $component->provider); |
| 37 | + $this->assertEquals('register', $component->action); |
| 38 | + $this->assertEquals('Register via :Provider', $component->label); |
| 39 | + $this->assertEquals([], $component->parameters); |
| 40 | + } |
| 41 | + |
| 42 | + public function test_component_uses_custom_label() |
| 43 | + { |
| 44 | + $component = new IdentityLink('gitlab', 'register', 'My label'); |
| 45 | + |
| 46 | + $this->assertEquals('gitlab', $component->provider); |
| 47 | + $this->assertEquals('register', $component->action); |
| 48 | + $this->assertEquals('My label', $component->label); |
| 49 | + $this->assertEquals([], $component->parameters); |
| 50 | + } |
| 51 | + |
| 52 | + public function test_login_link_rendered() |
| 53 | + { |
| 54 | + $component = new IdentityLink('gitlab'); |
| 55 | + |
| 56 | + $view = $this->render($component); |
| 57 | + |
| 58 | + $this->assertStringContainsString('http://localhost/login-via/gitlab', $view); |
| 59 | + $this->assertStringContainsString('Log in via Gitlab', $view); |
| 60 | + } |
| 61 | + |
| 62 | + public function test_register_link_rendered() |
| 63 | + { |
| 64 | + $component = new IdentityLink('gitlab', 'register', 'My label'); |
| 65 | + |
| 66 | + $view = $this->render($component); |
| 67 | + |
| 68 | + $this->assertStringContainsString('http://localhost/register-via/gitlab', $view); |
| 69 | + $this->assertStringContainsString('My label', $view); |
| 70 | + } |
| 71 | + |
| 72 | + private function render(Component $component) |
| 73 | + { |
| 74 | + return view($component->resolveView(), $component->data())->render(); |
| 75 | + } |
| 76 | +} |
0 commit comments