mirror of
https://github.com/Bubka/2FAuth.git
synced 2025-05-31 07:16:15 +02:00
Fix & Complete tests
This commit is contained in:
parent
5aec206f99
commit
c25aaa3371
@ -38,8 +38,8 @@ class LogoService
|
|||||||
$logoFilename = $this->getLogo(strval($serviceName));
|
$logoFilename = $this->getLogo(strval($serviceName));
|
||||||
|
|
||||||
if ($logoFilename) {
|
if ($logoFilename) {
|
||||||
$newFilename = Str::random(40).'.svg';
|
$iconFilename = Str::random(40).'.svg';
|
||||||
return Storage::disk('icons')->put($newFilename, Storage::disk('logos')->get($logoFilename)) ? $newFilename : null;
|
return $this->copyToIcons($logoFilename, $iconFilename) ? $iconFilename : null;
|
||||||
}
|
}
|
||||||
else return null;
|
else return null;
|
||||||
}
|
}
|
||||||
@ -149,4 +149,17 @@ class LogoService
|
|||||||
{
|
{
|
||||||
return strtolower(str_replace(['+'], ['plus'], $domain));
|
return strtolower(str_replace(['+'], ['plus'], $domain));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copy a logo file to the icons disk with a new name
|
||||||
|
*
|
||||||
|
* @param string $logoFilename
|
||||||
|
* @param string $iconFilename
|
||||||
|
* @return bool Weither the copy succed or not
|
||||||
|
*/
|
||||||
|
protected function copyToIcons($logoFilename, $iconFilename) : bool
|
||||||
|
{
|
||||||
|
return Storage::disk('icons')->put($iconFilename, Storage::disk('logos')->get($logoFilename));
|
||||||
|
}
|
||||||
}
|
}
|
61
tests/Feature/Services/LogoServiceTest.php
Normal file
61
tests/Feature/Services/LogoServiceTest.php
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Feature\Services;
|
||||||
|
|
||||||
|
use App\Services\LogoService;
|
||||||
|
use Tests\FeatureTestCase;
|
||||||
|
use Tests\TestCase;
|
||||||
|
use Mockery\MockInterface;
|
||||||
|
use Illuminate\Foundation\Testing\WithoutMiddleware;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers \App\Services\LogoService
|
||||||
|
*/
|
||||||
|
class LogoServiceTest extends TestCase
|
||||||
|
{
|
||||||
|
use WithoutMiddleware;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
*/
|
||||||
|
public function setUp() : void
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
*/
|
||||||
|
public function test_getIcon_returns_iconFilename_when_logo_exists()
|
||||||
|
{
|
||||||
|
$logoServiceMock = $this->partialMock(LogoService::class, function (MockInterface $mock) {
|
||||||
|
$mock->shouldAllowMockingProtectedMethods();
|
||||||
|
$mock->shouldReceive('getLogo', 'copyToIcons')
|
||||||
|
->once()
|
||||||
|
->andReturn('service.svg', true);
|
||||||
|
});
|
||||||
|
|
||||||
|
$icon = $logoServiceMock->getIcon('service');
|
||||||
|
|
||||||
|
$this->assertNotNull($icon);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
*/
|
||||||
|
public function test_getIcon_returns_null_when_no_logo_exists()
|
||||||
|
{
|
||||||
|
$logoServiceMock = $this->partialMock(LogoService::class, function (MockInterface $mock) {
|
||||||
|
$mock->shouldReceive('getLogo')
|
||||||
|
->once()
|
||||||
|
->andReturn(null);
|
||||||
|
});
|
||||||
|
|
||||||
|
$icon = $logoServiceMock->getIcon('no_logo_should_exists_with_this_name');
|
||||||
|
|
||||||
|
$this->assertEquals(null, $icon);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -25,8 +25,8 @@ class CleanIconStorageTest extends TestCase
|
|||||||
$event = new TwoFAccountDeleted($twofaccount);
|
$event = new TwoFAccountDeleted($twofaccount);
|
||||||
$listener = new CleanIconStorage();
|
$listener = new CleanIconStorage();
|
||||||
|
|
||||||
Storage::shouldReceive('delete')
|
Storage::shouldReceive('disk->delete')
|
||||||
->with('public/icons/' . $event->twofaccount->icon)
|
->with($event->twofaccount->icon)
|
||||||
->andReturn(true);
|
->andReturn(true);
|
||||||
|
|
||||||
$this->assertNull($listener->handle($event));
|
$this->assertNull($listener->handle($event));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user