jqh 6 år sedan
förälder
incheckning
85a929aca4

+ 1 - 1
resources/views/login.blade.php

@@ -83,7 +83,7 @@
         <div class="col-xs-8">
           @if(config('admin.auth.remember'))
             <div class="checkbox checkbox-primary checkbox-circle">
-              <input id="remember" name="remember" type="checkbox" value="1" {{ (!old('username') || old('remember')) ? 'checked' : '' }}>
+              <input id="remember" name="remember" type="checkbox" value="1" {{ (old('remember')) ? 'checked' : '' }}>
               <label for="remember">
                 {{ trans('admin.remember_me') }}
               </label>

+ 92 - 0
tests/BasicTestCase.php

@@ -0,0 +1,92 @@
+<?php
+
+namespace Tests;
+
+use Dcat\Admin\Models\Administrator;
+use Illuminate\Filesystem\Filesystem;
+use Illuminate\Support\Arr;
+use Illuminate\Support\Facades\DB;
+use Illuminate\Support\Facades\Schema;
+
+trait BasicTestCase
+{
+    public function setUp(): void
+    {
+        parent::setUp();
+
+        $adminConfig = require __DIR__.'/config/admin.php';
+
+        $this->app['config']->set('database.default', 'mysql');
+        $this->app['config']->set('database.connections.mysql.host', env('MYSQL_HOST', 'localhost'));
+        $this->app['config']->set('database.connections.mysql.database', 'laravel_dcat_admin_test');
+        $this->app['config']->set('database.connections.mysql.username', 'root');
+        $this->app['config']->set('database.connections.mysql.password', '');
+        $this->app['config']->set('app.key', 'AckfSECXIvnK5r28GVIWUAxmbBSjTsmF');
+        $this->app['config']->set('filesystems', require __DIR__.'/config/filesystems.php');
+        $this->app['config']->set('admin', $adminConfig);
+
+        foreach (Arr::dot(Arr::get($adminConfig, 'auth'), 'auth.') as $key => $value) {
+            $this->app['config']->set($key, $value);
+        }
+
+        $this->artisan('vendor:publish', ['--provider' => 'Dcat\Admin\AdminServiceProvider']);
+
+        Schema::defaultStringLength(191);
+
+        $this->artisan('admin:install');
+
+        $this->migrateTestTables();
+
+        if (file_exists($routes = admin_path('routes.php'))) {
+            require $routes;
+        }
+
+        require __DIR__.'/routes.php';
+
+        require __DIR__.'/seeds/factory.php';
+
+        view()->addNamespace('admin-tests', __DIR__.'/views');
+
+        if ($this->login) {
+            $this->be($this->getUser(), 'admin');
+        }
+    }
+
+    /**
+     * @return Administrator
+     */
+    protected function getUser()
+    {
+        if ($this->user) {
+            return $this->user;
+        }
+
+        return $this->user = Administrator::first();
+    }
+
+    public function tearDown(): void
+    {
+        (new \CreateAdminTables())->down();
+
+        (new \CreateTestTables())->down();
+
+        DB::select("delete from `migrations` where `migration` = '2016_01_04_173148_create_admin_tables'");
+        DB::select("delete from `migrations` where `migration` = '2016_11_22_093148_create_test_tables'");
+
+        parent::tearDown();
+    }
+
+    /**
+     * run package database migrations.
+     *
+     * @return void
+     */
+    public function migrateTestTables()
+    {
+        $fileSystem = new Filesystem();
+
+        $fileSystem->requireOnce(__DIR__.'/migrations/2016_11_22_093148_create_test_tables.php');
+
+        (new \CreateTestTables())->up();
+    }
+}

+ 89 - 0
tests/Controllers/DropdownController.php

