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
Alexandr Fanamurov
committed
Mar 16, 2018
1 parent
8b9203b
commit 8ed04d9
Showing
17 changed files
with
224 additions
and
13 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,45 @@ | ||
<?php | ||
|
||
namespace Larrock\Core\Tests\DatabaseTest; | ||
|
||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Support\Facades\DB; | ||
|
||
class CreateCategoryDatabase | ||
{ | ||
/** Поднимаем тестовую таблицу конфига */ | ||
public function setUpCategoryDatabase() | ||
{ | ||
DB::connection()->getSchemaBuilder()->create('category', function (Blueprint $table) { | ||
$table->increments('id'); | ||
$table->char('title'); | ||
$table->text('short')->nullable(); | ||
$table->text('description')->nullable(); | ||
$table->char('description_link')->nullable(); | ||
$table->char('component')->nullable(); | ||
$table->integer('parent')->nullable(); | ||
$table->integer('level')->default(1); | ||
$table->char('url', 191)->unique(); | ||
$table->integer('sitemap')->default(1); | ||
$table->integer('rss')->default(0); | ||
$table->integer('position')->default(1); | ||
$table->integer('active')->default(1); | ||
$table->integer('user_id')->unsigned()->nullable(); | ||
//$table->integer('user_id')->unsigned()->nullable()->index('category_user_id_foreign'); | ||
$table->integer('attached')->default(0); | ||
$table->timestamps(); | ||
|
||
$table->index(['url', 'active']); | ||
}); | ||
|
||
DB::connection()->table('category')->insert([ | ||
'title' => 'test', | ||
'short' => 'test', | ||
'description' => 'test', | ||
'component' => 'test', | ||
'parent' => NULL, | ||
'level' => 1, | ||
'url' => 'test', | ||
]); | ||
} | ||
} |
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,39 @@ | ||
<?php | ||
|
||
namespace Larrock\Core\Tests\Helpers; | ||
|
||
use Larrock\Core\Helpers\AdminMenuBuilder; | ||
use Larrock\Core\LarrockCoreServiceProvider; | ||
use Orchestra\Testbench\TestCase; | ||
|
||
class AdminMenuBuilderTest extends TestCase | ||
{ | ||
/** @var AdminMenuBuilder */ | ||
protected $AdminMenuBuilder; | ||
|
||
protected function setUp() | ||
{ | ||
parent::setUp(); | ||
|
||
$this->AdminMenuBuilder = new AdminMenuBuilder(); | ||
} | ||
|
||
public function tearDown() | ||
{ | ||
parent::tearDown(); | ||
|
||
unset($this->AdminMenuBuilder); | ||
} | ||
|
||
protected function getPackageProviders($app) | ||
{ | ||
return [ | ||
LarrockCoreServiceProvider::class | ||
]; | ||
} | ||
|
||
public function testTopMenu() | ||
{ | ||
$this->assertEquals(['menu' => [], 'menu_other' => []], $this->AdminMenuBuilder->topMenu()); | ||
} | ||
} |
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
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,95 @@ | ||
<?php | ||
|
||
namespace Larrock\Core\Tests\Helpers; | ||
|
||
use Larrock\Core\Helpers\Tree; | ||
use Larrock\Core\Tests\DatabaseTest\CreateCategoryDatabase; | ||
use Orchestra\Testbench\TestCase; | ||
use Illuminate\Support\Facades\DB; | ||
|
||
class TreeTest extends TestCase | ||
{ | ||
/** @var Tree */ | ||
protected $tree; | ||
|
||
protected function setUp() | ||
{ | ||
parent::setUp(); | ||
|
||
$this->tree = new Tree(); | ||
} | ||
|
||
public function tearDown() | ||
{ | ||
parent::tearDown(); | ||
|
||
unset($this->tree); | ||
} | ||
|
||
protected function getEnvironmentSetUp($app) | ||
{ | ||
$app['config']->set('database.default', 'sqlite'); | ||
$app['config']->set('database.connections.sqlite', [ | ||
'driver' => 'sqlite', | ||
'database' => ':memory:', | ||
'prefix' => '', | ||
]); | ||
} | ||
|
||
public function testBuildTree() | ||
{ | ||
$seed = new CreateCategoryDatabase(); | ||
$seed->setUpCategoryDatabase(); | ||
|
||
DB::connection()->table('category')->insert([ | ||
'title' => 'test2', | ||
'short' => 'test2', | ||
'description' => 'test2', | ||
'component' => 'test', | ||
'parent' => 1, | ||
'level' => 2, | ||
'url' => 'test2', | ||
]); | ||
|
||
$data = DB::table('category')->get(); | ||
$test = $this->tree->buildTree($data, 'parent'); | ||
$this->assertCount(1, $test[0]->children); | ||
} | ||
|
||
public function testListActiveCategories() | ||
{ | ||
$seed = new CreateCategoryDatabase(); | ||
$seed->setUpCategoryDatabase(); | ||
|
||
DB::connection()->table('category')->insert([ | ||
'title' => 'test2', | ||
'short' => 'test2', | ||
'description' => 'test2', | ||
'component' => 'test', | ||
'parent' => 1, | ||
'level' => 2, | ||
'url' => 'test2', | ||
'active' => 1 | ||
]); | ||
|
||
DB::connection()->table('category')->insert([ | ||
'title' => 'test3', | ||
'short' => 'test3', | ||
'description' => 'test3', | ||
'component' => 'test', | ||
'parent' => 2, | ||
'level' => 3, | ||
'url' => 'test3', | ||
'active' => 0 | ||
]); | ||
|
||
$data = DB::table('category')->where('id', '=', 1)->get(); | ||
|
||
$data[0]->get_childActive = collect(); | ||
$parent = DB::table('category')->where('id', '=', 2)->first(); | ||
$parent->get_childActive = null; | ||
$data[0]->get_childActive->push($parent); | ||
|
||
$this->assertEquals([0 => '1', 1 => '2'], $this->tree->listActiveCategories($data)); | ||
} | ||
} |