Skip to content

Commit

Permalink
update test, fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexandr Fanamurov committed Mar 16, 2018
1 parent 8b9203b commit 8ed04d9
Show file tree
Hide file tree
Showing 17 changed files with 224 additions and 13 deletions.
3 changes: 2 additions & 1 deletion src/AdminDashboardController.php
Expand Up @@ -9,7 +9,8 @@ class AdminDashboardController extends Controller
{
public function __construct()
{
$this->middleware(\LarrockPages::combineAdminMiddlewares());
$component = new Component;
$this->middleware($component->combineAdminMiddlewares());
}

public function index()
Expand Down
1 change: 1 addition & 0 deletions src/Component.php
Expand Up @@ -447,6 +447,7 @@ public function tabbable($data)
$this->addDataPlugins($data);
}

$this->tabs = collect();
foreach($this->rows as $row_value){
$this->tabs->put(key($row_value->tab), current($row_value->tab));
}
Expand Down
4 changes: 2 additions & 2 deletions src/Helpers/AdminMenuBuilder.php
Expand Up @@ -2,11 +2,11 @@

namespace Larrock\Core\Helpers;

use App\Http\Controllers\Controller;
use Illuminate\Routing\Controller;

class AdminMenuBuilder extends Controller
{
public function top_menu()
public function topMenu()
{
$menu = [];
$menu_other = [];
Expand Down
2 changes: 1 addition & 1 deletion src/Helpers/Tree.php
Expand Up @@ -38,7 +38,7 @@ public function buildTree($data, $row_level = 'parent')
* @param int $level
* @return array
*/
public function createTree(&$list, $parent, $level = 1){
protected function createTree(&$list, $parent, $level = 1){
$tree = array();
foreach ($parent as $l){
$l->level = $level;
Expand Down
2 changes: 1 addition & 1 deletion src/Middleware/AdminMenu.php
Expand Up @@ -20,7 +20,7 @@ public function handle($request, Closure $next)
{
$menu = new AdminMenuBuilder();
if(Route::current()){
View::share('top_menu', $menu->top_menu());
View::share('top_menu', $menu->topMenu());
}
return $next($request);
}
Expand Down
24 changes: 22 additions & 2 deletions tests/ComponentTest.php
Expand Up @@ -8,10 +8,15 @@
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\DB;
use Larrock\ComponentAdminSeo\LarrockComponentAdminSeoServiceProvider;
use Larrock\ComponentBlocks\BlocksComponent;
use Larrock\ComponentBlocks\Facades\LarrockBlocks;
use Larrock\ComponentBlocks\LarrockComponentBlocksServiceProvider;
use Larrock\ComponentBlocks\Models\Blocks;
use Larrock\Core\Component;
use Larrock\Core\Helpers\FormBuilder\FormCheckbox;
use Larrock\Core\Helpers\FormBuilder\FormInput;
use Larrock\Core\Models\Config;
use Larrock\Core\Tests\DatabaseTest\CreateBlocksDatabase;
use Larrock\Core\Tests\DatabaseTest\CreateLinkDatabase;
use Larrock\Core\Tests\DatabaseTest\CreateSeoDatabase;
use Proengsoft\JsValidation\JsValidationServiceProvider;
Expand Down Expand Up @@ -53,7 +58,8 @@ protected function getPackageProviders($app)
return [
JsValidationServiceProvider::class,
LarrockComponentAdminSeoServiceProvider::class,
BreadcrumbsServiceProvider::class
BreadcrumbsServiceProvider::class,
LarrockComponentBlocksServiceProvider::class
];
}

Expand All @@ -63,7 +69,8 @@ protected function getPackageAliases($app)
'JsValidator' => 'Proengsoft\JsValidation\Facades\JsValidatorFacade',
'LarrockAdminSeo' => 'Larrock\ComponentAdminSeo\Facades\LarrockSeo',
//'LarrockFeed' => 'Larrock\ComponentFeed\Facades\LarrockFeed',
'Breadcrumbs' => 'DaveJamesMiller\Breadcrumbs\Facades\Breadcrumbs'
'Breadcrumbs' => 'DaveJamesMiller\Breadcrumbs\Facades\Breadcrumbs',
'LarrockBlocks' => 'Larrock\ComponentBlocks\Facades\LarrockBlocks'
];
}

Expand Down Expand Up @@ -302,6 +309,19 @@ public function testAddAnonsToModule()
$this->assertArrayHasKey('anons', $this->component->plugins_backend);
}

/*public function testTabbable()
{
$seed = new CreateBlocksDatabase();
$seed->setUpBlocksDatabase();
$seed = new CreateSeoDatabase();
$seed->setUpSeoDatabase();
$data = Blocks::first();
$BlocksComponent = new BlocksComponent();
$BlocksComponent->tabbable($data);
}*/

public function testAddDataPlugins()
{
$seed = new CreateSeoDatabase();
Expand Down
45 changes: 45 additions & 0 deletions tests/DatabaseTest/CreateCategoryDatabase.php
@@ -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',
]);
}
}
39 changes: 39 additions & 0 deletions tests/Helpers/AdminMenuBuilderTest.php
@@ -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());
}
}
5 changes: 3 additions & 2 deletions tests/Helpers/FormBuilder/FBElementTest.php
Expand Up @@ -104,13 +104,14 @@ public function testSetConnect()
*/
public function testSetWhereConnect()
{
$this->FBElement->setWhereConnect('test_key', 'test_value');

$this->FBElement->setConnect(Config::class, 'test_relation', 'test_group');
$this->FBElement->setWhereConnect('test_key', 'test_value');
$this->assertEquals('test_key', $this->FBElement->connect->where_key);
$this->assertEquals('test_value', $this->FBElement->connect->where_value);
$this->assertInstanceOf('Larrock\Core\Helpers\FormBuilder\FBElement', $this->FBElement);

$this->FBElement = new FBElement('test_name', 'test_title');
$this->FBElement->setWhereConnect('test_key', 'test_value');
}