@@ -0,0 +1,89 @@
+<?php
+
+namespace Tests\Controllers;
+
+use Dcat\Admin\Admin;
+use Dcat\Admin\Layout\Content;
+use Dcat\Admin\Layout\Row;
+use Dcat\Admin\Widgets\Box;
+use Dcat\Admin\Widgets\Code;
+use Dcat\Admin\Widgets\Dropdown;
+use Illuminate\Routing\Controller;
+
+class DropdownController extends Controller
+{
+    protected $tian = ['甲', '乙', '丙', '丁', '戊', '己', '庚', '辛', '壬', '癸'];
+    protected $di = ['寅', '卯', '辰', '巳', '午', '未', '申', '酉', '戌', '亥', '子', '丑'];
+
+    public function index(Content $content)
+    {
+        return $content->header('Dropdown Menu')
+            ->row(function (Row $row) {
+                $row->column(3, $this->example1());
+                $row->column(3, $this->example2());
+                $row->column(3, $this->example3());
+            });
+
+    }
+
+    protected function example1()
+    {
+        $menu1 = Dropdown::make($this->tian)->button('天干');
+
+        $menu2 = Dropdown::make()
+            ->button('使用标题')
+            ->buttonClass('btn btn-sm btn-inverse')
+            ->options($this->tian, '天干')
+            ->options($this->di, '地支');
+
+        $menu3 = Dropdown::make([1, 2, 3, Dropdown::DIVIDER, 4, 5])->button('中间加分隔线');
+
+        return Box::make(
+            'Example1',
+            $menu1->render().' &nbsp; '.$menu2->render().' &nbsp; '.$menu3->render()
+        );
+    }
+
+    protected function example2()
+    {
+        $menu = Dropdown::make($this->tian);
+
+        $menu->map(function ($v, $k) {
+            if ($k === 7) {
+                $this->divider();
+            }
+            $k++;
+            return "{$k}. $v";
+        });
+
+        return Box::make('Example2', function () use ($menu) {
+            return "<div class='dropdown'><a class='btn no-shadow text-muted' data-toggle='dropdown' href='javascript:void(0)'><i class='ti-email'></i> 自定义按钮 </a>{$menu->render()}</div>";
+        });
+    }
+
+    protected function example3()
+    {
+        $menu1 = Dropdown::make()
+            ->options($this->tian, '天干')
+            ->options($this->di, '地支')
+            ->click()
+            ->buttonClass('btn btn-sm btn-light')
+            ->map(function ($v, $k) {
+                $k++;
+
+                return "<a class='test_item' data-id='$k', data-value='{$v}' data-test='Hello world.' href='javascript:void(0)'>{$k}. $v</a>";
+            });
+
+        Admin::script(
+            <<<JS
+$('.test_item').click(function () {
+    LA.info("Selected: " + JSON.stringify($(this).data()));
+});
+JS
+        );
+
+        return Box::make('Example3', $menu1);
+    }
+
+
+}

+ 42 - 0
tests/Controllers/UserController.php

@@ -8,6 +8,7 @@ use Dcat\Admin\Form;
 use Dcat\Admin\Grid;
 use Dcat\Admin\Layout\Content;
 use Dcat\Admin\Controllers\HasResourceActions;
+use Dcat\Admin\Show;
 use Tests\Models\Tag;
 use Tests\Repositories\User;
 
@@ -57,6 +58,21 @@ class UserController extends Controller
         return $content->body($this->form());
     }
 
+    /**
+     * Show interface.
+     *
+     * @param mixed $id
+     * @param Content $content
+     * @return Content
+     */
+    public function show($id, Content $content)
+    {
+        return $content
+            ->header('User')
+            ->description('Detail')
+            ->body($this->detail($id));
+    }
+
     /**
      * Make a grid builder.
      *
@@ -126,6 +142,32 @@ class UserController extends Controller
         return $grid;
     }
 
+    /**
+     * Make a show builder.
+     *
+     * @param mixed $id
+     * @return Show
+     */
+    protected function detail($id)
+    {
+        $show = new Show(new User());
+
+        $show->setId($id);
+
+        $show->id('ID');
+        $show->username();
+        $show->email;
+
+        $show->divider();
+
+        $show->full_name();
+        $show->field('profile.postcode');
+
+        $show->tags->json();
+
+        return $show;
+    }
+
     /**
      * Make a form builder.
      *

+ 59 - 0
tests/DuskTestCase.php

@@ -0,0 +1,59 @@
+<?php
+
+namespace Tests;
+
+use Dcat\Admin\Models\Administrator;
+use Laravel\Dusk\Browser;
+use Laravel\Dusk\TestCase as BaseTestCase;
+use Facebook\WebDriver\Chrome\ChromeOptions;
+use Facebook\WebDriver\Remote\RemoteWebDriver;
+use Facebook\WebDriver\Remote\DesiredCapabilities;
+
+abstract class DuskTestCase extends BaseTestCase
+{
+    use CreatesApplication,
+        BasicTestCase;
+
+    /**
+     * @var Administrator
+     */
+    protected $user;
+
+    protected $login = true;
+
+    public function login(Browser $browser)
+    {
+        $browser->loginAs($this->getUser(), 'admin');
+    }
+
+    /**
+     * Prepare for Dusk test execution.
+     *
+     * @beforeClass
+     * @return void
+     */
+    public static function prepare()
+    {
+        static::startChromeDriver();
+    }
+
+    /**
+     * Create the RemoteWebDriver instance.
+     *
+     * @return \Facebook\WebDriver\Remote\RemoteWebDriver
+     */
+    protected function driver()
+    {
+        $options = (new ChromeOptions)->addArguments([
+            '--disable-gpu',
+            '--headless',
+            '--window-size=1920,1080',
+        ]);
+
+        return RemoteWebDriver::create(
+            'http://localhost:9515', DesiredCapabilities::chrome()->setCapability(
+                ChromeOptions::CAPABILITY, $options
+            )
+        );
+    }
+}

