-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
226 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,3 +10,4 @@ phpunit.xml | |
Thumbs.db | ||
.php_cs.cache | ||
.php-cs-fixer.cache | ||
phpunit.log.xml |
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,27 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit bootstrap="vendor/autoload.php" | ||
backupGlobals="false" | ||
backupStaticAttributes="false" | ||
colors="true" | ||
verbose="true" | ||
convertErrorsToExceptions="true" | ||
convertNoticesToExceptions="true" | ||
convertWarningsToExceptions="true" | ||
processIsolation="true" | ||
stopOnFailure="false"> | ||
<testsuites> | ||
<testsuite name="Feature"> | ||
<directory suffix="Test.php">./tests/Feature</directory> | ||
</testsuite> | ||
</testsuites> | ||
<filter> | ||
<whitelist> | ||
<directory suffix=".php">src/</directory> | ||
</whitelist> | ||
</filter> | ||
<php> | ||
<server name="APP_ENV" value="testing"/> | ||
<server name="APP_DEBUG" value="false"/> | ||
<server name="APP_KEY" value="01234567890123456789012345678932"/> | ||
</php> | ||
</phpunit> |
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,122 @@ | ||
<?php | ||
|
||
namespace Novius\LaravelNovaMenu\Tests\Feature; | ||
|
||
use Novius\LaravelNovaMenu\Models\Menu; | ||
use Novius\LaravelNovaMenu\Models\MenuItem; | ||
use Novius\LaravelNovaMenu\Tests\TestCase; | ||
|
||
class ItemObserverTest extends TestCase | ||
{ | ||
protected Menu $menu; | ||
|
||
public function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
$this->menu = $this->createMenu(); | ||
} | ||
|
||
/** @test */ | ||
public function createExternalLinkTest() | ||
{ | ||
request()->merge([ | ||
'link_type' => MenuItem::TYPE_EXTERNAL_LINK, | ||
]); | ||
$linkValue = 'https://www.novius.fr'; | ||
|
||
$link = new MenuItem(); | ||
$link->name = 'Test external'; | ||
$link->menu_id = $this->menu->id; | ||
$link->external_link = $linkValue; | ||
$link->internal_link = 'should_be_null_after_saved'; | ||
$link->html = 'should_be_null_after_saved'; | ||
$link->is_empty_link = 1; | ||
$link->save(); | ||
|
||
$this->assertNull($link->internal_link); | ||
$this->assertNull($link->html); | ||
$this->assertEquals(0, $link->is_empty_link); | ||
$this->assertEquals($link->external_link, $linkValue); | ||
} | ||
|
||
/** @test */ | ||
public function createInternalLinkTest() | ||
{ | ||
request()->merge([ | ||
'link_type' => MenuItem::TYPE_INTERNAL_LINK, | ||
]); | ||
$linkValue = 'linkable_route:contact'; | ||
|
||
$link = new MenuItem(); | ||
$link->name = 'Test internal'; | ||
$link->menu_id = $this->menu->id; | ||
$link->external_link = 'should_be_null_after_saved'; | ||
$link->is_empty_link = 1; | ||
$link->html = 'should_be_null_after_saved'; | ||
$link->internal_link = $linkValue; | ||
$link->save(); | ||
|
||
$this->assertNull($link->external_link); | ||
$this->assertNull($link->html); | ||
$this->assertEquals(0, $link->is_empty_link); | ||
$this->assertEquals($link->internal_link, $linkValue); | ||
} | ||
|
||
/** @test */ | ||
public function createEmptyLinkTest() | ||
{ | ||
request()->merge([ | ||
'link_type' => MenuItem::TYPE_EMPTY, | ||
]); | ||
|
||
$link = new MenuItem(); | ||
$link->name = 'Test empty link'; | ||
$link->menu_id = $this->menu->id; | ||
$link->is_empty_link = 1; | ||
$link->external_link = 'should_be_null_after_saved'; | ||
$link->html = 'should_be_null_after_saved'; | ||
$link->internal_link = 'should_be_null_after_saved'; | ||
$link->save(); | ||
|
||
$this->assertNull($link->external_link); | ||
$this->assertNull($link->internal_link); | ||
$this->assertNull($link->html); | ||
$this->assertEquals(1, $link->is_empty_link); | ||
} | ||
|
||
/** @test */ | ||
public function createHtmlLinkTest() | ||
{ | ||
request()->merge([ | ||
'link_type' => MenuItem::TYPE_HTML, | ||
]); | ||
|
||
$html = '<div>test</div>'; | ||
|
||
$link = new MenuItem(); | ||
$link->name = 'Test html link'; | ||
$link->menu_id = $this->menu->id; | ||
$link->html = $html; | ||
$link->is_empty_link = 1; | ||
$link->external_link = 'should_be_null_after_saved'; | ||
$link->internal_link = 'should_be_null_after_saved'; | ||
$link->save(); | ||
|
||
$this->assertNull($link->external_link); | ||
$this->assertNull($link->internal_link); | ||
$this->assertEquals(0, $link->is_empty_link); | ||
$this->assertEquals($link->html, $html); | ||
} | ||
|
||
protected function createMenu(): Menu | ||
{ | ||
$menu = new Menu(); | ||
$menu->name = 'Test menu'; | ||
if (!$menu->save()) { | ||
throw new \Exception('Unable to save menu.'); | ||
} | ||
|
||
return $menu; | ||
} | ||
} |
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,54 @@ | ||
<?php | ||
|
||
namespace Novius\LaravelNovaMenu\Tests; | ||
|
||
use Illuminate\Support\Facades\Artisan; | ||
use Novius\LaravelNovaMenu\LaravelNovaMenuServiceProvider; | ||
use Orchestra\Testbench\TestCase as Orchestra; | ||
|
||
abstract class TestCase extends Orchestra | ||
{ | ||
public function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
Artisan::call('migrate'); | ||
} | ||
|
||
/** | ||
* @param \Illuminate\Foundation\Application $app | ||
* | ||
* @return array | ||
*/ | ||
protected function getPackageProviders($app) | ||
{ | ||
return [ | ||
LaravelNovaMenuServiceProvider::class, | ||
]; | ||
} | ||
|
||
/** | ||
* @param \Illuminate\Foundation\Application $app | ||
*/ | ||
protected function getEnvironmentSetUp($app) | ||
{ | ||
$app['config']->set('database.default', 'sqlite'); | ||
$app['config']->set('database.connections.sqlite', [ | ||
'driver' => 'sqlite', | ||
'database' => ':memory:', | ||
'prefix' => '', | ||
]); | ||
|
||
$app['config']->set('sluggable', [ | ||
'onUpdate' => false, | ||
'separator' => '-', | ||
'method' => null, | ||
'maxLength' => null, | ||
'maxLengthKeepWords' => true, | ||
'slugEngineOptions' => [], | ||
'reserved' => null, | ||
'unique' => true, | ||
'includeTrashed' => false, | ||
]); | ||
} | ||
} |