public function testSetAttached()
Expand Down
7 changes: 4 additions & 3 deletions tests/Helpers/FormBuilder/FormCategoryTest.php
Expand Up @@ -55,9 +55,9 @@ public function testSetMaxItems()
public function setAllowEmpty()
{
$this->FormCategory->setAllowEmpty();
$this->assertTrue($this->FormCategory->setAllowEmpty()->allow_empty);
$this->assertInstanceOf(FBElement::class, $this->FormCategory->setAllowEmpty());
$this->assertInstanceOf(FormCategory::class, $this->FormCategory->setAllowEmpty());
$this->assertTrue($this->FormCategory->allow_empty);
$this->assertInstanceOf(FBElement::class, $this->FormCategory);
$this->assertInstanceOf(FormCategory::class, $this->FormCategory);
}

/**
Expand All @@ -74,6 +74,7 @@ public function testRender()
$this->FormCategory->setConnect(Config::class, 'test_relation');
$data = new Config();
$data->test_relation = collect([]);
$this->FormCategory->setDefaultValue('test');

$this->assertNotEmpty($this->FormCategory->render($this->FormCategory, $data));
}
Expand Down
5 changes: 4 additions & 1 deletion tests/Helpers/FormBuilder/FormCheckboxTest.php
Expand Up @@ -2,6 +2,7 @@

namespace Larrock\Core\Tests\Helpers\FormBuilder;

use Larrock\ComponentBlocks\LarrockComponentBlocksServiceProvider;
use Larrock\Core\Helpers\FormBuilder\FormCheckbox;
use Larrock\Core\LarrockCoreServiceProvider;

Expand All @@ -27,12 +28,14 @@ public function tearDown()
protected function getPackageProviders($app)
{
return [
LarrockCoreServiceProvider::class
LarrockCoreServiceProvider::class,
LarrockComponentBlocksServiceProvider::class
];
}

public function testRender()
{
$this->FormCheckbox->setDefaultValue('test');
$this->assertNotEmpty($this->FormCheckbox->render($this->FormCheckbox, collect([])));
}
}
1 change: 1 addition & 0 deletions tests/Helpers/FormBuilder/FormHiddenTest.php
Expand Up @@ -33,6 +33,7 @@ protected function getPackageProviders($app)

public function testRender()
{
$this->FormHidden->setDefaultValue('test');
$this->assertNotEmpty($this->FormHidden->render($this->FormHidden, collect([])));
}
}
1 change: 1 addition & 0 deletions tests/Helpers/FormBuilder/FormPasswordTest.php
Expand Up @@ -33,6 +33,7 @@ protected function getPackageProviders($app)

public function testRender()
{
$this->FormPassword->setDefaultValue('test');
$this->assertNotEmpty($this->FormPassword->render($this->FormPassword, collect([])));
}
}
1 change: 1 addition & 0 deletions tests/Helpers/FormBuilder/FormSelectKeyTest.php
Expand Up @@ -59,6 +59,7 @@ public function testSetOptionsKey()

public function testRender()
{
$this->FormSelectKey->setDefaultValue('test');
$data = new Config();
$data->test_name = collect([]);
$this->assertNotEmpty($this->FormSelectKey->render($this->FormSelectKey, $data));
Expand Down
1 change: 1 addition & 0 deletions tests/Helpers/FormBuilder/FormSelectTest.php
Expand Up @@ -58,6 +58,7 @@ public function testSetAllowCreate()

public function testRender()
{
$this->FormSelect->setDefaultValue('test');
$this->assertNotEmpty($this->FormSelect->render($this->FormSelect, collect([])));
}
}
1 change: 1 addition & 0 deletions tests/Helpers/FormBuilder/FormTextareaTest.php
Expand Up @@ -48,6 +48,7 @@ public function testSetNotEditor()

public function testRender()
{
$this->FormTextarea->setDefaultValue('test');
$this->assertNotEmpty($this->FormTextarea->render($this->FormTextarea, collect([])));
}
}
95 changes: 95 additions & 0 deletions tests/Helpers/TreeTest.php
@@ -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));
}
}

0 comments on commit 8ed04d9

Please sign in to comment.