+ 2 - 0
tests/Feature/AuthTest.php

@@ -6,6 +6,8 @@ use Tests\TestCase;
 
 class AuthTest extends TestCase
 {
+    protected $login = false;
+
     public function testLoginPage()
     {
         $this->visit('admin/auth/login')

+ 1 - 1
tests/Feature/CombineGridTest.php

@@ -6,7 +6,7 @@ use Tests\TestCase;
 
 class CombineGridTest extends TestCase
 {
-    protected $login = true;
+
 
     public function test()
     {

+ 1 - 1
tests/Feature/IndexTest.php

@@ -6,7 +6,7 @@ use Tests\TestCase;
 
 class IndexTest extends TestCase
 {
-    protected $login = true;
+
 
     public function testIndex()
     {

+ 5 - 3
tests/Feature/MenuTest.php

@@ -8,8 +8,6 @@ use Dcat\Admin\Models\Menu;
 
 class MenuTest extends TestCase
 {
-    protected $login = true;
-
     public function testMenuIndex()
     {
         $this->visit('admin/auth/menu')
@@ -20,7 +18,11 @@ class MenuTest extends TestCase
             ->see('Roles')
             ->see('Permission')
             ->see('Menu')
-            ->see('Operation log');
+            ->see('Operation log')
+            ->see('Helpers')
+            ->see('Extensions')
+            ->see('Scaffold')
+            ->see('Routes');
     }
 
     public function testAddMenu()

+ 1 - 1
tests/Feature/OperationLogTest.php

@@ -7,7 +7,7 @@ use Dcat\Admin\Models\OperationLog;
 
 class OperationLogTest extends TestCase
 {
-    protected $login = true;
+
 
     public function testOperationLogIndex()
     {

+ 0 - 2
tests/Feature/PermissionsTest.php

@@ -9,8 +9,6 @@ use Tests\TestCase;
 
 class PermissionsTest extends TestCase
 {
-    protected $login = true;
-
     public function testPermissionsIndex()
     {
         $this->assertTrue(Administrator::first()->isAdministrator());

+ 1 - 1
tests/Feature/RolesTest.php

@@ -8,7 +8,7 @@ use Dcat\Admin\Models\Administrator;
 
 class RolesTest extends TestCase
 {
-    protected $login = true;
+
 
     public function testRolesIndex()
     {

+ 2 - 0
tests/Feature/SectionTest.php

@@ -6,6 +6,8 @@ use Tests\TestCase;
 
 class SectionTest extends TestCase
 {
+    protected $login = false;
+
     public function testInjectValues()
     {
         // view

+ 0 - 2
tests/Feature/TranslationTest.php

@@ -8,8 +8,6 @@ use Tests\TestCase;
 
 class TranslationTest extends TestCase
 {
-    protected $login = true;
-
     public function testTransField()
     {
         $this->visit('admin/tests/users');

+ 0 - 2
tests/Feature/UserFormTest.php

@@ -8,8 +8,6 @@ use Tests\Models\User as UserModel;
 
 class UserFormTest extends TestCase
 {
-    protected $login = true;
-
     public function testCreatePage()
     {
         $this->visit('admin/tests/users/create')

+ 0 - 2
tests/Feature/UserGridTest.php

@@ -8,8 +8,6 @@ use Tests\Models\User as UserModel;
 
 class UserGridTest extends TestCase
 {
-    protected $login = true;
-
     public function testIndexPage()
     {
         $this->visit('admin/tests/users')

+ 0 - 2
tests/Feature/UserSettingTest.php

@@ -8,8 +8,6 @@ use Illuminate\Support\Facades\File;
 
 class UserSettingTest extends TestCase
 {
-    protected $login = true;
-
     public function testVisitSettingPage()
     {
         $this->visit('admin/auth/setting')

+ 41 - 0
tests/Feature/UserShowTest.php

@@ -0,0 +1,41 @@
+<?php
+
+namespace Tests\Feature;
+
+use Tests\TestCase;
+
+class UserShowTest extends TestCase
+{
+    public function test()
+    {
+        $this->seedsTable(10);
+
+        $this->visit('admin/tests/users/1');
+
+        $this->assertResponseStatus(200);
+
+        $this->see('Detail')
+            ->see('ID')
+            ->see('username')
+            ->see('email')
+            ->see('full name')
+            ->see('postcode')
+            ->see('tags');
+
+        $this->seeInElement('a[href="http://localhost:8000/admin/tests/users"]', 'List')
+            ->seeInElement('a[href="http://localhost:8000/admin/tests/users/1/edit"]', 'Edit');
+
+        $this->assertCount(1, $this->crawler()->filter('hr'));
+
+    }
+
+    protected function seedsTable($count = 100)
+    {
+        factory(\Tests\Models\User::class, $count)
+            ->create()
+            ->each(function ($u) {
+                $u->profile()->save(factory(\Tests\Models\Profile::class)->make());
+                $u->tags()->saveMany(factory(\Tests\Models\Tag::class, 5)->make());
+            });
+    }
+}

+ 0 - 2
tests/Feature/UsersTest.php

@@ -7,8 +7,6 @@ use Tests\TestCase;
 
 class UsersTest extends TestCase
 {
-    protected $login = true;
-
     public function testUsersIndexPage()
     {
         $this->visit('admin/auth/users')

+ 3 - 69
tests/TestCase.php

@@ -11,7 +11,8 @@ use Laravel\BrowserKitTesting\TestCase as BaseTestCase;
 
 class TestCase extends BaseTestCase
 {
-    use CreatesApplication;
+    use CreatesApplication,
+        BasicTestCase;
 
     protected $baseUrl = 'http://localhost:8000';
 
@@ -20,73 +21,6 @@ class TestCase extends BaseTestCase
      */
     protected $user;
 
-    protected $login = false;
+    protected $login = true;
 
-    public function setUp(): void
-    {
-        parent::setUp();
-
-        $adminConfig = require __DIR__.'/config/admin.php';
-
-        $this->app['config']->set('database.default', 'mysql');
-        $this->app['config']->set('database.connections.mysql.host', env('MYSQL_HOST', 'localhost'));
-        $this->app['config']->set('database.connections.mysql.database', 'laravel_dcat_admin_test');
-        $this->app['config']->set('database.connections.mysql.username', 'root');
-        $this->app['config']->set('database.connections.mysql.password', '');
-        $this->app['config']->set('app.key', 'AckfSECXIvnK5r28GVIWUAxmbBSjTsmF');
-        $this->app['config']->set('filesystems', require __DIR__.'/config/filesystems.php');
-        $this->app['config']->set('admin', $adminConfig);
-
-        foreach (Arr::dot(Arr::get($adminConfig, 'auth'), 'auth.') as $key => $value) {
-            $this->app['config']->set($key, $value);
-        }
-
-        $this->artisan('vendor:publish', ['--provider' => 'Dcat\Admin\AdminServiceProvider']);
-
-        Schema::defaultStringLength(191);
-
-        $this->artisan('admin:install');
-
-        $this->migrateTestTables();
-
-        if (file_exists($routes = admin_path('routes.php'))) {
-            require $routes;
-        }
-
-        require __DIR__.'/routes.php';
-
-        require __DIR__.'/seeds/factory.php';
-
-        view()->addNamespace('admin-tests', __DIR__.'/views');
-
-        if ($this->login) {
-            $this->be($this->user = Administrator::first(), 'admin');
-        }
-    }
-
-    public function tearDown(): void
-    {
-        (new \CreateAdminTables())->down();
-
-        (new \CreateTestTables())->down();
-
-        DB::select("delete from `migrations` where `migration` = '2016_01_04_173148_create_admin_tables'");
-        DB::select("delete from `migrations` where `migration` = '2016_11_22_093148_create_test_tables'");
-
-        parent::tearDown();
-    }
-
-    /**
-     * run package database migrations.
-     *
-     * @return void
-     */
-    public function migrateTestTables()
-    {
-        $fileSystem = new Filesystem();
-
-        $fileSystem->requireOnce(__DIR__.'/migrations/2016_11_22_093148_create_test_tables.php');
-
-        (new \CreateTestTables())->up();
-    }
 }