From f06eda03aced894b0974c1c0fb0fb1ba34cbf01a Mon Sep 17 00:00:00 2001 From: Talemul Islam Date: Fri, 16 May 2025 20:53:54 +0600 Subject: [PATCH 01/10] update --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 1a2c3490..8bf257e6 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,7 @@ "doctrine/dbal": "2.*|3.*" }, "require-dev": { - "laravel/laravel": ">=8.0", + "laravel/laravel": ">=8.0|^10.0|^11.0|^12.0", "fzaninotto/faker": "~1.4", "intervention/image": "~2.3", "laravel/browser-kit-testing": "^6.0", From 3dfb1b87fb20c7ad7983d9b9b7fb147a5fd8da1a Mon Sep 17 00:00:00 2001 From: Talemul Islam Date: Fri, 16 May 2025 21:20:20 +0600 Subject: [PATCH 02/10] update --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 8bf257e6..da8306e9 100644 --- a/composer.json +++ b/composer.json @@ -13,9 +13,9 @@ ], "require": { "php": "~7.3|~8.0", - "symfony/dom-crawler": "~3.1|~4.0|~5.0", + "symfony/dom-crawler": "~3.1|~4.0|~5.0|~6.0", "laravel/framework": ">=7.0", - "doctrine/dbal": "2.*|3.*" + "doctrine/dbal": "2.*|3.*|4.*" }, "require-dev": { "laravel/laravel": ">=8.0|^10.0|^11.0|^12.0", From 1a4fd1711223839193fa0407db6347ef77ca9ab3 Mon Sep 17 00:00:00 2001 From: Talemul Islam Date: Fri, 16 May 2025 22:28:05 +0600 Subject: [PATCH 03/10] update --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index da8306e9..65a8d3aa 100644 --- a/composer.json +++ b/composer.json @@ -15,7 +15,7 @@ "php": "~7.3|~8.0", "symfony/dom-crawler": "~3.1|~4.0|~5.0|~6.0", "laravel/framework": ">=7.0", - "doctrine/dbal": "2.*|3.*|4.*" + "doctrine/dbal": "2.*|3.*|4.*|5.*" }, "require-dev": { "laravel/laravel": ">=8.0|^10.0|^11.0|^12.0", From 8e8fcf2a547b0ef790059eed4c989bfe8065689e Mon Sep 17 00:00:00 2001 From: Talemul Islam Date: Fri, 16 May 2025 22:49:22 +0600 Subject: [PATCH 04/10] update --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 65a8d3aa..3d9db226 100644 --- a/composer.json +++ b/composer.json @@ -13,7 +13,7 @@ ], "require": { "php": "~7.3|~8.0", - "symfony/dom-crawler": "~3.1|~4.0|~5.0|~6.0", + "symfony/dom-crawler": "~3.1|~4.0|~5.0|~6.0|~7.0", "laravel/framework": ">=7.0", "doctrine/dbal": "2.*|3.*|4.*|5.*" }, From 0ff8b715de44af8fe9bdbbf6f6adf6518bf38709 Mon Sep 17 00:00:00 2001 From: Talemul Islam Date: Fri, 16 May 2025 23:14:51 +0600 Subject: [PATCH 05/10] update --- src/Console/ResourceGenerator.php | 70 ++++++++++++++++++++++++------- 1 file changed, 55 insertions(+), 15 deletions(-) diff --git a/src/Console/ResourceGenerator.php b/src/Console/ResourceGenerator.php index e6c98d1d..4245b1c5 100644 --- a/src/Console/ResourceGenerator.php +++ b/src/Console/ResourceGenerator.php @@ -211,33 +211,73 @@ protected function getReservedColumns() * * @return \Doctrine\DBAL\Schema\Column[] */ +// protected function getTableColumns() +// { +// if (!$this->model->getConnection()->isDoctrineAvailable()) { +// throw new \Exception( +// 'You need to require doctrine/dbal: ~2.3 in your own composer.json to get database columns. ' +// ); +// } +// +// $table = $this->model->getConnection()->getTablePrefix().$this->model->getTable(); +// /** @var \Doctrine\DBAL\Schema\MySqlSchemaManager $schema */ +// $schema = $this->model->getConnection()->getDoctrineSchemaManager($table); +// +// // custom mapping the types that doctrine/dbal does not support +// $databasePlatform = $schema->getDatabasePlatform(); +// +// foreach ($this->doctrineTypeMapping as $doctrineType => $dbTypes) { +// foreach ($dbTypes as $dbType) { +// $databasePlatform->registerDoctrineTypeMapping($dbType, $doctrineType); +// } +// } +// +// $database = null; +// if (strpos($table, '.')) { +// list($database, $table) = explode('.', $table); +// } +// +// return $schema->listTableColumns($table, $database); +// } + protected function getTableColumns() { - if (!$this->model->getConnection()->isDoctrineAvailable()) { + $connection = $this->model->getConnection(); + + // Check if the connection is using Doctrine DBAL + if ($connection->getDriverName() !== 'pgsql' && !class_exists('Doctrine\DBAL\Driver\Connection')) { throw new \Exception( - 'You need to require doctrine/dbal: ~2.3 in your own composer.json to get database columns. ' + 'Doctrine DBAL is required to get database columns. Please install "doctrine/dbal" in your composer.json.' ); } - $table = $this->model->getConnection()->getTablePrefix().$this->model->getTable(); - /** @var \Doctrine\DBAL\Schema\MySqlSchemaManager $schema */ - $schema = $this->model->getConnection()->getDoctrineSchemaManager($table); + $table = $connection->getTablePrefix() . $this->model->getTable(); + + // Use the Doctrine Schema Manager only if Doctrine DBAL is available + if (class_exists('Doctrine\DBAL\Driver\Connection')) { + /** @var \Doctrine\DBAL\Schema\AbstractSchemaManager $schema */ + $schema = $connection->getDoctrineSchemaManager(); - // custom mapping the types that doctrine/dbal does not support - $databasePlatform = $schema->getDatabasePlatform(); + // Custom mapping the types that Doctrine DBAL does not support + $databasePlatform = $schema->getDatabasePlatform(); - foreach ($this->doctrineTypeMapping as $doctrineType => $dbTypes) { - foreach ($dbTypes as $dbType) { - $databasePlatform->registerDoctrineTypeMapping($dbType, $doctrineType); + foreach ($this->doctrineTypeMapping as $doctrineType => $dbTypes) { + foreach ($dbTypes as $dbType) { + $databasePlatform->registerDoctrineTypeMapping($dbType, $doctrineType); + } + } + + // Handle potential table being prefixed with a database name + $database = null; + if (strpos($table, '.')) { + list($database, $table) = explode('.', $table); } - } - $database = null; - if (strpos($table, '.')) { - list($database, $table) = explode('.', $table); + return $schema->listTableColumns($table, $database); } - return $schema->listTableColumns($table, $database); + // Return an empty array or handle non-Doctrine case + return []; } /** From 36fd81bfc4ec85f85d0579aeec1387d7aebeb8d7 Mon Sep 17 00:00:00 2001 From: Talemul Islam Date: Tue, 20 May 2025 23:48:28 +0600 Subject: [PATCH 06/10] update php unit test to pest --- .env | 58 +++ .gitignore | 1 + composer.json | 124 ++--- phpunit.xml.dist | 26 +- tests/AuthTest.php | 110 +++-- tests/Feature/AuthTest.php | 1 + tests/Feature/FileUploadTest.php | 1 + tests/Feature/ImageUploadTest.php | 1 + tests/Feature/IndexTest.php | 1 + tests/Feature/InstallTest.php | 1 + tests/Feature/LaravelTest.php | 1 + tests/Feature/MenuTest.php | 1 + tests/Feature/ModelTreeTest.php | 1 + tests/Feature/OperationLogTest.php | 1 + tests/Feature/PermissionsTest.php | 1 + tests/Feature/RolesTest.php | 1 + tests/Feature/UserFormTest.php | 1 + tests/Feature/UserGridTest.php | 1 + tests/Feature/UserSettingTest.php | 1 + tests/Feature/UsersTest.php | 1 + tests/FileUploadTest.php | 241 +++++----- tests/ImageUploadTest.php | 330 +++++++------- tests/IndexTest.php | 82 ++-- tests/InstallTest.php | 27 +- tests/LaravelTest.php | 15 +- tests/MenuTest.php | 130 +++--- tests/ModelTreeTest.php | 31 +- tests/OperationLogTest.php | 150 +++--- tests/PermissionsTest.php | 404 ++++++++-------- tests/RolesTest.php | 190 ++++---- tests/TestCase.php | 98 +--- tests/UserFormTest.php | 387 ++++++++-------- tests/UserGridTest.php | 431 ++++++++---------- tests/UserSettingTest.php | 170 ++++--- tests/UsersTest.php | 170 ++++--- tests/config/admin.php | 26 +- tests/config/filesystems.php | 2 +- tests/controllers/FileController.php | 6 +- tests/controllers/ImageController.php | 6 +- tests/controllers/MultipleImageController.php | 6 +- tests/controllers/UserController.php | 6 +- .../2016_11_22_093148_create_test_tables.php | 99 ++++ tests/database/factories/ProfileFactory.php | 25 + tests/database/factories/TagFactory.php | 17 + tests/database/factories/UserFactory.php | 22 + .../seeders/LegacyUserTableSeeder.php | 19 + tests/database/seeders/UserTableSeeder.php | 24 + tests/models/Tree.php | 2 +- tests/pest.php | 5 + 49 files changed, 1717 insertions(+), 1738 deletions(-) create mode 100644 .env create mode 100644 tests/Feature/AuthTest.php create mode 100644 tests/Feature/FileUploadTest.php create mode 100644 tests/Feature/ImageUploadTest.php create mode 100644 tests/Feature/IndexTest.php create mode 100644 tests/Feature/InstallTest.php create mode 100644 tests/Feature/LaravelTest.php create mode 100644 tests/Feature/MenuTest.php create mode 100644 tests/Feature/ModelTreeTest.php create mode 100644 tests/Feature/OperationLogTest.php create mode 100644 tests/Feature/PermissionsTest.php create mode 100644 tests/Feature/RolesTest.php create mode 100644 tests/Feature/UserFormTest.php create mode 100644 tests/Feature/UserGridTest.php create mode 100644 tests/Feature/UserSettingTest.php create mode 100644 tests/Feature/UsersTest.php create mode 100644 tests/database/Migrations/2016_11_22_093148_create_test_tables.php create mode 100644 tests/database/factories/ProfileFactory.php create mode 100644 tests/database/factories/TagFactory.php create mode 100644 tests/database/factories/UserFactory.php create mode 100644 tests/database/seeders/LegacyUserTableSeeder.php create mode 100644 tests/database/seeders/UserTableSeeder.php create mode 100644 tests/pest.php diff --git a/.env b/.env new file mode 100644 index 00000000..415f6df6 --- /dev/null +++ b/.env @@ -0,0 +1,58 @@ +APP_NAME=Laravel +APP_ENV=local +APP_KEY=base64:zteoqWgF8QKpwp+etk3Z/OkK6Qy/NrDkb0/hm/jvCAw= +APP_DEBUG=true +APP_URL=http://localhost + +LOG_CHANNEL=stack +LOG_DEPRECATIONS_CHANNEL=null +LOG_LEVEL=debug + +DB_CONNECTION=pgsql +DB_HOST=localhost +DB_PORT=5432 +DB_DATABASE=admin_test +DB_USERNAME=postgres +DB_PASSWORD=nopass + +BROADCAST_DRIVER=log +CACHE_DRIVER=file +FILESYSTEM_DISK=local +QUEUE_CONNECTION=sync +SESSION_DRIVER=file +SESSION_LIFETIME=120 + +MEMCACHED_HOST=127.0.0.1 + +REDIS_HOST=127.0.0.1 +REDIS_PASSWORD=null +REDIS_PORT=6379 + +MAIL_MAILER=smtp +MAIL_HOST=mailpit +MAIL_PORT=1025 +MAIL_USERNAME=null +MAIL_PASSWORD=null +MAIL_ENCRYPTION=null +MAIL_FROM_ADDRESS="hello@example.com" +MAIL_FROM_NAME="${APP_NAME}" + +AWS_ACCESS_KEY_ID= +AWS_SECRET_ACCESS_KEY= +AWS_DEFAULT_REGION=us-east-1 +AWS_BUCKET= +AWS_USE_PATH_STYLE_ENDPOINT=false + +PUSHER_APP_ID= +PUSHER_APP_KEY= +PUSHER_APP_SECRET= +PUSHER_HOST= +PUSHER_PORT=443 +PUSHER_SCHEME=https +PUSHER_APP_CLUSTER=mt1 + +VITE_PUSHER_APP_KEY="${PUSHER_APP_KEY}" +VITE_PUSHER_HOST="${PUSHER_HOST}" +VITE_PUSHER_PORT="${PUSHER_PORT}" +VITE_PUSHER_SCHEME="${PUSHER_SCHEME}" +VITE_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}" diff --git a/.gitignore b/.gitignore index 4e530b36..dd2c8eb9 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,4 @@ composer.lock resources/assets/minify-manifest.json resources/assets/open-admin.min.css resources/assets/open-admin.min.js +.env diff --git a/composer.json b/composer.json index 3d9db226..c2b5e5e5 100644 --- a/composer.json +++ b/composer.json @@ -1,65 +1,69 @@ { - "name": "open-admin-org/open-admin", - "description": "open-admin. Open-source Laravel Admin panel. No pro or paid package, free & open. Based on laravel-admin, with special thanks to z-song", - "type": "library", - "keywords": ["laravel", "admin", "grid", "form", "open-admin","open","free"], - "homepage": "https://github.com/open-admin-org/open-admin", - "license": "MIT", - "authors": [ - { - "name": "Sjors Broersen | Open-Admin.org", - "email": "info@open-admin.org" - } - ], - "require": { - "php": "~7.3|~8.0", - "symfony/dom-crawler": "~3.1|~4.0|~5.0|~6.0|~7.0", - "laravel/framework": ">=7.0", - "doctrine/dbal": "2.*|3.*|4.*|5.*" - }, - "require-dev": { - "laravel/laravel": ">=8.0|^10.0|^11.0|^12.0", - "fzaninotto/faker": "~1.4", - "intervention/image": "~2.3", - "laravel/browser-kit-testing": "^6.0", - "spatie/phpunit-watcher": "^1.22.0" - }, - "autoload": { - "psr-4": { - "OpenAdmin\\Admin\\": "src/" - }, - "files": [ - "src/helpers.php" - ] - }, - "autoload-dev": { - "psr-4": { - "Tests\\Models\\": "tests/models", - "Tests\\Controllers\\": "tests/controllers" - }, - "classmap": [ - "tests/TestCase.php" - ] - }, - "scripts": { - "sass": "sass --watch resources/assets/open-admin/scss/styles.scss:resources/assets/open-admin/css/styles.css resources/assets/open-admin/scss/pages:resources/assets/open-admin/css/pages --style compressed", - "test": "./vendor/bin/phpunit" - }, - "suggest": { - "intervention/image": "Required to handling and manipulation upload images (~2.3).", - "spatie/eloquent-sortable": "Required to built orderable gird." + "name": "open-admin-org/open-admin", + "description": "open-admin. Open-source Laravel Admin panel. No pro or paid package, free & open. Based on laravel-admin, with special thanks to z-song", + "type": "library", + "keywords": ["laravel", "admin", "grid", "form", "open-admin","open","free"], + "homepage": "https://github.com/open-admin-org/open-admin", + "license": "MIT", + "authors": [ + { + "name": "Sjors Broersen | Open-Admin.org", + "email": "info@open-admin.org" + } + ], + "require": { + "php": "^8.2", + "laravel/framework": "12.0", + "symfony/dom-crawler": "^6.0|^7.0", + "doctrine/dbal": "^3.0|^4.0|^5.0", + "phpunit/phpunit": "11.5.15", + "pestphp/pest": "3.8", + "nunomaduro/collision": "^8.8" + + }, + "require-dev": { + "intervention/image": "^2.7", + "pestphp/pest-plugin-drift": "^3.0", + "laravel/browser-kit-testing": "^7.2" + }, + "autoload": { + "psr-4": { + "OpenAdmin\\Admin\\": "src/" }, - "extra": { - "laravel": { - "providers": [ - "OpenAdmin\\Admin\\AdminServiceProvider" - ], - "aliases": { - "Admin": "OpenAdmin\\Admin\\Facades\\Admin" - } - } + "files": [ + "src/helpers.php" + ] + }, + "autoload-dev": { + "psr-4": { + "Tests\\": "tests/" }, - "config": { - "process-timeout": 0 + "classmap": [ + "tests/TestCase.php" + ] + }, + "scripts": { + "sass": "sass --watch resources/assets/open-admin/scss/styles.scss:resources/assets/open-admin/css/styles.css resources/assets/open-admin/scss/pages:resources/assets/open-admin/css/pages --style compressed", + "test": "./vendor/bin/phpunit" + }, + "suggest": { + "intervention/image": "Required to handling and manipulation upload images (~2.3).", + "spatie/eloquent-sortable": "Required to built orderable gird." + }, + "extra": { + "laravel": { + "providers": [ + "OpenAdmin\\Admin\\AdminServiceProvider" + ], + "aliases": { + "Admin": "OpenAdmin\\Admin\\Facades\\Admin" + } + } + }, + "config": { + "process-timeout": 0, + "allow-plugins": { + "pestphp/pest-plugin": true } + } } diff --git a/phpunit.xml.dist b/phpunit.xml.dist index b9440089..f8966410 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,18 +1,18 @@ - + cacheResult="true" + cacheDirectory=".phpunit.cache"> + - - tests/ + + ./tests - \ No newline at end of file + + + + app + + + diff --git a/tests/AuthTest.php b/tests/AuthTest.php index 3b491ff4..7d48c00f 100644 --- a/tests/AuthTest.php +++ b/tests/AuthTest.php @@ -1,61 +1,55 @@ visit('admin/auth/login') - ->see('login'); - } - - public function testVisitWithoutLogin() - { - $this->visit('admin') - ->dontSeeIsAuthenticated('admin') - ->seePageIs('admin/auth/login'); - } - - public function testLogin() - { - $credentials = ['username' => 'admin', 'password' => 'admin']; - - $this->visit('admin/auth/login') - ->see('login') - ->submitForm('Login', $credentials) - ->see('dashboard') - ->seeCredentials($credentials, 'admin') - ->seeIsAuthenticated('admin') - ->seePageIs('admin') - ->see('Dashboard') - ->see('Description...') - - ->see('Environment') - ->see('PHP version') - ->see('Laravel version') - - ->see('Available extensions') - ->seeLink('open-admin-ext/helpers', 'https://github.com/open-admin-extensions/helpers') - ->seeLink('open-admin-ext/backup', 'https://github.com/open-admin-extensions/backup') - ->seeLink('open-admin-ext/media-manager', 'https://github.com/open-admin-extensions/media-manager') - - ->see('Dependencies') - ->see('php') +uses(\TestCase::class); +test('login page', function () { + $this->visit('admin/auth/login') + ->see('login'); +}); + +test('visit without login', function () { + $this->visit('admin') + ->dontSeeIsAuthenticated('admin') + ->seePageIs('admin/auth/login'); +}); + +test('login', function () { + $credentials = ['username' => 'admin', 'password' => 'admin']; + + $this->visit('admin/auth/login') + ->see('login') + ->submitForm('Login', $credentials) + ->see('dashboard') + ->seeCredentials($credentials, 'admin') + ->seeIsAuthenticated('admin') + ->seePageIs('admin') + ->see('Dashboard') + ->see('Description...') + + ->see('Environment') + ->see('PHP version') + ->see('Laravel version') + + ->see('Available extensions') + ->seeLink('laravel-admin-ext/helpers', 'https://github.com/laravel-admin-extensions/helpers') + ->seeLink('laravel-admin-ext/backup', 'https://github.com/laravel-admin-extensions/backup') + ->seeLink('laravel-admin-ext/media-manager', 'https://github.com/laravel-admin-extensions/media-manager') + + ->see('Dependencies') + ->see('php') // ->see('>=7.0.0') - ->see('laravel/framework'); - - $this - ->see('Admin') - ->see('Users') - ->see('Roles') - ->see('Permission') - ->see('Operation log') - ->see('Menu'); - } - - public function testLogout() - { - $this->visit('admin/auth/logout') - ->seePageIs('admin/auth/login') - ->dontSeeIsAuthenticated('admin'); - } -} + ->see('laravel/framework'); + + $this + ->see('Admin') + ->see('Users') + ->see('Roles') + ->see('Permission') + ->see('Operation log') + ->see('Menu'); +}); + +test('logout', function () { + $this->visit('admin/auth/logout') + ->seePageIs('admin/auth/login') + ->dontSeeIsAuthenticated('admin'); +}); diff --git a/tests/Feature/AuthTest.php b/tests/Feature/AuthTest.php new file mode 100644 index 00000000..b3d9bbc7 --- /dev/null +++ b/tests/Feature/AuthTest.php @@ -0,0 +1 @@ +be(Administrator::first(), 'admin'); - } - - public function testFileUploadPage() - { - $this->visit('admin/files/create') - ->see('Files') - ->seeInElement('h3[class=box-title]', 'Create') - ->seeElement('input[name=file1]') - ->seeElement('input[name=file2]') - ->seeElement('input[name=file3]') - ->seeElement('input[name=file4]') - ->seeElement('input[name=file5]') - ->seeElement('input[name=file6]') +beforeEach(function () { + $this->be(Administrator::first(), 'admin'); +}); +test('file upload page', function () { + $this->visit('admin/files/create') + ->see('Files') + ->seeInElement('h3[class=box-title]', 'Create') + ->seeElement('input[name=file1]') + ->seeElement('input[name=file2]') + ->seeElement('input[name=file3]') + ->seeElement('input[name=file4]') + ->seeElement('input[name=file5]') + ->seeElement('input[name=file6]') // ->seeInElement('a[href="/admin/files"]', 'List') - ->seeInElement('button[type=reset]', 'Reset') - ->seeInElement('button[type=submit]', 'Submit'); - } - - protected function uploadFiles() - { - return $this->visit('admin/files/create') - ->attach(__DIR__.'/AuthTest.php', 'file1') - ->attach(__DIR__.'/InstallTest.php', 'file2') - ->attach(__DIR__.'/IndexTest.php', 'file3') - ->attach(__DIR__.'/LaravelTest.php', 'file4') - ->attach(__DIR__.'/routes.php', 'file5') - ->attach(__DIR__.'/migrations/2016_11_22_093148_create_test_tables.php', 'file6') - ->press('Submit'); - } - - public function testUploadFile() - { - File::cleanDirectory(public_path('uploads/files')); - - $this->uploadFiles() - ->seePageIs('admin/files'); + ->seeInElement('button[type=reset]', 'Reset') + ->seeInElement('button[type=submit]', 'Submit'); +}); +function uploadFiles() +{ + return $this->visit('admin/files/create') + ->attach(__DIR__.'/AuthTest.php', 'file1') + ->attach(__DIR__.'/InstallTest.php', 'file2') + ->attach(__DIR__.'/IndexTest.php', 'file3') + ->attach(__DIR__.'/LaravelTest.php', 'file4') + ->attach(__DIR__.'/routes.php', 'file5') + ->attach(__DIR__.'/migrations/2016_11_22_093148_create_test_tables.php', 'file6') + ->press('Submit'); +} +test('upload file', function () { + File::cleanDirectory(public_path('uploads/files')); - $this->assertEquals(FileModel::count(), 1); + uploadFiles() + ->seePageIs('admin/files'); - $where = [ - 'file1' => 'files/AuthTest.php', - 'file2' => 'files/InstallTest.php', - 'file3' => 'files/IndexTest.php', - 'file4' => 'files/LaravelTest.php', - 'file5' => 'files/routes.php', - 'file6' => 'files/2016_11_22_093148_create_test_tables.php', - ]; + expect(1)->toEqual(FileModel::count()); - $this->seeInDatabase('test_files', $where); + $where = [ + 'file1' => 'files/AuthTest.php', + 'file2' => 'files/InstallTest.php', + 'file3' => 'files/IndexTest.php', + 'file4' => 'files/LaravelTest.php', + 'file5' => 'files/routes.php', + 'file6' => 'files/2016_11_22_093148_create_test_tables.php', + ]; - $files = FileModel::first()->toArray(); + $this->seeInDatabase('test_files', $where); - foreach (range(1, 6) as $index) { - $this->assertFileExists(public_path('uploads/'.$files['file'.$index])); - } + $files = FileModel::first()->toArray(); - File::cleanDirectory(public_path('uploads/files')); + foreach (range(1, 6) as $index) { + expect(public_path('uploads/'.$files['file'.$index]))->toBeFile(); } - public function testUpdateFile() - { - File::cleanDirectory(public_path('uploads/files')); - - $this->uploadFiles(); - - $old = FileModel::first(); - - $this->visit('admin/files/1/edit') - ->see('ID') - ->see('Created At') - ->see('Updated At') - ->seeElement('input[name=file1]') - ->seeElement('input[name=file2]') - ->seeElement('input[name=file3]') - ->seeElement('input[name=file4]') - ->seeElement('input[name=file5]') - ->seeElement('input[name=file6]') + File::cleanDirectory(public_path('uploads/files')); +}); +test('update file', function () { + File::cleanDirectory(public_path('uploads/files')); + + uploadFiles(); + + $old = FileModel::first(); + + $this->visit('admin/files/1/edit') + ->see('ID') + ->see('Created At') + ->see('Updated At') + ->seeElement('input[name=file1]') + ->seeElement('input[name=file2]') + ->seeElement('input[name=file3]') + ->seeElement('input[name=file4]') + ->seeElement('input[name=file5]') + ->seeElement('input[name=file6]') // ->seeInElement('a[href="/admin/files"]', 'List') - ->seeInElement('button[type=reset]', 'Reset') - ->seeInElement('button[type=submit]', 'Submit'); + ->seeInElement('button[type=reset]', 'Reset') + ->seeInElement('button[type=submit]', 'Submit'); - $this->attach(__DIR__.'/RolesTest.php', 'file3') - ->attach(__DIR__.'/MenuTest.php', 'file4') - ->attach(__DIR__.'/TestCase.php', 'file5') - ->press('Submit'); + $this->attach(__DIR__.'/RolesTest.php', 'file3') + ->attach(__DIR__.'/MenuTest.php', 'file4') + ->attach(__DIR__.'/TestCase.php', 'file5') + ->press('Submit'); - $new = FileModel::first(); + $new = FileModel::first(); - $this->assertEquals($old->id, $new->id); - $this->assertEquals($old->file1, $new->file1); - $this->assertEquals($old->file2, $new->file2); - $this->assertEquals($old->file6, $new->file6); + expect($new->id)->toEqual($old->id); + expect($new->file1)->toEqual($old->file1); + expect($new->file2)->toEqual($old->file2); + expect($new->file6)->toEqual($old->file6); - $this->assertNotEquals($old->file3, $new->file3); - $this->assertNotEquals($old->file4, $new->file4); - $this->assertNotEquals($old->file5, $new->file5); + $this->assertNotEquals($old->file3, $new->file3); + $this->assertNotEquals($old->file4, $new->file4); + $this->assertNotEquals($old->file5, $new->file5); - File::cleanDirectory(public_path('uploads/files')); - } - - public function testDeleteFiles() - { - File::cleanDirectory(public_path('uploads/files')); - - $this->uploadFiles(); + File::cleanDirectory(public_path('uploads/files')); +}); +test('delete files', function () { + File::cleanDirectory(public_path('uploads/files')); - $this->visit('admin/files') - ->seeInElement('td', 1); + uploadFiles(); - $files = FileModel::first()->toArray(); + $this->visit('admin/files') + ->seeInElement('td', 1); - $this->delete('admin/files/1') - ->dontSeeInDatabase('test_files', ['id' => 1]); + $files = FileModel::first()->toArray(); - foreach (range(1, 6) as $index) { - $this->assertFileDoesNotExist(public_path('uploads/'.$files['file'.$index])); - } + $this->delete('admin/files/1') + ->dontSeeInDatabase('test_files', ['id' => 1]); - $this->visit('admin/files') - ->seeInElement('td', 'svg'); + foreach (range(1, 6) as $index) { + $this->assertFileDoesNotExist(public_path('uploads/'.$files['file'.$index])); } - public function testBatchDelete() - { - File::cleanDirectory(public_path('uploads/files')); + $this->visit('admin/files') + ->seeInElement('td', 'svg'); +}); +test('batch delete', function () { + File::cleanDirectory(public_path('uploads/files')); - $this->uploadFiles(); - $this->uploadFiles(); - $this->uploadFiles(); + uploadFiles(); + uploadFiles(); + uploadFiles(); - $this->visit('admin/files') - ->seeInElement('td', 1) - ->seeInElement('td', 2) - ->seeInElement('td', 3); + $this->visit('admin/files') + ->seeInElement('td', 1) + ->seeInElement('td', 2) + ->seeInElement('td', 3); - $fi = new FilesystemIterator(public_path('uploads/files'), FilesystemIterator::SKIP_DOTS); + $fi = new FilesystemIterator(public_path('uploads/files'), FilesystemIterator::SKIP_DOTS); - $this->assertEquals(iterator_count($fi), 18); + expect(18)->toEqual(iterator_count($fi)); - $this->assertEquals(FileModel::count(), 3); + expect(3)->toEqual(FileModel::count()); - $this->delete('admin/files/1,2,3'); + $this->delete('admin/files/1,2,3'); - $this->assertEquals(FileModel::count(), 0); + expect(0)->toEqual(FileModel::count()); - $this->visit('admin/files') - ->seeInElement('td', 'svg'); + $this->visit('admin/files') + ->seeInElement('td', 'svg'); - $this->assertEquals(iterator_count($fi), 0); - } -} + expect(0)->toEqual(iterator_count($fi)); +}); diff --git a/tests/ImageUploadTest.php b/tests/ImageUploadTest.php index d96f6ee7..ab6e9c6e 100644 --- a/tests/ImageUploadTest.php +++ b/tests/ImageUploadTest.php @@ -1,235 +1,211 @@ be(Administrator::first(), 'admin'); +}); +test('disable filter', function () { + $this->visit('admin/images') + ->dontSeeElement('input[name=id]'); +}); +test('image upload page', function () { + $this->visit('admin/images/create') + ->see('Images') + ->seeInElement('h3[class=box-title]', 'Create') + ->seeElement('input[name=image1]') + ->seeElement('input[name=image2]') + ->seeElement('input[name=image3]') + ->seeElement('input[name=image4]') + ->seeElement('input[name=image5]') + ->seeElement('input[name=image6]') + ->seeInElement('button[type=reset]', 'Reset') + ->seeInElement('button[type=submit]', 'Submit'); +}); +function uploadImages() { - protected function setUp(): void - { - parent::setUp(); - - $this->be(Administrator::first(), 'admin'); - } - - public function testDisableFilter() - { - $this->visit('admin/images') - ->dontSeeElement('input[name=id]'); - } - - public function testImageUploadPage() - { - $this->visit('admin/images/create') - ->see('Images') - ->seeInElement('h3[class=box-title]', 'Create') - ->seeElement('input[name=image1]') - ->seeElement('input[name=image2]') - ->seeElement('input[name=image3]') - ->seeElement('input[name=image4]') - ->seeElement('input[name=image5]') - ->seeElement('input[name=image6]') - ->seeInElement('button[type=reset]', 'Reset') - ->seeInElement('button[type=submit]', 'Submit'); - } - - protected function uploadImages() - { - return $this->visit('admin/images/create') - ->attach(__DIR__.'/assets/test.jpg', 'image1') - ->attach(__DIR__.'/assets/test.jpg', 'image2') - ->attach(__DIR__.'/assets/test.jpg', 'image3') - ->attach(__DIR__.'/assets/test.jpg', 'image4') - ->attach(__DIR__.'/assets/test.jpg', 'image5') - ->attach(__DIR__.'/assets/test.jpg', 'image6') - ->press('Submit'); - } - - public function testUploadImage() - { - File::cleanDirectory(public_path('uploads/images')); - - $this->uploadImages() - ->seePageIs('admin/images'); - - $this->assertEquals(Image::count(), 1); +// return $this->visit('admin/images/create') +// ->attach(__DIR__.'/assets/test.jpg', 'image1') +// ->attach(__DIR__.'/assets/test.jpg', 'image2') +// ->attach(__DIR__.'/assets/test.jpg', 'image3') +// ->attach(__DIR__.'/assets/test.jpg', 'image4') +// ->attach(__DIR__.'/assets/test.jpg', 'image5') +// ->attach(__DIR__.'/assets/test.jpg', 'image6') +// ->press('Submit'); +} +test('upload image', function () { + File::cleanDirectory(public_path('uploads/images')); - $this->seeInDatabase('test_images', ['image4' => 'images/renamed.jpeg']); + uploadImages() + ->seePageIs('admin/images'); - $images = Image::first()->toArray(); + expect(1)->toEqual(Image::count()); - foreach (range(1, 6) as $index) { - $this->assertFileExists(public_path('uploads/'.$images['image'.$index])); - } + $this->seeInDatabase('test_images', ['image4' => 'images/renamed.jpeg']); - $this->assertFileExists(public_path('uploads/images/asdasdasdasdasd.jpeg')); + $images = Image::first()->toArray(); - File::cleanDirectory(public_path('uploads/images')); + foreach (range(1, 6) as $index) { + expect(public_path('uploads/'.$images['image'.$index]))->toBeFile(); } - public function testRemoveImage() - { - File::cleanDirectory(public_path('uploads/images')); - - $this->uploadImages(); - - $this->assertEquals($this->fileCountInImageDir(), 6); - } + expect(public_path('uploads/images/asdasdasdasdasd.jpeg'))->toBeFile(); - public function testUpdateImage() - { - File::cleanDirectory(public_path('uploads/images')); + File::cleanDirectory(public_path('uploads/images')); +}); +test('remove image', function () { + File::cleanDirectory(public_path('uploads/images')); - $this->uploadImages(); + uploadImages(); - $old = Image::first(); + expect(6)->toEqual(fileCountInImageDir()); +}); +test('update image', function () { + File::cleanDirectory(public_path('uploads/images')); - $this->visit('admin/images/1/edit') - ->see('ID') - ->see('Created At') - ->see('Updated At') - ->seeElement('input[name=image1]') - ->seeElement('input[name=image2]') - ->seeElement('input[name=image3]') - ->seeElement('input[name=image4]') - ->seeElement('input[name=image5]') - ->seeElement('input[name=image6]') - ->seeInElement('button[type=reset]', 'Reset') - ->seeInElement('button[type=submit]', 'Submit'); + uploadImages(); - $this->attach(__DIR__.'/assets/test.jpg', 'image3') - ->attach(__DIR__.'/assets/test.jpg', 'image4') - ->attach(__DIR__.'/assets/test.jpg', 'image5') - ->press('Submit'); + $old = Image::first(); - $new = Image::first(); + $this->visit('admin/images/1/edit') + ->see('ID') + ->see('Created At') + ->see('Updated At') + ->seeElement('input[name=image1]') + ->seeElement('input[name=image2]') + ->seeElement('input[name=image3]') + ->seeElement('input[name=image4]') + ->seeElement('input[name=image5]') + ->seeElement('input[name=image6]') + ->seeInElement('button[type=reset]', 'Reset') + ->seeInElement('button[type=submit]', 'Submit'); - $this->assertEquals($old->id, $new->id); - $this->assertEquals($old->image1, $new->image1); - $this->assertEquals($old->image2, $new->image2); - $this->assertEquals($old->image6, $new->image6); + $this->attach(__DIR__.'/assets/test.jpg', 'image3') + ->attach(__DIR__.'/assets/test.jpg', 'image4') + ->attach(__DIR__.'/assets/test.jpg', 'image5') + ->press('Submit'); - $this->assertNotEquals($old->image3, $new->image3); - $this->assertNotEquals($old->image4, $new->image4); - $this->assertNotEquals($old->image5, $new->image5); + $new = Image::first(); - File::cleanDirectory(public_path('uploads/images')); - } + expect($new->id)->toEqual($old->id); + expect($new->image1)->toEqual($old->image1); + expect($new->image2)->toEqual($old->image2); + expect($new->image6)->toEqual($old->image6); - public function testDeleteImages() - { - File::cleanDirectory(public_path('uploads/images')); + $this->assertNotEquals($old->image3, $new->image3); + $this->assertNotEquals($old->image4, $new->image4); + $this->assertNotEquals($old->image5, $new->image5); - $this->uploadImages(); + File::cleanDirectory(public_path('uploads/images')); +}); +test('delete images', function () { + File::cleanDirectory(public_path('uploads/images')); - $this->visit('admin/images') - ->seeInElement('td', 1); + uploadImages(); - $images = Image::first()->toArray(); + $this->visit('admin/images') + ->seeInElement('td', 1); - $this->delete('admin/images/1') - ->dontSeeInDatabase('test_images', ['id' => 1]); + $images = Image::first()->toArray(); - foreach (range(1, 6) as $index) { - $this->assertFileDoesNotExist(public_path('uploads/'.$images['image'.$index])); - } + $this->delete('admin/images/1') + ->dontSeeInDatabase('test_images', ['id' => 1]); - $this->visit('admin/images') - ->seeInElement('td', 'svg'); + foreach (range(1, 6) as $index) { + $this->assertFileDoesNotExist(public_path('uploads/'.$images['image'.$index])); } - public function testBatchDelete() - { - File::cleanDirectory(public_path('uploads/images')); - - $this->uploadImages(); - $this->uploadImages(); - $this->uploadImages(); + $this->visit('admin/images') + ->seeInElement('td', 'svg'); +}); +test('batch delete', function () { + File::cleanDirectory(public_path('uploads/images')); - $this->visit('admin/images') - ->seeInElement('td', 1) - ->seeInElement('td', 2) - ->seeInElement('td', 3); + uploadImages(); + uploadImages(); + uploadImages(); - $this->assertEquals($this->fileCountInImageDir(), 18); + $this->visit('admin/images') + ->seeInElement('td', 1) + ->seeInElement('td', 2) + ->seeInElement('td', 3); - $this->assertEquals(Image::count(), 3); + expect(18)->toEqual(fileCountInImageDir()); - $this->delete('admin/images/1,2,3'); + expect(3)->toEqual(Image::count()); - $this->assertEquals(Image::count(), 0); + $this->delete('admin/images/1,2,3'); - $this->visit('admin/images') - ->seeInElement('td', 'svg'); + expect(0)->toEqual(Image::count()); - $this->assertEquals($this->fileCountInImageDir(), 0); - } + $this->visit('admin/images') + ->seeInElement('td', 'svg'); - public function testUploadMultipleImage() - { - File::cleanDirectory(public_path('uploads/images')); + expect(0)->toEqual(fileCountInImageDir()); +}); +test('upload multiple image', function () { + File::cleanDirectory(public_path('uploads/images')); - $this->visit('admin/multiple-images/create') - ->seeElement('input[type=file][name="pictures[]"][multiple]'); + $this->visit('admin/multiple-images/create') + ->seeElement('input[type=file][name="pictures[]"][multiple]'); - $path = __DIR__.'/assets/test.jpg'; + $path = __DIR__.'/assets/test.jpg'; - $file = new \Illuminate\Http\UploadedFile($path, 'test.jpg', 'image/jpeg', null, true); + $file = new \Illuminate\Http\UploadedFile($path, 'test.jpg', 'image/jpeg', null, true); - $size = rand(10, 20); - $files = ['pictures' => array_pad([], $size, $file)]; + $size = rand(10, 20); + $files = ['pictures' => array_pad([], $size, $file)]; - $this->call( - 'POST', // $method - '/admin/multiple-images', // $action - [], // $parameters - [], - $files - ); + $this->call( + 'POST', // $method + '/admin/multiple-images', // $action + [], // $parameters + [], + $files + ); - $this->assertResponseStatus(302); - $this->assertRedirectedTo('/admin/multiple-images'); + $this->assertResponseStatus(302); + $this->assertRedirectedTo('/admin/multiple-images'); - $this->assertEquals($this->fileCountInImageDir(), $size); + expect($size)->toEqual(fileCountInImageDir()); - $pictures = MultipleImage::first()->pictures; + $pictures = MultipleImage::first()->pictures; - $this->assertCount($size, $pictures); + expect($pictures)->toHaveCount($size); - foreach ($pictures as $picture) { - $this->assertFileExists(public_path('uploads/'.$picture)); - } + foreach ($pictures as $picture) { + expect(public_path('uploads/'.$picture))->toBeFile(); } +}); +test('remove multiple files', function () { + File::cleanDirectory(public_path('uploads/images')); - public function testRemoveMultipleFiles() - { - File::cleanDirectory(public_path('uploads/images')); - - // upload files - $path = __DIR__.'/assets/test.jpg'; - - $file = new \Illuminate\Http\UploadedFile($path, 'test.jpg', 'image/jpeg', null, true); + // upload files + $path = __DIR__.'/assets/test.jpg'; - $size = rand(10, 20); - $files = ['pictures' => array_pad([], $size, $file)]; + $file = new \Illuminate\Http\UploadedFile($path, 'test.jpg', 'image/jpeg', null, true); - $this->call( - 'POST', // $method - '/admin/multiple-images', // $action - [], // $parameters - [], - $files - ); + $size = rand(10, 20); + $files = ['pictures' => array_pad([], $size, $file)]; - $this->assertEquals($this->fileCountInImageDir(), $size); - } + $this->call( + 'POST', // $method + '/admin/multiple-images', // $action + [], // $parameters + [], + $files + ); - protected function fileCountInImageDir($dir = 'uploads/images') - { - $file = new FilesystemIterator(public_path($dir), FilesystemIterator::SKIP_DOTS); + expect($size)->toEqual(fileCountInImageDir()); +}); +function fileCountInImageDir($dir = 'uploads/images') +{ + $file = new FilesystemIterator(public_path($dir), FilesystemIterator::SKIP_DOTS); - return iterator_count($file); - } + return iterator_count($file); } diff --git a/tests/IndexTest.php b/tests/IndexTest.php index 6ff03b04..1406ceee 100644 --- a/tests/IndexTest.php +++ b/tests/IndexTest.php @@ -1,49 +1,39 @@ be(Administrator::first(), 'admin'); - } - - public function testIndex() - { - $this->visit('admin/') - ->see('Dashboard') - ->see('Description...') - - ->see('Environment') - ->see('PHP version') - ->see('Laravel version') - - ->see('Available extensions') - ->seeLink('open-admin-ext/helpers', 'https://github.com/open-admin-extensions/helpers') - ->seeLink('open-admin-ext/backup', 'https://github.com/open-admin-extensions/backup') - ->seeLink('open-admin-ext/media-manager', 'https://github.com/open-admin-extensions/media-manager') - - ->see('Dependencies') - ->see('php') +uses(\TestCase::class); +use Encore\Admin\Auth\Database\Administrator; +beforeEach(function () { + $this->be(Administrator::first(), 'admin'); +}); +test('index', function () { + $this->visit('admin/') + ->see('Dashboard') + ->see('Description...') + + ->see('Environment') + ->see('PHP version') + ->see('Laravel version') + + ->see('Available extensions') + ->seeLink('laravel-admin-ext/helpers', 'https://github.com/laravel-admin-extensions/helpers') + ->seeLink('laravel-admin-ext/backup', 'https://github.com/laravel-admin-extensions/backup') + ->seeLink('laravel-admin-ext/media-manager', 'https://github.com/laravel-admin-extensions/media-manager') + + ->see('Dependencies') + ->see('php') // ->see('>=7.0.0') - ->see('laravel/framework'); - } - - public function testClickMenu() - { - $this->visit('admin/') - ->click('Users') - ->seePageis('admin/auth/users') - ->click('Roles') - ->seePageis('admin/auth/roles') - ->click('Permission') - ->seePageis('admin/auth/permissions') - ->click('Menu') - ->seePageis('admin/auth/menu') - ->click('Operation log') - ->seePageis('admin/auth/logs'); - } -} + ->see('laravel/framework'); +}); +test('click menu', function () { + $this->visit('admin/') + ->click('Users') + ->seePageis('admin/auth/users') + ->click('Roles') + ->seePageis('admin/auth/roles') + ->click('Permission') + ->seePageis('admin/auth/permissions') + ->click('Menu') + ->seePageis('admin/auth/menu') + ->click('Operation log') + ->seePageis('admin/auth/logs'); +}); diff --git a/tests/InstallTest.php b/tests/InstallTest.php index ec451562..f21427ea 100644 --- a/tests/InstallTest.php +++ b/tests/InstallTest.php @@ -1,25 +1,22 @@ assertFileExists(admin_path()); +uses(\TestCase::class); +test('installed directories', function () { + expect(admin_path())->toBeFile(); - $this->assertFileExists(admin_path('Controllers')); + expect(admin_path('Controllers'))->toBeFile(); - $this->assertFileExists(admin_path('routes.php')); + expect(admin_path('routes.php'))->toBeFile(); - $this->assertFileExists(admin_path('bootstrap.php')); + expect(admin_path('bootstrap.php'))->toBeFile(); - $this->assertFileExists(admin_path('Controllers/HomeController.php')); + expect(admin_path('Controllers/HomeController.php'))->toBeFile(); - $this->assertFileExists(admin_path('Controllers/AuthController.php')); + expect(admin_path('Controllers/AuthController.php'))->toBeFile(); - $this->assertFileExists(admin_path('Controllers/ExampleController.php')); + expect(admin_path('Controllers/ExampleController.php'))->toBeFile(); - $this->assertFileExists(config_path('admin.php')); + expect(config_path('admin.php'))->toBeFile(); - $this->assertFileExists(public_path('vendor/open-admin')); - } -} + expect(public_path('vendor/laravel-admin'))->toBeFile(); +}); diff --git a/tests/LaravelTest.php b/tests/LaravelTest.php index 541521c9..42f58b11 100644 --- a/tests/LaravelTest.php +++ b/tests/LaravelTest.php @@ -1,11 +1,8 @@ visit('/') - ->assertResponseStatus(200) - ->see('Laravel'); - } -} +uses(\TestCase::class); +test('laravel', function () { + $this->visit('/') + ->assertResponseStatus(200) + ->see('Laravel'); +}); diff --git a/tests/MenuTest.php b/tests/MenuTest.php index e78675a1..482aa2ba 100644 --- a/tests/MenuTest.php +++ b/tests/MenuTest.php @@ -1,76 +1,58 @@ be(Administrator::first(), 'admin'); - } - - public function testMenuIndex() - { - $this->visit('admin/auth/menu') - ->see('Menu') - ->see('Index') - ->see('Auth') - ->see('Users') - ->see('Roles') - ->see('Permission') - ->see('Menu'); - } - - public function testAddMenu() - { - $item = ['parent_id' => '0', 'title' => 'Test', 'uri' => 'test']; - - $this->visit('admin/auth/menu') - ->seePageIs('admin/auth/menu') - ->see('Menu') - ->submitForm('Submit', $item) - ->seePageIs('admin/auth/menu') - ->seeInDatabase(config('admin.database.menu_table'), $item) - ->assertEquals(8, Menu::count()); - -// $this->expectException(\Laravel\BrowserKitTesting\HttpException::class); -// -// $this->visit('admin') -// ->see('Test') -// ->click('Test'); - } - - public function testDeleteMenu() - { - $this->delete('admin/auth/menu/8') - ->assertEquals(7, Menu::count()); - } - - public function testEditMenu() - { - $this->visit('admin/auth/menu/1/edit') - ->see('Menu') - ->submitForm('Submit', ['title' => 'blablabla']) - ->seePageIs('admin/auth/menu') - ->seeInDatabase(config('admin.database.menu_table'), ['title' => 'blablabla']) - ->assertEquals(7, Menu::count()); - } - - public function testShowPage() - { - $this->visit('admin/auth/menu/1/edit') - ->seePageIs('admin/auth/menu/1/edit'); - } - - public function testEditMenuParent() - { - $this->expectException(\Laravel\BrowserKitTesting\HttpException::class); - - $this->visit('admin/auth/menu/5/edit') - ->see('Menu') - ->submitForm('Submit', ['parent_id' => 5]); - } -} +uses(\TestCase::class); +use Encore\Admin\Auth\Database\Administrator; +use Encore\Admin\Auth\Database\Menu; +beforeEach(function () { + $this->be(Administrator::first(), 'admin'); +}); +test('menu index', function () { + $this->visit('admin/auth/menu') + ->see('Menu') + ->see('Index') + ->see('Auth') + ->see('Users') + ->see('Roles') + ->see('Permission') + ->see('Menu'); +}); +test('add menu', function () { + $item = ['parent_id' => '0', 'title' => 'Test', 'uri' => 'test']; + + $this->visit('admin/auth/menu') + ->seePageIs('admin/auth/menu') + ->see('Menu') + ->submitForm('Submit', $item) + ->seePageIs('admin/auth/menu') + ->seeInDatabase(config('admin.database.menu_table'), $item) + ->assertEquals(8, Menu::count()); + + // $this->expectException(\Laravel\BrowserKitTesting\HttpException::class); + // + // $this->visit('admin') + // ->see('Test') + // ->click('Test'); +}); +test('delete menu', function () { + $this->delete('admin/auth/menu/8') + ->assertEquals(7, Menu::count()); +}); +test('edit menu', function () { + $this->visit('admin/auth/menu/1/edit') + ->see('Menu') + ->submitForm('Submit', ['title' => 'blablabla']) + ->seePageIs('admin/auth/menu') + ->seeInDatabase(config('admin.database.menu_table'), ['title' => 'blablabla']) + ->assertEquals(7, Menu::count()); +}); +test('show page', function () { + $this->visit('admin/auth/menu/1/edit') + ->seePageIs('admin/auth/menu/1/edit'); +}); +test('edit menu parent', function () { + $this->expectException(\Laravel\BrowserKitTesting\HttpException::class); + + $this->visit('admin/auth/menu/5/edit') + ->see('Menu') + ->submitForm('Submit', ['parent_id' => 5]); +}); diff --git a/tests/ModelTreeTest.php b/tests/ModelTreeTest.php index 0bed689b..2c35e653 100644 --- a/tests/ModelTreeTest.php +++ b/tests/ModelTreeTest.php @@ -1,25 +1,18 @@ where('uri', ''); + }, $rootText); - public function testSelectOptions() - { - $rootText = 'Root Text'; + $count = Tree::query()->where('uri', '')->count(); - $options = Tree::selectOptions(function ($query) { - return $query->where('uri', ''); - }, $rootText); - - $count = Tree::query()->where('uri', '')->count(); - - $this->assertEquals(array_shift($options), $rootText); - $this->assertEquals(count($options), $count); - } -} + expect($rootText)->toEqual(array_shift($options)); + expect($count)->toEqual(count($options)); +}); diff --git a/tests/OperationLogTest.php b/tests/OperationLogTest.php index 738a00b7..8c0530b1 100644 --- a/tests/OperationLogTest.php +++ b/tests/OperationLogTest.php @@ -1,84 +1,70 @@ be(Administrator::first(), 'admin'); - } - - public function testOperationLogIndex() - { - $this->visit('admin/auth/logs') - ->see('Operation log') - ->see('List') - ->see('GET') - ->see('admin/auth/logs'); - } - - public function testGenerateLogs() - { - $table = config('admin.database.operation_log_table'); - - $this->visit('admin/auth/menu') - ->seePageIs('admin/auth/menu') - ->visit('admin/auth/users') - ->seePageIs('admin/auth/users') - ->visit('admin/auth/permissions') - ->seePageIs('admin/auth/permissions') - ->visit('admin/auth/roles') - ->seePageIs('admin/auth/roles') - ->visit('admin/auth/logs') - ->seePageIs('admin/auth/logs') - ->seeInDatabase($table, ['path' => 'admin/auth/menu', 'method' => 'GET']) - ->seeInDatabase($table, ['path' => 'admin/auth/users', 'method' => 'GET']) - ->seeInDatabase($table, ['path' => 'admin/auth/permissions', 'method' => 'GET']) - ->seeInDatabase($table, ['path' => 'admin/auth/roles', 'method' => 'GET']); - - $this->assertEquals(4, OperationLog::count()); - } - - public function testDeleteLogs() - { - $table = config('admin.database.operation_log_table'); - - $this->visit('admin/auth/logs') - ->seePageIs('admin/auth/logs') - ->assertEquals(0, OperationLog::count()); - - $this->visit('admin/auth/users'); - - $this->seeInDatabase($table, ['path' => 'admin/auth/users', 'method' => 'GET']); - - $this->delete('admin/auth/logs/1') - ->assertEquals(0, OperationLog::count()); - } - - public function testDeleteMultipleLogs() - { - $table = config('admin.database.operation_log_table'); - - $this->visit('admin/auth/menu') - ->visit('admin/auth/users') - ->visit('admin/auth/permissions') - ->visit('admin/auth/roles') - ->seeInDatabase($table, ['path' => 'admin/auth/menu', 'method' => 'GET']) - ->seeInDatabase($table, ['path' => 'admin/auth/users', 'method' => 'GET']) - ->seeInDatabase($table, ['path' => 'admin/auth/permissions', 'method' => 'GET']) - ->seeInDatabase($table, ['path' => 'admin/auth/roles', 'method' => 'GET']) - ->assertEquals(4, OperationLog::count()); - - $this->delete('admin/auth/logs/1,2,3,4') - ->notSeeInDatabase($table, ['path' => 'admin/auth/menu', 'method' => 'GET']) - ->notSeeInDatabase($table, ['path' => 'admin/auth/users', 'method' => 'GET']) - ->notSeeInDatabase($table, ['path' => 'admin/auth/permissions', 'method' => 'GET']) - ->notSeeInDatabase($table, ['path' => 'admin/auth/roles', 'method' => 'GET']) - - ->assertEquals(0, OperationLog::count()); - } -} +uses(\TestCase::class); +use Encore\Admin\Auth\Database\Administrator; +use Encore\Admin\Auth\Database\OperationLog; +beforeEach(function () { + $this->be(Administrator::first(), 'admin'); +}); +test('operation log index', function () { + $this->visit('admin/auth/logs') + ->see('Operation log') + ->see('List') + ->see('GET') + ->see('admin/auth/logs'); +}); +test('generate logs', function () { + $table = config('admin.database.operation_log_table'); + + $this->visit('admin/auth/menu') + ->seePageIs('admin/auth/menu') + ->visit('admin/auth/users') + ->seePageIs('admin/auth/users') + ->visit('admin/auth/permissions') + ->seePageIs('admin/auth/permissions') + ->visit('admin/auth/roles') + ->seePageIs('admin/auth/roles') + ->visit('admin/auth/logs') + ->seePageIs('admin/auth/logs') + ->seeInDatabase($table, ['path' => 'admin/auth/menu', 'method' => 'GET']) + ->seeInDatabase($table, ['path' => 'admin/auth/users', 'method' => 'GET']) + ->seeInDatabase($table, ['path' => 'admin/auth/permissions', 'method' => 'GET']) + ->seeInDatabase($table, ['path' => 'admin/auth/roles', 'method' => 'GET']); + + expect(OperationLog::count())->toEqual(4); +}); +test('delete logs', function () { + $table = config('admin.database.operation_log_table'); + + $this->visit('admin/auth/logs') + ->seePageIs('admin/auth/logs') + ->assertEquals(0, OperationLog::count()); + + $this->visit('admin/auth/users'); + + $this->seeInDatabase($table, ['path' => 'admin/auth/users', 'method' => 'GET']); + + $this->delete('admin/auth/logs/1') + ->assertEquals(0, OperationLog::count()); +}); +test('delete multiple logs', function () { + $table = config('admin.database.operation_log_table'); + + $this->visit('admin/auth/menu') + ->visit('admin/auth/users') + ->visit('admin/auth/permissions') + ->visit('admin/auth/roles') + ->seeInDatabase($table, ['path' => 'admin/auth/menu', 'method' => 'GET']) + ->seeInDatabase($table, ['path' => 'admin/auth/users', 'method' => 'GET']) + ->seeInDatabase($table, ['path' => 'admin/auth/permissions', 'method' => 'GET']) + ->seeInDatabase($table, ['path' => 'admin/auth/roles', 'method' => 'GET']) + ->assertEquals(4, OperationLog::count()); + + $this->delete('admin/auth/logs/1,2,3,4') + ->notSeeInDatabase($table, ['path' => 'admin/auth/menu', 'method' => 'GET']) + ->notSeeInDatabase($table, ['path' => 'admin/auth/users', 'method' => 'GET']) + ->notSeeInDatabase($table, ['path' => 'admin/auth/permissions', 'method' => 'GET']) + ->notSeeInDatabase($table, ['path' => 'admin/auth/roles', 'method' => 'GET']) + + ->assertEquals(0, OperationLog::count()); +}); diff --git a/tests/PermissionsTest.php b/tests/PermissionsTest.php index e31b4724..90db02a2 100644 --- a/tests/PermissionsTest.php +++ b/tests/PermissionsTest.php @@ -1,214 +1,194 @@ be(Administrator::first(), 'admin'); - } - - public function testPermissionsIndex() - { - $this->assertTrue(Administrator::first()->isAdministrator()); - - $this->visit('admin/auth/permissions') - ->see('Permissions'); - } - - public function testAddAndDeletePermissions() - { - $this->visit('admin/auth/permissions/create') - ->see('Permissions') - ->submitForm('Submit', ['slug' => 'can-edit', 'name' => 'Can edit', 'http_path' => 'users/1/edit', 'http_method' => ['GET']]) - ->seePageIs('admin/auth/permissions') - ->visit('admin/auth/permissions/create') - ->see('Permissions') - ->submitForm('Submit', ['slug' => 'can-delete', 'name' => 'Can delete', 'http_path' => 'users/1', 'http_method' => ['DELETE']]) - ->seePageIs('admin/auth/permissions') - ->seeInDatabase(config('admin.database.permissions_table'), ['slug' => 'can-edit', 'name' => 'Can edit', 'http_path' => 'users/1/edit', 'http_method' => 'GET']) - ->seeInDatabase(config('admin.database.permissions_table'), ['slug' => 'can-delete', 'name' => 'Can delete', 'http_path' => 'users/1', 'http_method' => 'DELETE']) - ->assertEquals(7, Permission::count()); - - $this->assertTrue(Administrator::first()->can('can-edit')); - $this->assertTrue(Administrator::first()->can('can-delete')); - - $this->delete('admin/auth/permissions/6') - ->assertEquals(6, Permission::count()); - - $this->delete('admin/auth/permissions/7') - ->assertEquals(5, Permission::count()); - } - - public function testAddPermissionToRole() - { - $this->visit('admin/auth/permissions/create') - ->see('Permissions') - ->submitForm('Submit', ['slug' => 'can-create', 'name' => 'Can Create', 'http_path' => 'users/create', 'http_method' => ['GET']]) - ->seePageIs('admin/auth/permissions'); - - $this->assertEquals(6, Permission::count()); - - $this->visit('admin/auth/roles/1/edit') - ->see('Edit') - ->submitForm('Submit', ['permissions' => [1]]) - ->seePageIs('admin/auth/roles') - ->seeInDatabase(config('admin.database.role_permissions_table'), ['role_id' => 1, 'permission_id' => 1]); - } - - public function testAddPermissionToUser() - { - $this->visit('admin/auth/permissions/create') - ->see('Permissions') - ->submitForm('Submit', ['slug' => 'can-create', 'name' => 'Can Create', 'http_path' => 'users/create', 'http_method' => ['GET']]) - ->seePageIs('admin/auth/permissions'); - - $this->assertEquals(6, Permission::count()); - - $this->visit('admin/auth/users/1/edit') - ->see('Edit') - ->submitForm('Submit', ['permissions' => [1], 'roles' => [1]]) - ->seePageIs('admin/auth/users') - ->seeInDatabase(config('admin.database.user_permissions_table'), ['user_id' => 1, 'permission_id' => 1]) - ->seeInDatabase(config('admin.database.role_users_table'), ['user_id' => 1, 'role_id' => 1]); - } - - public function testAddUserAndAssignPermission() - { - $user = [ - 'username' => 'Test', - 'name' => 'Name', - 'password' => '123456', - 'password_confirmation' => '123456', - ]; - - $this->visit('admin/auth/users/create') - ->see('Create') - ->submitForm('Submit', $user) - ->seePageIs('admin/auth/users') - ->seeInDatabase(config('admin.database.users_table'), ['username' => 'Test']); - - $this->assertFalse(Administrator::find(2)->isAdministrator()); - - $this->visit('admin/auth/permissions/create') - ->see('Permissions') - ->submitForm('Submit', ['slug' => 'can-update', 'name' => 'Can Update', 'http_path' => 'users/*/edit', 'http_method' => ['GET']]) - ->seePageIs('admin/auth/permissions'); - - $this->assertEquals(6, Permission::count()); - - $this->visit('admin/auth/permissions/create') - ->see('Permissions') - ->submitForm('Submit', ['slug' => 'can-remove', 'name' => 'Can Remove', 'http_path' => 'users/*', 'http_method' => ['DELETE']]) - ->seePageIs('admin/auth/permissions'); - - $this->assertEquals(7, Permission::count()); - - $this->visit('admin/auth/users/2/edit') - ->see('Edit') - ->submitForm('Submit', ['permissions' => [6]]) - ->seePageIs('admin/auth/users') - ->seeInDatabase(config('admin.database.user_permissions_table'), ['user_id' => 2, 'permission_id' => 6]); - - $this->assertTrue(Administrator::find(2)->can('can-update')); - $this->assertTrue(Administrator::find(2)->cannot('can-remove')); - - $this->visit('admin/auth/users/2/edit') - ->see('Edit') - ->submitForm('Submit', ['permissions' => [7]]) - ->seePageIs('admin/auth/users') - ->seeInDatabase(config('admin.database.user_permissions_table'), ['user_id' => 2, 'permission_id' => 7]); - - $this->assertTrue(Administrator::find(2)->can('can-remove')); - - $this->visit('admin/auth/users/2/edit') - ->see('Edit') - ->submitForm('Submit', ['permissions' => []]) - ->seePageIs('admin/auth/users') - ->missingFromDatabase(config('admin.database.user_permissions_table'), ['user_id' => 2, 'permission_id' => 6]) - ->missingFromDatabase(config('admin.database.user_permissions_table'), ['user_id' => 2, 'permission_id' => 7]); - - $this->assertTrue(Administrator::find(2)->cannot('can-update')); - $this->assertTrue(Administrator::find(2)->cannot('can-remove')); - } - - public function testPermissionThroughRole() - { - $user = [ - 'username' => 'Test', - 'name' => 'Name', - 'password' => '123456', - 'password_confirmation' => '123456', - ]; - - // 1.add a user - $this->visit('admin/auth/users/create') - ->see('Create') - ->submitForm('Submit', $user) - ->seePageIs('admin/auth/users') - ->seeInDatabase(config('admin.database.users_table'), ['username' => 'Test']); - - $this->assertFalse(Administrator::find(2)->isAdministrator()); - - // 2.add a role - $this->visit('admin/auth/roles/create') - ->see('Roles') - ->submitForm('Submit', ['slug' => 'developer', 'name' => 'Developer...']) - ->seePageIs('admin/auth/roles') - ->seeInDatabase(config('admin.database.roles_table'), ['slug' => 'developer', 'name' => 'Developer...']) - ->assertEquals(2, Role::count()); - - $this->assertFalse(Administrator::find(2)->isRole('developer')); - - // 3.assign role to user - $this->visit('admin/auth/users/2/edit') - ->see('Edit') - ->submitForm('Submit', ['roles' => [2]]) - ->seePageIs('admin/auth/users') - ->seeInDatabase(config('admin.database.role_users_table'), ['user_id' => 2, 'role_id' => 2]); - - $this->assertTrue(Administrator::find(2)->isRole('developer')); - - // 4.add a permission - $this->visit('admin/auth/permissions/create') - ->see('Permissions') - ->submitForm('Submit', ['slug' => 'can-remove', 'name' => 'Can Remove', 'http_path' => 'users/*', 'http_method' => ['DELETE']]) - ->seePageIs('admin/auth/permissions'); - - $this->assertEquals(6, Permission::count()); - - $this->assertTrue(Administrator::find(2)->cannot('can-remove')); - - // 5.assign permission to role - $this->visit('admin/auth/roles/2/edit') - ->see('Edit') - ->submitForm('Submit', ['permissions' => [6]]) - ->seePageIs('admin/auth/roles') - ->seeInDatabase(config('admin.database.role_permissions_table'), ['role_id' => 2, 'permission_id' => 6]); - - $this->assertTrue(Administrator::find(2)->can('can-remove')); - } - - public function testEditPermission() - { - $this->visit('admin/auth/permissions/create') - ->see('Permissions') - ->submitForm('Submit', ['slug' => 'can-edit', 'name' => 'Can edit', 'http_path' => 'users/1/edit', 'http_method' => ['GET']]) - ->seePageIs('admin/auth/permissions') - ->seeInDatabase(config('admin.database.permissions_table'), ['slug' => 'can-edit']) - ->seeInDatabase(config('admin.database.permissions_table'), ['name' => 'Can edit']) - ->assertEquals(6, Permission::count()); - - $this->visit('admin/auth/permissions/1/edit') - ->see('Permissions') - ->submitForm('Submit', ['slug' => 'can-delete']) - ->seePageIs('admin/auth/permissions') - ->seeInDatabase(config('admin.database.permissions_table'), ['slug' => 'can-delete']) - ->assertEquals(6, Permission::count()); - } -} +uses(\TestCase::class); +use Encore\Admin\Auth\Database\Administrator; +use Encore\Admin\Auth\Database\Permission; +use Encore\Admin\Auth\Database\Role; +beforeEach(function () { + $this->be(Administrator::first(), 'admin'); +}); +test('permissions index', function () { + expect(Administrator::first()->isAdministrator())->toBeTrue(); + + $this->visit('admin/auth/permissions') + ->see('Permissions'); +}); +test('add and delete permissions', function () { + $this->visit('admin/auth/permissions/create') + ->see('Permissions') + ->submitForm('Submit', ['slug' => 'can-edit', 'name' => 'Can edit', 'http_path' => 'users/1/edit', 'http_method' => ['GET']]) + ->seePageIs('admin/auth/permissions') + ->visit('admin/auth/permissions/create') + ->see('Permissions') + ->submitForm('Submit', ['slug' => 'can-delete', 'name' => 'Can delete', 'http_path' => 'users/1', 'http_method' => ['DELETE']]) + ->seePageIs('admin/auth/permissions') + ->seeInDatabase(config('admin.database.permissions_table'), ['slug' => 'can-edit', 'name' => 'Can edit', 'http_path' => 'users/1/edit', 'http_method' => 'GET']) + ->seeInDatabase(config('admin.database.permissions_table'), ['slug' => 'can-delete', 'name' => 'Can delete', 'http_path' => 'users/1', 'http_method' => 'DELETE']) + ->assertEquals(7, Permission::count()); + + expect(Administrator::first()->can('can-edit'))->toBeTrue(); + expect(Administrator::first()->can('can-delete'))->toBeTrue(); + + $this->delete('admin/auth/permissions/6') + ->assertEquals(6, Permission::count()); + + $this->delete('admin/auth/permissions/7') + ->assertEquals(5, Permission::count()); +}); +test('add permission to role', function () { + $this->visit('admin/auth/permissions/create') + ->see('Permissions') + ->submitForm('Submit', ['slug' => 'can-create', 'name' => 'Can Create', 'http_path' => 'users/create', 'http_method' => ['GET']]) + ->seePageIs('admin/auth/permissions'); + + expect(Permission::count())->toEqual(6); + + $this->visit('admin/auth/roles/1/edit') + ->see('Edit') + ->submitForm('Submit', ['permissions' => [1]]) + ->seePageIs('admin/auth/roles') + ->seeInDatabase(config('admin.database.role_permissions_table'), ['role_id' => 1, 'permission_id' => 1]); +}); +test('add permission to user', function () { + $this->visit('admin/auth/permissions/create') + ->see('Permissions') + ->submitForm('Submit', ['slug' => 'can-create', 'name' => 'Can Create', 'http_path' => 'users/create', 'http_method' => ['GET']]) + ->seePageIs('admin/auth/permissions'); + + expect(Permission::count())->toEqual(6); + + $this->visit('admin/auth/users/1/edit') + ->see('Edit') + ->submitForm('Submit', ['permissions' => [1], 'roles' => [1]]) + ->seePageIs('admin/auth/users') + ->seeInDatabase(config('admin.database.user_permissions_table'), ['user_id' => 1, 'permission_id' => 1]) + ->seeInDatabase(config('admin.database.role_users_table'), ['user_id' => 1, 'role_id' => 1]); +}); +test('add user and assign permission', function () { + $user = [ + 'username' => 'Test', + 'name' => 'Name', + 'password' => '123456', + 'password_confirmation' => '123456', + ]; + + $this->visit('admin/auth/users/create') + ->see('Create') + ->submitForm('Submit', $user) + ->seePageIs('admin/auth/users') + ->seeInDatabase(config('admin.database.users_table'), ['username' => 'Test']); + + expect(Administrator::find(2)->isAdministrator())->toBeFalse(); + + $this->visit('admin/auth/permissions/create') + ->see('Permissions') + ->submitForm('Submit', ['slug' => 'can-update', 'name' => 'Can Update', 'http_path' => 'users/*/edit', 'http_method' => ['GET']]) + ->seePageIs('admin/auth/permissions'); + + expect(Permission::count())->toEqual(6); + + $this->visit('admin/auth/permissions/create') + ->see('Permissions') + ->submitForm('Submit', ['slug' => 'can-remove', 'name' => 'Can Remove', 'http_path' => 'users/*', 'http_method' => ['DELETE']]) + ->seePageIs('admin/auth/permissions'); + + expect(Permission::count())->toEqual(7); + + $this->visit('admin/auth/users/2/edit') + ->see('Edit') + ->submitForm('Submit', ['permissions' => [6]]) + ->seePageIs('admin/auth/users') + ->seeInDatabase(config('admin.database.user_permissions_table'), ['user_id' => 2, 'permission_id' => 6]); + + expect(Administrator::find(2)->can('can-update'))->toBeTrue(); + expect(Administrator::find(2)->cannot('can-remove'))->toBeTrue(); + + $this->visit('admin/auth/users/2/edit') + ->see('Edit') + ->submitForm('Submit', ['permissions' => [7]]) + ->seePageIs('admin/auth/users') + ->seeInDatabase(config('admin.database.user_permissions_table'), ['user_id' => 2, 'permission_id' => 7]); + + expect(Administrator::find(2)->can('can-remove'))->toBeTrue(); + + $this->visit('admin/auth/users/2/edit') + ->see('Edit') + ->submitForm('Submit', ['permissions' => []]) + ->seePageIs('admin/auth/users') + ->missingFromDatabase(config('admin.database.user_permissions_table'), ['user_id' => 2, 'permission_id' => 6]) + ->missingFromDatabase(config('admin.database.user_permissions_table'), ['user_id' => 2, 'permission_id' => 7]); + + expect(Administrator::find(2)->cannot('can-update'))->toBeTrue(); + expect(Administrator::find(2)->cannot('can-remove'))->toBeTrue(); +}); +test('permission through role', function () { + $user = [ + 'username' => 'Test', + 'name' => 'Name', + 'password' => '123456', + 'password_confirmation' => '123456', + ]; + + // 1.add a user + $this->visit('admin/auth/users/create') + ->see('Create') + ->submitForm('Submit', $user) + ->seePageIs('admin/auth/users') + ->seeInDatabase(config('admin.database.users_table'), ['username' => 'Test']); + + expect(Administrator::find(2)->isAdministrator())->toBeFalse(); + + // 2.add a role + $this->visit('admin/auth/roles/create') + ->see('Roles') + ->submitForm('Submit', ['slug' => 'developer', 'name' => 'Developer...']) + ->seePageIs('admin/auth/roles') + ->seeInDatabase(config('admin.database.roles_table'), ['slug' => 'developer', 'name' => 'Developer...']) + ->assertEquals(2, Role::count()); + + expect(Administrator::find(2)->isRole('developer'))->toBeFalse(); + + // 3.assign role to user + $this->visit('admin/auth/users/2/edit') + ->see('Edit') + ->submitForm('Submit', ['roles' => [2]]) + ->seePageIs('admin/auth/users') + ->seeInDatabase(config('admin.database.role_users_table'), ['user_id' => 2, 'role_id' => 2]); + + expect(Administrator::find(2)->isRole('developer'))->toBeTrue(); + + // 4.add a permission + $this->visit('admin/auth/permissions/create') + ->see('Permissions') + ->submitForm('Submit', ['slug' => 'can-remove', 'name' => 'Can Remove', 'http_path' => 'users/*', 'http_method' => ['DELETE']]) + ->seePageIs('admin/auth/permissions'); + + expect(Permission::count())->toEqual(6); + + expect(Administrator::find(2)->cannot('can-remove'))->toBeTrue(); + + // 5.assign permission to role + $this->visit('admin/auth/roles/2/edit') + ->see('Edit') + ->submitForm('Submit', ['permissions' => [6]]) + ->seePageIs('admin/auth/roles') + ->seeInDatabase(config('admin.database.role_permissions_table'), ['role_id' => 2, 'permission_id' => 6]); + + expect(Administrator::find(2)->can('can-remove'))->toBeTrue(); +}); +test('edit permission', function () { + $this->visit('admin/auth/permissions/create') + ->see('Permissions') + ->submitForm('Submit', ['slug' => 'can-edit', 'name' => 'Can edit', 'http_path' => 'users/1/edit', 'http_method' => ['GET']]) + ->seePageIs('admin/auth/permissions') + ->seeInDatabase(config('admin.database.permissions_table'), ['slug' => 'can-edit']) + ->seeInDatabase(config('admin.database.permissions_table'), ['name' => 'Can edit']) + ->assertEquals(6, Permission::count()); + + $this->visit('admin/auth/permissions/1/edit') + ->see('Permissions') + ->submitForm('Submit', ['slug' => 'can-delete']) + ->seePageIs('admin/auth/permissions') + ->seeInDatabase(config('admin.database.permissions_table'), ['slug' => 'can-delete']) + ->assertEquals(6, Permission::count()); +}); diff --git a/tests/RolesTest.php b/tests/RolesTest.php index e3f359c0..d2b1b010 100644 --- a/tests/RolesTest.php +++ b/tests/RolesTest.php @@ -1,105 +1,89 @@ be(Administrator::first(), 'admin'); - } - - public function testRolesIndex() - { - $this->visit('admin/auth/roles') - ->see('Roles') - ->see('administrator'); - } - - public function testAddRole() - { - $this->visit('admin/auth/roles/create') - ->see('Roles') - ->submitForm('Submit', ['slug' => 'developer', 'name' => 'Developer...']) - ->seePageIs('admin/auth/roles') - ->seeInDatabase(config('admin.database.roles_table'), ['slug' => 'developer', 'name' => 'Developer...']) - ->assertEquals(2, Role::count()); - } - - public function testAddRoleToUser() - { - $user = [ - 'username' => 'Test', - 'name' => 'Name', - 'password' => '123456', - 'password_confirmation' => '123456', - - ]; - - $this->visit('admin/auth/users/create') - ->see('Create') - ->submitForm('Submit', $user) - ->seePageIs('admin/auth/users') - ->seeInDatabase(config('admin.database.users_table'), ['username' => 'Test']); - - $this->assertEquals(1, Role::count()); - - $this->visit('admin/auth/roles/create') - ->see('Roles') - ->submitForm('Submit', ['slug' => 'developer', 'name' => 'Developer...']) - ->seePageIs('admin/auth/roles') - ->seeInDatabase(config('admin.database.roles_table'), ['slug' => 'developer', 'name' => 'Developer...']) - ->assertEquals(2, Role::count()); - - $this->assertFalse(Administrator::find(2)->isRole('developer')); - - $this->visit('admin/auth/users/2/edit') - ->see('Edit') - ->submitForm('Submit', ['roles' => [2]]) - ->seePageIs('admin/auth/users') - ->seeInDatabase(config('admin.database.role_users_table'), ['user_id' => 2, 'role_id' => 2]); - - $this->assertTrue(Administrator::find(2)->isRole('developer')); - - $this->assertFalse(Administrator::find(2)->inRoles(['editor', 'operator'])); - $this->assertTrue(Administrator::find(2)->inRoles(['developer', 'operator', 'editor'])); - } - - public function testDeleteRole() - { - $this->assertEquals(1, Role::count()); - - $this->visit('admin/auth/roles/create') - ->see('Roles') - ->submitForm('Submit', ['slug' => 'developer', 'name' => 'Developer...']) - ->seePageIs('admin/auth/roles') - ->seeInDatabase(config('admin.database.roles_table'), ['slug' => 'developer', 'name' => 'Developer...']) - ->assertEquals(2, Role::count()); - - $this->delete('admin/auth/roles/2') - ->assertEquals(1, Role::count()); - - $this->delete('admin/auth/roles/1') - ->assertEquals(0, Role::count()); - } - - public function testEditRole() - { - $this->visit('admin/auth/roles/create') - ->see('Roles') - ->submitForm('Submit', ['slug' => 'developer', 'name' => 'Developer...']) - ->seePageIs('admin/auth/roles') - ->seeInDatabase(config('admin.database.roles_table'), ['slug' => 'developer', 'name' => 'Developer...']) - ->assertEquals(2, Role::count()); - - $this->visit('admin/auth/roles/2/edit') - ->see('Roles') - ->submitForm('Submit', ['name' => 'blablabla']) - ->seePageIs('admin/auth/roles') - ->seeInDatabase(config('admin.database.roles_table'), ['name' => 'blablabla']) - ->assertEquals(2, Role::count()); - } -} +uses(\TestCase::class); +use Encore\Admin\Auth\Database\Administrator; +use Encore\Admin\Auth\Database\Role; +beforeEach(function () { + $this->be(Administrator::first(), 'admin'); +}); +test('roles index', function () { + $this->visit('admin/auth/roles') + ->see('Roles') + ->see('administrator'); +}); +test('add role', function () { + $this->visit('admin/auth/roles/create') + ->see('Roles') + ->submitForm('Submit', ['slug' => 'developer', 'name' => 'Developer...']) + ->seePageIs('admin/auth/roles') + ->seeInDatabase(config('admin.database.roles_table'), ['slug' => 'developer', 'name' => 'Developer...']) + ->assertEquals(2, Role::count()); +}); +test('add role to user', function () { + $user = [ + 'username' => 'Test', + 'name' => 'Name', + 'password' => '123456', + 'password_confirmation' => '123456', + + ]; + + $this->visit('admin/auth/users/create') + ->see('Create') + ->submitForm('Submit', $user) + ->seePageIs('admin/auth/users') + ->seeInDatabase(config('admin.database.users_table'), ['username' => 'Test']); + + expect(Role::count())->toEqual(1); + + $this->visit('admin/auth/roles/create') + ->see('Roles') + ->submitForm('Submit', ['slug' => 'developer', 'name' => 'Developer...']) + ->seePageIs('admin/auth/roles') + ->seeInDatabase(config('admin.database.roles_table'), ['slug' => 'developer', 'name' => 'Developer...']) + ->assertEquals(2, Role::count()); + + expect(Administrator::find(2)->isRole('developer'))->toBeFalse(); + + $this->visit('admin/auth/users/2/edit') + ->see('Edit') + ->submitForm('Submit', ['roles' => [2]]) + ->seePageIs('admin/auth/users') + ->seeInDatabase(config('admin.database.role_users_table'), ['user_id' => 2, 'role_id' => 2]); + + expect(Administrator::find(2)->isRole('developer'))->toBeTrue(); + + expect(Administrator::find(2)->inRoles(['editor', 'operator']))->toBeFalse(); + expect(Administrator::find(2)->inRoles(['developer', 'operator', 'editor']))->toBeTrue(); +}); +test('delete role', function () { + expect(Role::count())->toEqual(1); + + $this->visit('admin/auth/roles/create') + ->see('Roles') + ->submitForm('Submit', ['slug' => 'developer', 'name' => 'Developer...']) + ->seePageIs('admin/auth/roles') + ->seeInDatabase(config('admin.database.roles_table'), ['slug' => 'developer', 'name' => 'Developer...']) + ->assertEquals(2, Role::count()); + + $this->delete('admin/auth/roles/2') + ->assertEquals(1, Role::count()); + + $this->delete('admin/auth/roles/1') + ->assertEquals(0, Role::count()); +}); +test('edit role', function () { + $this->visit('admin/auth/roles/create') + ->see('Roles') + ->submitForm('Submit', ['slug' => 'developer', 'name' => 'Developer...']) + ->seePageIs('admin/auth/roles') + ->seeInDatabase(config('admin.database.roles_table'), ['slug' => 'developer', 'name' => 'Developer...']) + ->assertEquals(2, Role::count()); + + $this->visit('admin/auth/roles/2/edit') + ->see('Roles') + ->submitForm('Submit', ['name' => 'blablabla']) + ->seePageIs('admin/auth/roles') + ->seeInDatabase(config('admin.database.roles_table'), ['name' => 'blablabla']) + ->assertEquals(2, Role::count()); +}); diff --git a/tests/TestCase.php b/tests/TestCase.php index 3d471d02..2932d4a6 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -1,98 +1,10 @@ booting(function () { - $loader = \Illuminate\Foundation\AliasLoader::getInstance(); - $loader->alias('Admin', \OpenAdmin\Admin\Facades\Admin::class); - }); - - $app->make('Illuminate\Contracts\Console\Kernel')->bootstrap(); - - $app->register('OpenAdmin\Admin\AdminServiceProvider'); - - return $app; - } - - protected function setUp(): void - { - parent::setUp(); - - $adminConfig = require __DIR__.'/config/admin.php'; - - $this->app['config']->set('database.default', env('DB_CONNECTION', 'mysql')); - $this->app['config']->set('database.connections.mysql.host', env('MYSQL_HOST', 'localhost')); - $this->app['config']->set('database.connections.mysql.database', env('MYSQL_DATABASE', 'laravel_admin_test')); - $this->app['config']->set('database.connections.mysql.username', env('MYSQL_USER', 'root')); - $this->app['config']->set('database.connections.mysql.password', env('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' => 'OpenAdmin\Admin\AdminServiceProvider']); - - Schema::defaultStringLength(191); - - $this->artisan('admin:install'); +use Illuminate\Foundation\Testing\TestCase as BaseTestCase; - $this->migrateTestTables(); - - if (file_exists($routes = admin_path('routes.php'))) { - require $routes; - } - - require __DIR__.'/routes.php'; - - require __DIR__.'/seeds/factory.php'; - -// \OpenAdmin\Admin\Admin::$css = []; -// \OpenAdmin\Admin\Admin::$js = []; -// \OpenAdmin\Admin\Admin::$script = []; - } - - protected function tearDown(): void - { - (new CreateAdminTables())->down(); - - (new CreateTestTables())->down(); - - DB::select("delete from `migrations` where `migration` = '2016_01_04_173148_create_admin_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(); - } +abstract class TestCase extends BaseTestCase +{ + use CreatesApplication; } diff --git a/tests/UserFormTest.php b/tests/UserFormTest.php index aad90758..ae9a09c6 100644 --- a/tests/UserFormTest.php +++ b/tests/UserFormTest.php @@ -1,209 +1,188 @@ be(Administrator::first(), 'admin'); +}); +test('create page', function () { + $this->visit('admin/users/create') + ->seeElement('input[type=text][name=username]') + ->seeElement('input[type=email][name=email]') + ->seeElement('input[type=text][name=mobile]') + ->seeElement('input[type=file][name=avatar]') + ->seeElement('hr') + ->seeElement("input[type=text][name='profile[first_name]']") + ->seeElement("input[type=text][name='profile[last_name]']") + ->seeElement("input[type=text][name='profile[postcode]']") + ->seeElement("textarea[name='profile[address]'][rows=15]") + ->seeElement("input[type=hidden][name='profile[latitude]']") + ->seeElement("input[type=hidden][name='profile[longitude]']") + ->seeElement("input[type=text][name='profile[color]']") + ->seeElement("input[type=text][name='profile[start_at]']") + ->seeElement("input[type=text][name='profile[end_at]']") + ->seeElement('span[class=help-block] i[class*=fa-info-circle]') + ->seeInElement('span[class=help-block]', 'Please input your postcode') + ->seeElement('span[class=help-block] i[class*=fa-image]') + ->seeInElement('span[class=help-block]', '上传头像') + ->seeElement("select[name='tags[]'][multiple=multiple]") + ->seeInElement('a[html-field]', 'html...'); +}); +test('submit form', function () { + $data = [ + 'username' => 'John Doe', + 'email' => 'hello@world.com', + 'mobile' => '13421234123', + 'password' => '123456', + 'password_confirmation' => '123456', + //"avatar" => "test.jpg", + 'profile' => [ + 'first_name' => 'John', + 'last_name' => 'Doe', + 'postcode' => '123456', + 'address' => 'Jinshajiang RD', + 'latitude' => '131.2123123456', + 'longitude' => '21.342123456', + 'color' => '#ffffff', + 'start_at' => date('Y-m-d H:i:s', time()), + 'end_at' => date('Y-m-d H:i:s', time()), + ], + ]; + + $this->visit('admin/users/create') + ->attach(__DIR__.'/assets/test.jpg', 'avatar') + + ->submitForm('Submit', $data) + ->seePageIs('admin/users') + ->seeInElement('td', 1) + ->seeInElement('td', $data['username']) + ->seeInElement('td', $data['email']) + ->seeInElement('td', $data['mobile']) + ->seeInElement('td', "{$data['profile']['first_name']} {$data['profile']['last_name']}") + ->seeElement('td img') + ->seeInElement('td', $data['profile']['postcode']) + ->seeInElement('td', $data['profile']['address']) + ->seeInElement('td', "{$data['profile']['latitude']} {$data['profile']['longitude']}") + ->seeInElement('td', $data['profile']['color']) + ->seeInElement('td', $data['profile']['start_at']) + ->seeInElement('td', $data['profile']['end_at']); + + expect(UserModel::all())->toHaveCount(1); + + $this->seeInDatabase('test_users', ['username' => $data['username']]); + $this->seeInDatabase('test_users', ['email' => $data['email']]); + $this->seeInDatabase('test_users', ['mobile' => $data['mobile']]); + $this->seeInDatabase('test_users', ['password' => $data['password']]); + + $this->seeInDatabase('test_user_profiles', ['first_name' => $data['profile']['first_name']]); + $this->seeInDatabase('test_user_profiles', ['last_name' => $data['profile']['last_name']]); + $this->seeInDatabase('test_user_profiles', ['postcode' => $data['profile']['postcode']]); + $this->seeInDatabase('test_user_profiles', ['address' => $data['profile']['address']]); + $this->seeInDatabase('test_user_profiles', ['latitude' => $data['profile']['latitude']]); + $this->seeInDatabase('test_user_profiles', ['longitude' => $data['profile']['longitude']]); + $this->seeInDatabase('test_user_profiles', ['color' => $data['profile']['color']]); + $this->seeInDatabase('test_user_profiles', ['start_at' => $data['profile']['start_at']]); + $this->seeInDatabase('test_user_profiles', ['end_at' => $data['profile']['end_at']]); + + $avatar = UserModel::first()->avatar; + + expect(public_path('uploads/'.$avatar))->toBeFile(); +}); +function seedsTable($count = 100) { - protected function setUp(): void - { - parent::setUp(); - - $this->be(Administrator::first(), 'admin'); - } - - public function testCreatePage() - { - $this->visit('admin/users/create') - ->seeElement('input[type=text][name=username]') - ->seeElement('input[type=email][name=email]') - ->seeElement('input[type=text][name=mobile]') - ->seeElement('input[type=file][name=avatar]') - ->seeElement('hr') - ->seeElement("input[type=text][name='profile[first_name]']") - ->seeElement("input[type=text][name='profile[last_name]']") - ->seeElement("input[type=text][name='profile[postcode]']") - ->seeElement("textarea[name='profile[address]'][rows=15]") - ->seeElement("input[type=hidden][name='profile[latitude]']") - ->seeElement("input[type=hidden][name='profile[longitude]']") - ->seeElement("input[type=text][name='profile[color]']") - ->seeElement("input[type=text][name='profile[start_at]']") - ->seeElement("input[type=text][name='profile[end_at]']") - ->seeElement('span[class=help-block] i[class*=fa-info-circle]') - ->seeInElement('span[class=help-block]', 'Please input your postcode') - ->seeElement('span[class=help-block] i[class*=fa-image]') - ->seeInElement('span[class=help-block]', '上传头像') - ->seeElement("select[name='tags[]'][multiple=multiple]") - ->seeInElement('a[html-field]', 'html...'); - } - - public function testSubmitForm() - { - $data = [ - 'username' => 'John Doe', - 'email' => 'hello@world.com', - 'mobile' => '13421234123', - 'password' => '123456', - 'password_confirmation' => '123456', - //"avatar" => "test.jpg", - 'profile' => [ - 'first_name' => 'John', - 'last_name' => 'Doe', - 'postcode' => '123456', - 'address' => 'Jinshajiang RD', - 'latitude' => '131.2123123456', - 'longitude' => '21.342123456', - 'color' => '#ffffff', - 'start_at' => date('Y-m-d H:i:s', time()), - 'end_at' => date('Y-m-d H:i:s', time()), - ], - ]; - - $this->visit('admin/users/create') - ->attach(__DIR__.'/assets/test.jpg', 'avatar') - - ->submitForm('Submit', $data) - ->seePageIs('admin/users') - ->seeInElement('td', 1) - ->seeInElement('td', $data['username']) - ->seeInElement('td', $data['email']) - ->seeInElement('td', $data['mobile']) - ->seeInElement('td', "{$data['profile']['first_name']} {$data['profile']['last_name']}") - ->seeElement('td img') - ->seeInElement('td', $data['profile']['postcode']) - ->seeInElement('td', $data['profile']['address']) - ->seeInElement('td', "{$data['profile']['latitude']} {$data['profile']['longitude']}") - ->seeInElement('td', $data['profile']['color']) - ->seeInElement('td', $data['profile']['start_at']) - ->seeInElement('td', $data['profile']['end_at']); - - $this->assertCount(1, UserModel::all()); - - $this->seeInDatabase('test_users', ['username' => $data['username']]); - $this->seeInDatabase('test_users', ['email' => $data['email']]); - $this->seeInDatabase('test_users', ['mobile' => $data['mobile']]); - $this->seeInDatabase('test_users', ['password' => $data['password']]); - - $this->seeInDatabase('test_user_profiles', ['first_name' => $data['profile']['first_name']]); - $this->seeInDatabase('test_user_profiles', ['last_name' => $data['profile']['last_name']]); - $this->seeInDatabase('test_user_profiles', ['postcode' => $data['profile']['postcode']]); - $this->seeInDatabase('test_user_profiles', ['address' => $data['profile']['address']]); - $this->seeInDatabase('test_user_profiles', ['latitude' => $data['profile']['latitude']]); - $this->seeInDatabase('test_user_profiles', ['longitude' => $data['profile']['longitude']]); - $this->seeInDatabase('test_user_profiles', ['color' => $data['profile']['color']]); - $this->seeInDatabase('test_user_profiles', ['start_at' => $data['profile']['start_at']]); - $this->seeInDatabase('test_user_profiles', ['end_at' => $data['profile']['end_at']]); - - $avatar = UserModel::first()->avatar; - - $this->assertFileExists(public_path('uploads/'.$avatar)); - } - - 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()); - }); - } - - public function testEditForm() - { - $this->seedsTable(10); - - $id = rand(1, 10); - - $user = UserModel::with('profile')->find($id); - - $this->visit("admin/users/$id/edit") - ->seeElement("input[type=text][name=username][value='{$user->username}']") - ->seeElement("input[type=email][name=email][value='{$user->email}']") - ->seeElement("input[type=text][name=mobile][value='{$user->mobile}']") - ->seeElement('hr') - ->seeElement("input[type=text][name='profile[first_name]'][value='{$user->profile->first_name}']") - ->seeElement("input[type=text][name='profile[last_name]'][value='{$user->profile->last_name}']") - ->seeElement("input[type=text][name='profile[postcode]'][value='{$user->profile->postcode}']") - ->seeInElement("textarea[name='profile[address]']", $user->profile->address) - ->seeElement("input[type=hidden][name='profile[latitude]'][value='{$user->profile->latitude}']") - ->seeElement("input[type=hidden][name='profile[longitude]'][value='{$user->profile->longitude}']") - ->seeElement("input[type=text][name='profile[color]'][value='{$user->profile->color}']") - ->seeElement("input[type=text][name='profile[start_at]'][value='{$user->profile->start_at}']") - ->seeElement("input[type=text][name='profile[end_at]'][value='{$user->profile->end_at}']") - ->seeElement("select[name='tags[]'][multiple=multiple]"); - - $this->assertCount(50, $this->crawler()->filter("select[name='tags[]'] option")); - $this->assertCount(5, $this->crawler()->filter("select[name='tags[]'] option[selected]")); - } - - public function testUpdateForm() - { - $this->seedsTable(10); - - $id = rand(1, 10); - - $this->visit("admin/users/$id/edit") - ->type('hello world', 'username') - ->type('123', 'password') - ->type('123', 'password_confirmation') - ->press('Submit') - ->seePageIs('admin/users') - ->seeInDatabase('test_users', ['username' => 'hello world']); - - $user = UserModel::with('profile')->find($id); - - $this->assertEquals($user->username, 'hello world'); - } - - public function testUpdateFormWithRule() - { - $this->seedsTable(10); - - $id = rand(1, 10); - - $this->visit("admin/users/$id/edit") - ->type('', 'email') - ->press('Submit') - ->seePageIs("admin/users/$id/edit") - ->see('The email field is required'); - - $this->type('xxaxx', 'email') - ->press('Submit') - ->seePageIs("admin/users/$id/edit") - ->see('The email must be a valid email address.'); - - $this->visit("admin/users/$id/edit") - ->type('123', 'password') - ->type('1234', 'password_confirmation') - ->press('Submit') - ->seePageIs("admin/users/$id/edit") - ->see('The Password confirmation does not match.'); - - $this->type('xx@xx.xx', 'email') - ->type('123', 'password') - ->type('123', 'password_confirmation') - ->press('Submit') - ->seePageIs('admin/users') - ->seeInDatabase('test_users', ['email' => 'xx@xx.xx']); - } - - public function testFormHeader() - { - $this->seedsTable(1); - - $this->visit('admin/users/1/edit') - ->seeInElement('a[class*=btn-danger]', 'Delete') - ->seeInElement('a[class*=btn-default]', 'List') - ->seeInElement('a[class*=btn-primary]', 'View'); - } - - public function testFormFooter() - { - $this->seedsTable(1); - - $this->visit('admin/users/1/edit') - ->seeElement('input[type=checkbox][value=1]') - ->seeElement('input[type=checkbox][value=2]'); - } + 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()); + }); } +test('edit form', function () { + seedsTable(10); + + $id = rand(1, 10); + + $user = UserModel::with('profile')->find($id); + + $this->visit("admin/users/$id/edit") + ->seeElement("input[type=text][name=username][value='{$user->username}']") + ->seeElement("input[type=email][name=email][value='{$user->email}']") + ->seeElement("input[type=text][name=mobile][value='{$user->mobile}']") + ->seeElement('hr') + ->seeElement("input[type=text][name='profile[first_name]'][value='{$user->profile->first_name}']") + ->seeElement("input[type=text][name='profile[last_name]'][value='{$user->profile->last_name}']") + ->seeElement("input[type=text][name='profile[postcode]'][value='{$user->profile->postcode}']") + ->seeInElement("textarea[name='profile[address]']", $user->profile->address) + ->seeElement("input[type=hidden][name='profile[latitude]'][value='{$user->profile->latitude}']") + ->seeElement("input[type=hidden][name='profile[longitude]'][value='{$user->profile->longitude}']") + ->seeElement("input[type=text][name='profile[color]'][value='{$user->profile->color}']") + ->seeElement("input[type=text][name='profile[start_at]'][value='{$user->profile->start_at}']") + ->seeElement("input[type=text][name='profile[end_at]'][value='{$user->profile->end_at}']") + ->seeElement("select[name='tags[]'][multiple=multiple]"); + + expect($this->crawler()->filter("select[name='tags[]'] option"))->toHaveCount(50); + expect($this->crawler()->filter("select[name='tags[]'] option[selected]"))->toHaveCount(5); +}); +test('update form', function () { + seedsTable(10); + + $id = rand(1, 10); + + $this->visit("admin/users/$id/edit") + ->type('hello world', 'username') + ->type('123', 'password') + ->type('123', 'password_confirmation') + ->press('Submit') + ->seePageIs('admin/users') + ->seeInDatabase('test_users', ['username' => 'hello world']); + + $user = UserModel::with('profile')->find($id); + + expect('hello world')->toEqual($user->username); +}); +test('update form with rule', function () { + seedsTable(10); + + $id = rand(1, 10); + + $this->visit("admin/users/$id/edit") + ->type('', 'email') + ->press('Submit') + ->seePageIs("admin/users/$id/edit") + ->see('The email field is required'); + + $this->type('xxaxx', 'email') + ->press('Submit') + ->seePageIs("admin/users/$id/edit") + ->see('The email must be a valid email address.'); + + $this->visit("admin/users/$id/edit") + ->type('123', 'password') + ->type('1234', 'password_confirmation') + ->press('Submit') + ->seePageIs("admin/users/$id/edit") + ->see('The Password confirmation does not match.'); + + $this->type('xx@xx.xx', 'email') + ->type('123', 'password') + ->type('123', 'password_confirmation') + ->press('Submit') + ->seePageIs('admin/users') + ->seeInDatabase('test_users', ['email' => 'xx@xx.xx']); +}); +test('form header', function () { + seedsTable(1); + + $this->visit('admin/users/1/edit') + ->seeInElement('a[class*=btn-danger]', 'Delete') + ->seeInElement('a[class*=btn-default]', 'List') + ->seeInElement('a[class*=btn-primary]', 'View'); +}); +test('form footer', function () { + seedsTable(1); + + $this->visit('admin/users/1/edit') + ->seeElement('input[type=checkbox][value=1]') + ->seeElement('input[type=checkbox][value=2]'); +}); diff --git a/tests/UserGridTest.php b/tests/UserGridTest.php index b4694be3..cfbcc4e2 100644 --- a/tests/UserGridTest.php +++ b/tests/UserGridTest.php @@ -1,249 +1,218 @@ be(Administrator::first(), 'admin'); +}); +test('index page', function () { + $this->visit('admin/users') + ->see('Users') + ->seeInElement('tr th', 'Username') + ->seeInElement('tr th', 'Email') + ->seeInElement('tr th', 'Mobile') + ->seeInElement('tr th', 'Full name') + ->seeInElement('tr th', 'Avatar') + ->seeInElement('tr th', 'Post code') + ->seeInElement('tr th', 'Address') + ->seeInElement('tr th', 'Position') + ->seeInElement('tr th', 'Color') + ->seeInElement('tr th', '开始时间') + ->seeInElement('tr th', '结束时间') + ->seeInElement('tr th', 'Color') + ->seeInElement('tr th', 'Created at') + ->seeInElement('tr th', 'Updated at'); + + $action = url('/admin/users'); + + $this->seeElement("form[action='$action'][method=get]") + ->seeElement("form[action='$action'][method=get] input[name=id]") + ->seeElement("form[action='$action'][method=get] input[name=username]") + ->seeElement("form[action='$action'][method=get] input[name=email]") + ->seeElement("form[action='$action'][method=get] input[name='profile[start_at][start]']") + ->seeElement("form[action='$action'][method=get] input[name='profile[start_at][end]']") + ->seeElement("form[action='$action'][method=get] input[name='profile[end_at][start]']") + ->seeElement("form[action='$action'][method=get] input[name='profile[end_at][end]']"); + + $urlAll = url('/admin/users?_export_=all'); + $urlNew = url('/admin/users/create'); + $this->seeInElement("a[href=\"{$urlAll}\"]", 'All') + ->seeInElement("a[href=\"{$urlNew}\"]", 'New'); +}); +function seedsTable($count = 100) { - protected function setUp(): void - { - parent::setUp(); - - $this->be(Administrator::first(), 'admin'); - } - - public function testIndexPage() - { - $this->visit('admin/users') - ->see('Users') - ->seeInElement('tr th', 'Username') - ->seeInElement('tr th', 'Email') - ->seeInElement('tr th', 'Mobile') - ->seeInElement('tr th', 'Full name') - ->seeInElement('tr th', 'Avatar') - ->seeInElement('tr th', 'Post code') - ->seeInElement('tr th', 'Address') - ->seeInElement('tr th', 'Position') - ->seeInElement('tr th', 'Color') - ->seeInElement('tr th', '开始时间') - ->seeInElement('tr th', '结束时间') - ->seeInElement('tr th', 'Color') - ->seeInElement('tr th', 'Created at') - ->seeInElement('tr th', 'Updated at'); - - $action = url('/admin/users'); - - $this->seeElement("form[action='$action'][method=get]") - ->seeElement("form[action='$action'][method=get] input[name=id]") - ->seeElement("form[action='$action'][method=get] input[name=username]") - ->seeElement("form[action='$action'][method=get] input[name=email]") - ->seeElement("form[action='$action'][method=get] input[name='profile[start_at][start]']") - ->seeElement("form[action='$action'][method=get] input[name='profile[start_at][end]']") - ->seeElement("form[action='$action'][method=get] input[name='profile[end_at][start]']") - ->seeElement("form[action='$action'][method=get] input[name='profile[end_at][end]']"); - - $urlAll = url('/admin/users?_export_=all'); - $urlNew = url('/admin/users/create'); - $this->seeInElement("a[href=\"{$urlAll}\"]", 'All') - ->seeInElement("a[href=\"{$urlNew}\"]", 'New'); - } - - 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()); - $u->data = ['json' => ['field' => random_int(0, 50)]]; - $u->save(); - }); - } - - public function testGridWithData() - { - $this->seedsTable(); - - $this->visit('admin/users') - ->see('Users'); - - $this->assertCount(100, UserModel::all()); - $this->assertCount(100, ProfileModel::all()); - } - - public function testGridPagination() - { - $this->seedsTable(65); - - $this->visit('admin/users') - ->see('Users'); - - $this->visit('admin/users?page=2'); - $this->assertCount(20, $this->crawler()->filter('td a i[class*=fa-edit]')); - - $this->visit('admin/users?page=3'); - $this->assertCount(20, $this->crawler()->filter('td a i[class*=fa-edit]')); - - $this->visit('admin/users?page=4'); - $this->assertCount(5, $this->crawler()->filter('td a i[class*=fa-edit]')); - - $this->click(1)->seePageIs('admin/users?page=1'); - $this->assertCount(20, $this->crawler()->filter('td a i[class*=fa-edit]')); - } - - public function testOrderByJson() - { - $this->seedsTable(10); - $this->assertCount(10, UserModel::all()); - - $this->visit('admin/users?_sort[column]=data.json.field&_sort[type]=desc&_sort[cast]=unsigned'); - - $jsonTds = $this->crawler->filter('table.table tbody td.column-data-json-field'); - $this->assertCount(10, $jsonTds); - $prevValue = PHP_INT_MAX; - foreach ($jsonTds as $jsonTd) { - $currentValue = (int) $jsonTd->nodeValue; - $this->assertTrue($currentValue <= $prevValue); - $prevValue = $currentValue; - } - } - - public function testEqualFilter() - { - $this->seedsTable(50); - - $this->visit('admin/users') - ->see('Users'); - - $this->assertCount(50, UserModel::all()); - $this->assertCount(50, ProfileModel::all()); - - $id = rand(1, 50); - - $user = UserModel::find($id); - - $this->visit('admin/users?id='.$id) - ->seeInElement('td', $user->username) - ->seeInElement('td', $user->email) - ->seeInElement('td', $user->mobile) - ->seeElement("img[src='{$user->avatar}']") - ->seeInElement('td', "{$user->profile->first_name} {$user->profile->last_name}") - ->seeInElement('td', $user->postcode) - ->seeInElement('td', $user->address) - ->seeInElement('td', "{$user->profile->latitude} {$user->profile->longitude}") - ->seeInElement('td', $user->color) - ->seeInElement('td', $user->start_at) - ->seeInElement('td', $user->end_at); - } - - public function testLikeFilter() - { - $this->seedsTable(50); - - $this->visit('admin/users') - ->see('Users'); - - $this->assertCount(50, UserModel::all()); - $this->assertCount(50, ProfileModel::all()); - - $users = UserModel::where('username', 'like', '%mi%')->get(); - - $this->visit('admin/users?username=mi'); - - $this->assertCount($this->crawler()->filter('table tr')->count() - 1, $users); - - foreach ($users as $user) { - $this->seeInElement('td', $user->username); - } - } - - public function testFilterRelation() - { - $this->seedsTable(50); - - $user = UserModel::with('profile')->find(rand(1, 50)); - - $this->visit('admin/users?email='.$user->email) - ->seeInElement('td', $user->username) - ->seeInElement('td', $user->email) - ->seeInElement('td', $user->mobile) - ->seeElement("img[src='{$user->avatar}']") - ->seeInElement('td', "{$user->profile->first_name} {$user->profile->last_name}") - ->seeInElement('td', $user->postcode) - ->seeInElement('td', $user->address) - ->seeInElement('td', "{$user->profile->latitude} {$user->profile->longitude}") - ->seeInElement('td', $user->color) - ->seeInElement('td', $user->start_at) - ->seeInElement('td', $user->end_at); - } - - public function testDisplayCallback() - { - $this->seedsTable(1); - - $user = UserModel::with('profile')->find(1); - - $this->visit('admin/users') - ->seeInElement('th', 'Column1 not in table') - ->seeInElement('th', 'Column2 not in table') - ->seeInElement('td', "full name:{$user->profile->first_name} {$user->profile->last_name}") - ->seeInElement('td', "{$user->email}#{$user->profile->color}"); - } - - public function testHasManyRelation() - { - factory(\Tests\Models\User::class, 10) - ->create() - ->each(function ($u) { - $u->profile()->save(factory(\Tests\Models\Profile::class)->make()); - $u->tags()->saveMany(factory(\Tests\Models\Tag::class, 5)->make()); - }); - - $this->visit('admin/users') - ->seeElement('td code'); - - $this->assertCount(50, $this->crawler()->filter('td code')); + 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()); + $u->data = ['json' => ['field' => random_int(0, 50)]]; + $u->save(); + }); +} +test('grid with data', function () { + seedsTable(); + + $this->visit('admin/users') + ->see('Users'); + + expect(UserModel::all())->toHaveCount(100); + expect(ProfileModel::all())->toHaveCount(100); +}); +test('grid pagination', function () { + seedsTable(65); + + $this->visit('admin/users') + ->see('Users'); + + $this->visit('admin/users?page=2'); + expect($this->crawler()->filter('td a i[class*=fa-edit]'))->toHaveCount(20); + + $this->visit('admin/users?page=3'); + expect($this->crawler()->filter('td a i[class*=fa-edit]'))->toHaveCount(20); + + $this->visit('admin/users?page=4'); + expect($this->crawler()->filter('td a i[class*=fa-edit]'))->toHaveCount(5); + + $this->click(1)->seePageIs('admin/users?page=1'); + expect($this->crawler()->filter('td a i[class*=fa-edit]'))->toHaveCount(20); +}); +test('order by json', function () { + seedsTable(10); + expect(UserModel::all())->toHaveCount(10); + + $this->visit('admin/users?_sort[column]=data.json.field&_sort[type]=desc&_sort[cast]=unsigned'); + + $jsonTds = $this->crawler->filter('table.table tbody td.column-data-json-field'); + expect($jsonTds)->toHaveCount(10); + $prevValue = PHP_INT_MAX; + foreach ($jsonTds as $jsonTd) { + $currentValue = (int) $jsonTd->nodeValue; + expect($currentValue <= $prevValue)->toBeTrue(); + $prevValue = $currentValue; } +}); +test('equal filter', function () { + seedsTable(50); - public function testGridActions() - { - $this->seedsTable(15); + $this->visit('admin/users') + ->see('Users'); - $this->visit('admin/users'); + expect(UserModel::all())->toHaveCount(50); + expect(ProfileModel::all())->toHaveCount(50); - $this->assertCount(15, $this->crawler()->filter('td a i[class*=fa-edit]')); - $this->assertCount(15, $this->crawler()->filter('td a i[class*=fa-trash]')); - } + $id = rand(1, 50); - public function testGridRows() - { - $this->seedsTable(10); + $user = UserModel::find($id); - $this->visit('admin/users') - ->seeInElement('td a[class*=btn]', 'detail'); + $this->visit('admin/users?id='.$id) + ->seeInElement('td', $user->username) + ->seeInElement('td', $user->email) + ->seeInElement('td', $user->mobile) + ->seeElement("img[src='{$user->avatar}']") + ->seeInElement('td', "{$user->profile->first_name} {$user->profile->last_name}") + ->seeInElement('td', $user->postcode) + ->seeInElement('td', $user->address) + ->seeInElement('td', "{$user->profile->latitude} {$user->profile->longitude}") + ->seeInElement('td', $user->color) + ->seeInElement('td', $user->start_at) + ->seeInElement('td', $user->end_at); +}); +test('like filter', function () { + seedsTable(50); - $this->assertCount(5, $this->crawler()->filter('td a[class*=btn]')); - } + $this->visit('admin/users') + ->see('Users'); - public function testGridPerPage() - { - $this->seedsTable(98); + expect(UserModel::all())->toHaveCount(50); + expect(ProfileModel::all())->toHaveCount(50); - $this->visit('admin/users') - ->seeElement('select[class*=per-page][name=per-page]') - ->seeInElement('select option', 10) - ->seeInElement('select option[selected]', 20) - ->seeInElement('select option', 30) - ->seeInElement('select option', 50) - ->seeInElement('select option', 100); + $users = UserModel::where('username', 'like', '%mi%')->get(); - $this->assertEquals('http://localhost:8000/admin/users?per_page=20', $this->crawler()->filter('select option[selected]')->attr('value')); + $this->visit('admin/users?username=mi'); - $perPage = rand(1, 98); + expect($users)->toHaveCount($this->crawler()->filter('table tr')->count() - 1); - $this->visit('admin/users?per_page='.$perPage) - ->seeInElement('select option[selected]', $perPage) - ->assertCount($perPage + 1, $this->crawler()->filter('tr')); + foreach ($users as $user) { + $this->seeInElement('td', $user->username); } -} +}); +test('filter relation', function () { + seedsTable(50); + + $user = UserModel::with('profile')->find(rand(1, 50)); + + $this->visit('admin/users?email='.$user->email) + ->seeInElement('td', $user->username) + ->seeInElement('td', $user->email) + ->seeInElement('td', $user->mobile) + ->seeElement("img[src='{$user->avatar}']") + ->seeInElement('td', "{$user->profile->first_name} {$user->profile->last_name}") + ->seeInElement('td', $user->postcode) + ->seeInElement('td', $user->address) + ->seeInElement('td', "{$user->profile->latitude} {$user->profile->longitude}") + ->seeInElement('td', $user->color) + ->seeInElement('td', $user->start_at) + ->seeInElement('td', $user->end_at); +}); +test('display callback', function () { + seedsTable(1); + + $user = UserModel::with('profile')->find(1); + + $this->visit('admin/users') + ->seeInElement('th', 'Column1 not in table') + ->seeInElement('th', 'Column2 not in table') + ->seeInElement('td', "full name:{$user->profile->first_name} {$user->profile->last_name}") + ->seeInElement('td', "{$user->email}#{$user->profile->color}"); +}); +test('has many relation', function () { + factory(\Tests\Models\User::class, 10) + ->create() + ->each(function ($u) { + $u->profile()->save(factory(\Tests\Models\Profile::class)->make()); + $u->tags()->saveMany(factory(\Tests\Models\Tag::class, 5)->make()); + }); + + $this->visit('admin/users') + ->seeElement('td code'); + + expect($this->crawler()->filter('td code'))->toHaveCount(50); +}); +test('grid actions', function () { + seedsTable(15); + + $this->visit('admin/users'); + + expect($this->crawler()->filter('td a i[class*=fa-edit]'))->toHaveCount(15); + expect($this->crawler()->filter('td a i[class*=fa-trash]'))->toHaveCount(15); +}); +test('grid rows', function () { + seedsTable(10); + + $this->visit('admin/users') + ->seeInElement('td a[class*=btn]', 'detail'); + + expect($this->crawler()->filter('td a[class*=btn]'))->toHaveCount(5); +}); +test('grid per page', function () { + seedsTable(98); + + $this->visit('admin/users') + ->seeElement('select[class*=per-page][name=per-page]') + ->seeInElement('select option', 10) + ->seeInElement('select option[selected]', 20) + ->seeInElement('select option', 30) + ->seeInElement('select option', 50) + ->seeInElement('select option', 100); + + expect($this->crawler()->filter('select option[selected]')->attr('value'))->toEqual('http://localhost:8000/admin/users?per_page=20'); + + $perPage = rand(1, 98); + + $this->visit('admin/users?per_page='.$perPage) + ->seeInElement('select option[selected]', $perPage) + ->assertCount($perPage + 1, $this->crawler()->filter('tr')); +}); diff --git a/tests/UserSettingTest.php b/tests/UserSettingTest.php index 5d7fbfa0..4ccb286e 100644 --- a/tests/UserSettingTest.php +++ b/tests/UserSettingTest.php @@ -1,96 +1,80 @@ be(Administrator::first(), 'admin'); - } - - public function testVisitSettingPage() - { - $this->visit('admin/auth/setting') - ->see('User setting') - ->see('Username') - ->see('Name') - ->see('Avatar') - ->see('Password') - ->see('Password confirmation'); - - $this->seeElement('input[value=Administrator]') - ->seeInElement('.box-body', 'administrator'); - } - - public function testUpdateName() - { - $data = [ - 'name' => 'tester', - ]; - - $this->visit('admin/auth/setting') - ->submitForm('Submit', $data) - ->seePageIs('admin/auth/setting'); - - $this->seeInDatabase('admin_users', ['name' => $data['name']]); - } - - public function testUpdateAvatar() - { - File::cleanDirectory(public_path('uploads/images')); - - $this->visit('admin/auth/setting') - ->attach(__DIR__.'/assets/test.jpg', 'avatar') - ->press('Submit') - ->seePageIs('admin/auth/setting'); - - $avatar = Administrator::first()->avatar; - - $this->assertEquals('http://localhost:8000/uploads/images/test.jpg', $avatar); - } - - public function testUpdatePasswordConfirmation() - { - $data = [ - 'password' => '123456', - 'password_confirmation' => '123', - ]; - - $this->visit('admin/auth/setting') - ->submitForm('Submit', $data) - ->seePageIs('admin/auth/setting') - ->see('The Password confirmation does not match.'); - } - - public function testUpdatePassword() - { - $data = [ - 'password' => '123456', - 'password_confirmation' => '123456', - ]; - - $this->visit('admin/auth/setting') - ->submitForm('Submit', $data) - ->seePageIs('admin/auth/setting'); - - $this->assertTrue(app('hash')->check($data['password'], Administrator::first()->makeVisible('password')->password)); - - $this->visit('admin/auth/logout') - ->seePageIs('admin/auth/login') - ->dontSeeIsAuthenticated('admin'); - - $credentials = ['username' => 'admin', 'password' => '123456']; - - $this->visit('admin/auth/login') - ->see('login') - ->submitForm('Login', $credentials) - ->see('dashboard') - ->seeCredentials($credentials, 'admin') - ->seeIsAuthenticated('admin') - ->seePageIs('admin'); - } -} +beforeEach(function () { + $this->be(Administrator::first(), 'admin'); +}); +test('visit setting page', function () { + $this->visit('admin/auth/setting') + ->see('User setting') + ->see('Username') + ->see('Name') + ->see('Avatar') + ->see('Password') + ->see('Password confirmation'); + + $this->seeElement('input[value=Administrator]') + ->seeInElement('.box-body', 'administrator'); +}); +test('update name', function () { + $data = [ + 'name' => 'tester', + ]; + + $this->visit('admin/auth/setting') + ->submitForm('Submit', $data) + ->seePageIs('admin/auth/setting'); + + $this->seeInDatabase('admin_users', ['name' => $data['name']]); +}); +test('update avatar', function () { + File::cleanDirectory(public_path('uploads/images')); + + $this->visit('admin/auth/setting') + ->attach(__DIR__.'/assets/test.jpg', 'avatar') + ->press('Submit') + ->seePageIs('admin/auth/setting'); + + $avatar = Administrator::first()->avatar; + + expect($avatar)->toEqual('http://localhost:8000/uploads/images/test.jpg'); +}); +test('update password confirmation', function () { + $data = [ + 'password' => '123456', + 'password_confirmation' => '123', + ]; + + $this->visit('admin/auth/setting') + ->submitForm('Submit', $data) + ->seePageIs('admin/auth/setting') + ->see('The Password confirmation does not match.'); +}); +test('update password', function () { + $data = [ + 'password' => '123456', + 'password_confirmation' => '123456', + ]; + + $this->visit('admin/auth/setting') + ->submitForm('Submit', $data) + ->seePageIs('admin/auth/setting'); + + expect(app('hash')->check($data['password'], Administrator::first()->makeVisible('password')->password))->toBeTrue(); + + $this->visit('admin/auth/logout') + ->seePageIs('admin/auth/login') + ->dontSeeIsAuthenticated('admin'); + + $credentials = ['username' => 'admin', 'password' => '123456']; + + $this->visit('admin/auth/login') + ->see('login') + ->submitForm('Login', $credentials) + ->see('dashboard') + ->seeCredentials($credentials, 'admin') + ->seeIsAuthenticated('admin') + ->seePageIs('admin'); +}); diff --git a/tests/UsersTest.php b/tests/UsersTest.php index 8ff7a335..653fbeb9 100644 --- a/tests/UsersTest.php +++ b/tests/UsersTest.php @@ -1,95 +1,79 @@ user = Administrator::first(); - - $this->be($this->user, 'admin'); - } - - public function testUsersIndexPage() - { - $this->visit('admin/auth/users') - ->see('Administrator'); - } - - public function testCreateUser() - { - $user = [ - 'username' => 'Test', - 'name' => 'Name', - 'password' => '123456', - 'password_confirmation' => '123456', - ]; - - // create user - $this->visit('admin/auth/users/create') - ->see('Create') - ->submitForm('Submit', $user) - ->seePageIs('admin/auth/users') - ->seeInDatabase(config('admin.database.users_table'), ['username' => 'Test']); - - // assign role to user - $this->visit('admin/auth/users/2/edit') - ->see('Edit') - ->submitForm('Submit', ['roles' => [1]]) - ->seePageIs('admin/auth/users') - ->seeInDatabase(config('admin.database.role_users_table'), ['user_id' => 2, 'role_id' => 1]); - - $this->visit('admin/auth/logout') - ->dontSeeIsAuthenticated('admin') - ->seePageIs('admin/auth/login') - ->submitForm('Login', ['username' => $user['username'], 'password' => $user['password']]) - ->see('dashboard') - ->seeIsAuthenticated('admin') - ->seePageIs('admin'); - - $this->assertTrue($this->app['auth']->guard('admin')->getUser()->isAdministrator()); - - $this->see('Users') - ->see('Roles') - ->see('Permission') - ->see('Operation log') - ->see('Menu'); - } - - public function testUpdateUser() - { - $this->visit('admin/auth/users/'.$this->user->id.'/edit') - ->see('Create') - ->submitForm('Submit', ['name' => 'test', 'roles' => [1]]) - ->seePageIs('admin/auth/users') - ->seeInDatabase(config('admin.database.users_table'), ['name' => 'test']); - } - - public function testResetPassword() - { - $password = 'odjwyufkglte'; - - $data = [ - 'password' => $password, - 'password_confirmation' => $password, - 'roles' => [1], - ]; - - $this->visit('admin/auth/users/'.$this->user->id.'/edit') - ->see('Create') - ->submitForm('Submit', $data) - ->seePageIs('admin/auth/users') - ->visit('admin/auth/logout') - ->dontSeeIsAuthenticated('admin') - ->seePageIs('admin/auth/login') - ->submitForm('Login', ['username' => $this->user->username, 'password' => $password]) - ->see('dashboard') - ->seeIsAuthenticated('admin') - ->seePageIs('admin'); - } -} +uses(\TestCase::class); +use Encore\Admin\Auth\Database\Administrator; +beforeEach(function () { + $this->user = Administrator::first(); + + $this->be($this->user, 'admin'); +}); +test('users index page', function () { + $this->visit('admin/auth/users') + ->see('Administrator'); +}); +test('create user', function () { + $user = [ + 'username' => 'Test', + 'name' => 'Name', + 'password' => '123456', + 'password_confirmation' => '123456', + ]; + + // create user + $this->visit('admin/auth/users/create') + ->see('Create') + ->submitForm('Submit', $user) + ->seePageIs('admin/auth/users') + ->seeInDatabase(config('admin.database.users_table'), ['username' => 'Test']); + + // assign role to user + $this->visit('admin/auth/users/2/edit') + ->see('Edit') + ->submitForm('Submit', ['roles' => [1]]) + ->seePageIs('admin/auth/users') + ->seeInDatabase(config('admin.database.role_users_table'), ['user_id' => 2, 'role_id' => 1]); + + $this->visit('admin/auth/logout') + ->dontSeeIsAuthenticated('admin') + ->seePageIs('admin/auth/login') + ->submitForm('Login', ['username' => $user['username'], 'password' => $user['password']]) + ->see('dashboard') + ->seeIsAuthenticated('admin') + ->seePageIs('admin'); + + expect($this->app['auth']->guard('admin')->getUser()->isAdministrator())->toBeTrue(); + + $this->see('Users') + ->see('Roles') + ->see('Permission') + ->see('Operation log') + ->see('Menu'); +}); +test('update user', function () { + $this->visit('admin/auth/users/'.$this->user->id.'/edit') + ->see('Create') + ->submitForm('Submit', ['name' => 'test', 'roles' => [1]]) + ->seePageIs('admin/auth/users') + ->seeInDatabase(config('admin.database.users_table'), ['name' => 'test']); +}); +test('reset password', function () { + $password = 'odjwyufkglte'; + + $data = [ + 'password' => $password, + 'password_confirmation' => $password, + 'roles' => [1], + ]; + + $this->visit('admin/auth/users/'.$this->user->id.'/edit') + ->see('Create') + ->submitForm('Submit', $data) + ->seePageIs('admin/auth/users') + ->visit('admin/auth/logout') + ->dontSeeIsAuthenticated('admin') + ->seePageIs('admin/auth/login') + ->submitForm('Login', ['username' => $this->user->username, 'password' => $password]) + ->see('dashboard') + ->seeIsAuthenticated('admin') + ->seePageIs('admin'); +}); diff --git a/tests/config/admin.php b/tests/config/admin.php index 48adec81..b155b940 100644 --- a/tests/config/admin.php +++ b/tests/config/admin.php @@ -3,9 +3,9 @@ return [ /* - * Open-admin name. + * Laravel-admin name. */ - 'name' => 'Open-admin', + 'name' => 'Laravel-admin', /* * Logo in admin panel header. @@ -30,12 +30,12 @@ ], /* - * Open-admin install directory. + * Laravel-admin install directory. */ 'directory' => app_path('Admin'), /* - * Open-admin html title. + * Laravel-admin html title. */ 'title' => 'Admin', @@ -45,7 +45,7 @@ 'secure' => false, /* - * Open-admin auth setting. + * Laravel-admin auth setting. */ 'auth' => [ 'guards' => [ @@ -58,13 +58,13 @@ 'providers' => [ 'admin' => [ 'driver' => 'eloquent', - 'model' => OpenAdmin\Admin\Auth\Database\Administrator::class, + 'model' => Encore\Admin\Auth\Database\Administrator::class, ], ], ], /* - * Open-admin upload setting. + * Laravel-admin upload setting. */ 'upload' => [ @@ -77,7 +77,7 @@ ], /* - * Open-admin database setting. + * Laravel-admin database setting. */ 'database' => [ @@ -86,19 +86,19 @@ // User tables and model. 'users_table' => 'admin_users', - 'users_model' => OpenAdmin\Admin\Auth\Database\Administrator::class, + 'users_model' => Encore\Admin\Auth\Database\Administrator::class, // Role table and model. 'roles_table' => 'admin_roles', - 'roles_model' => OpenAdmin\Admin\Auth\Database\Role::class, + 'roles_model' => Encore\Admin\Auth\Database\Role::class, // Permission table and model. 'permissions_table' => 'admin_permissions', - 'permissions_model' => OpenAdmin\Admin\Auth\Database\Permission::class, + 'permissions_model' => Encore\Admin\Auth\Database\Permission::class, // Menu table and model. 'menu_table' => 'admin_menu', - 'menu_model' => OpenAdmin\Admin\Auth\Database\Menu::class, + 'menu_model' => Encore\Admin\Auth\Database\Menu::class, // Pivot table for table above. 'operation_log_table' => 'admin_operation_log', @@ -109,7 +109,7 @@ ], /* - * By setting this option to open or close operation log in open-admin. + * By setting this option to open or close operation log in laravel-admin. */ 'operation_log' => [ diff --git a/tests/config/filesystems.php b/tests/config/filesystems.php index 3cd874e8..4b0a99ea 100644 --- a/tests/config/filesystems.php +++ b/tests/config/filesystems.php @@ -86,7 +86,7 @@ 'driver' => 'oss', 'access_id' => 'LTAIsOQNIDQN78Jr', 'access_key' => 'ChsYewaCxm1mi7AIBPRniuncEbFHNO', - 'bucket' => 'open-admin', + 'bucket' => 'laravel-admin', 'endpoint' => 'oss-cn-shanghai.aliyuncs.com', ], diff --git a/tests/controllers/FileController.php b/tests/controllers/FileController.php index 62a0db19..565f0d28 100644 --- a/tests/controllers/FileController.php +++ b/tests/controllers/FileController.php @@ -2,9 +2,9 @@ namespace Tests\Controllers; -use OpenAdmin\Admin\Controllers\AdminController; -use OpenAdmin\Admin\Form; -use OpenAdmin\Admin\Grid; +use Encore\Admin\Controllers\AdminController; +use Encore\Admin\Form; +use Encore\Admin\Grid; use Tests\Models\File; class FileController extends AdminController diff --git a/tests/controllers/ImageController.php b/tests/controllers/ImageController.php index 0cf08cc2..8a1a44f7 100644 --- a/tests/controllers/ImageController.php +++ b/tests/controllers/ImageController.php @@ -2,9 +2,9 @@ namespace Tests\Controllers; -use OpenAdmin\Admin\Controllers\AdminController; -use OpenAdmin\Admin\Form; -use OpenAdmin\Admin\Grid; +use Encore\Admin\Controllers\AdminController; +use Encore\Admin\Form; +use Encore\Admin\Grid; use Tests\Models\Image; class ImageController extends AdminController diff --git a/tests/controllers/MultipleImageController.php b/tests/controllers/MultipleImageController.php index d0c88e32..78811759 100644 --- a/tests/controllers/MultipleImageController.php +++ b/tests/controllers/MultipleImageController.php @@ -2,9 +2,9 @@ namespace Tests\Controllers; -use OpenAdmin\Admin\Controllers\AdminController; -use OpenAdmin\Admin\Form; -use OpenAdmin\Admin\Grid; +use Encore\Admin\Controllers\AdminController; +use Encore\Admin\Form; +use Encore\Admin\Grid; use Tests\Models\MultipleImage; class MultipleImageController extends AdminController diff --git a/tests/controllers/UserController.php b/tests/controllers/UserController.php index 847c3800..6f6317d1 100644 --- a/tests/controllers/UserController.php +++ b/tests/controllers/UserController.php @@ -2,9 +2,9 @@ namespace Tests\Controllers; -use OpenAdmin\Admin\Controllers\AdminController; -use OpenAdmin\Admin\Form; -use OpenAdmin\Admin\Grid; +use Encore\Admin\Controllers\AdminController; +use Encore\Admin\Form; +use Encore\Admin\Grid; use Tests\Models\Tag; use Tests\Models\User; diff --git a/tests/database/Migrations/2016_11_22_093148_create_test_tables.php b/tests/database/Migrations/2016_11_22_093148_create_test_tables.php new file mode 100644 index 00000000..3632bd1d --- /dev/null +++ b/tests/database/Migrations/2016_11_22_093148_create_test_tables.php @@ -0,0 +1,99 @@ +increments('id'); + $table->string('image1'); + $table->string('image2'); + $table->string('image3'); + $table->string('image4'); + $table->string('image5'); + $table->string('image6'); + $table->timestamps(); + }); + + Schema::create('test_multiple_images', function (Blueprint $table) { + $table->increments('id'); + $table->text('pictures'); + $table->timestamps(); + }); + + Schema::create('test_files', function (Blueprint $table) { + $table->increments('id'); + $table->string('file1'); + $table->string('file2'); + $table->string('file3'); + $table->string('file4'); + $table->string('file5'); + $table->string('file6'); + $table->timestamps(); + }); + + Schema::create('test_users', function (Blueprint $table) { + $table->increments('id'); + $table->string('username'); + $table->string('email'); + $table->string('mobile')->nullable(); + $table->string('avatar')->nullable(); + $table->string('password'); + $table->json('data')->nullable(); + $table->timestamps(); + }); + + Schema::create('test_user_profiles', function (Blueprint $table) { + $table->increments('id'); + $table->string('user_id'); + $table->string('first_name')->nullable(); + $table->string('last_name')->nullable(); + $table->string('postcode')->nullable(); + $table->string('address')->nullable(); + $table->string('latitude')->nullable(); + $table->string('longitude')->nullable(); + $table->string('color')->nullable(); + $table->timestamp('start_at')->nullable(); + $table->timestamp('end_at')->nullable(); + + $table->timestamps(); + }); + + Schema::create('test_tags', function (Blueprint $table) { + $table->increments('id'); + $table->string('name'); + $table->timestamps(); + }); + + Schema::create('test_user_tags', function (Blueprint $table) { + $table->integer('user_id'); + $table->integer('tag_id'); + $table->index(['user_id', 'tag_id']); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('test_images'); + Schema::dropIfExists('test_multiple_images'); + Schema::dropIfExists('test_files'); + Schema::dropIfExists('test_users'); + Schema::dropIfExists('test_user_profiles'); + Schema::dropIfExists('test_tags'); + Schema::dropIfExists('test_user_tags'); + } +} diff --git a/tests/database/factories/ProfileFactory.php b/tests/database/factories/ProfileFactory.php new file mode 100644 index 00000000..226ee2e5 --- /dev/null +++ b/tests/database/factories/ProfileFactory.php @@ -0,0 +1,25 @@ + $this->faker->firstName, + 'last_name' => $this->faker->lastName, + 'postcode' => $this->faker->postcode, + 'address' => $this->faker->address, + 'latitude' => $this->faker->latitude, + 'longitude' => $this->faker->longitude, + 'color' => $this->faker->hexColor, + 'start_at' => $this->faker->dateTime, + 'end_at' => $this->faker->dateTime, + ]; + } +} diff --git a/tests/database/factories/TagFactory.php b/tests/database/factories/TagFactory.php new file mode 100644 index 00000000..48cad8f8 --- /dev/null +++ b/tests/database/factories/TagFactory.php @@ -0,0 +1,17 @@ + $this->faker->word, + ]; + } +} diff --git a/tests/database/factories/UserFactory.php b/tests/database/factories/UserFactory.php new file mode 100644 index 00000000..4274e3c0 --- /dev/null +++ b/tests/database/factories/UserFactory.php @@ -0,0 +1,22 @@ + $this->faker->userName, + 'email' => $this->faker->unique()->safeEmail, + 'mobile' => $this->faker->phoneNumber, + 'avatar' => $this->faker->imageUrl(), + 'password' => bcrypt('123456'), + ]; + } +} + diff --git a/tests/database/seeders/LegacyUserTableSeeder.php b/tests/database/seeders/LegacyUserTableSeeder.php new file mode 100644 index 00000000..c5dfe4df --- /dev/null +++ b/tests/database/seeders/LegacyUserTableSeeder.php @@ -0,0 +1,19 @@ +create() + ->each(function ($u) { + $u->profile()->save(factory(\Tests\Models\Profile::class)->make()); + $u->tags()->saveMany(factory(\Tests\Models\Tag::class, 5)->make()); + $u->data = ['json' => ['field' => random_int(0, 50)]]; + }); + } +} diff --git a/tests/database/seeders/UserTableSeeder.php b/tests/database/seeders/UserTableSeeder.php new file mode 100644 index 00000000..0ba5ee52 --- /dev/null +++ b/tests/database/seeders/UserTableSeeder.php @@ -0,0 +1,24 @@ +count(10) + ->create() + ->each(function ($user) { + // You can define ProfileFactory and TagFactory similarly if needed + Profile::factory()->create(['user_id' => $user->id]); + $user->tags()->saveMany(Tag::factory()->count(3)->make()); + }); + } +} diff --git a/tests/models/Tree.php b/tests/models/Tree.php index 4d444a72..c42419a0 100644 --- a/tests/models/Tree.php +++ b/tests/models/Tree.php @@ -2,8 +2,8 @@ namespace Tests\Models; +use Encore\Admin\Traits\ModelTree; use Illuminate\Database\Eloquent\Model; -use OpenAdmin\Admin\Traits\ModelTree; class Tree extends Model { diff --git a/tests/pest.php b/tests/pest.php new file mode 100644 index 00000000..38fe7b17 --- /dev/null +++ b/tests/pest.php @@ -0,0 +1,5 @@ +in(__DIR__ . '/Feature'); From def872b78bd4c5a78123c307228eec365b418c1f Mon Sep 17 00:00:00 2001 From: Talemul Islam Date: Tue, 20 May 2025 23:58:28 +0600 Subject: [PATCH 07/10] update php unit test --- .gitignore | 1 - composer.json | 124 +++-- phpunit.xml.dist | 26 +- tests/AuthTest.php | 110 ++--- tests/FileUploadTest.php | 241 +++++----- tests/ImageUploadTest.php | 330 +++++++------- tests/IndexTest.php | 82 ++-- tests/InstallTest.php | 27 +- tests/LaravelTest.php | 15 +- tests/MenuTest.php | 130 +++--- tests/ModelTreeTest.php | 31 +- tests/OperationLogTest.php | 150 +++--- tests/PermissionsTest.php | 404 ++++++++-------- tests/RolesTest.php | 190 ++++---- tests/TestCase.php | 98 +++- tests/UserFormTest.php | 387 ++++++++-------- tests/UserGridTest.php | 431 ++++++++++-------- tests/UserSettingTest.php | 170 +++---- tests/UsersTest.php | 170 +++---- tests/config/admin.php | 26 +- tests/config/filesystems.php | 2 +- tests/controllers/FileController.php | 6 +- tests/controllers/ImageController.php | 6 +- tests/controllers/MultipleImageController.php | 6 +- tests/controllers/UserController.php | 6 +- tests/models/Tree.php | 2 +- 26 files changed, 1738 insertions(+), 1433 deletions(-) diff --git a/.gitignore b/.gitignore index dd2c8eb9..4e530b36 100644 --- a/.gitignore +++ b/.gitignore @@ -10,4 +10,3 @@ composer.lock resources/assets/minify-manifest.json resources/assets/open-admin.min.css resources/assets/open-admin.min.js -.env diff --git a/composer.json b/composer.json index c2b5e5e5..3d9db226 100644 --- a/composer.json +++ b/composer.json @@ -1,69 +1,65 @@ { - "name": "open-admin-org/open-admin", - "description": "open-admin. Open-source Laravel Admin panel. No pro or paid package, free & open. Based on laravel-admin, with special thanks to z-song", - "type": "library", - "keywords": ["laravel", "admin", "grid", "form", "open-admin","open","free"], - "homepage": "https://github.com/open-admin-org/open-admin", - "license": "MIT", - "authors": [ - { - "name": "Sjors Broersen | Open-Admin.org", - "email": "info@open-admin.org" - } - ], - "require": { - "php": "^8.2", - "laravel/framework": "12.0", - "symfony/dom-crawler": "^6.0|^7.0", - "doctrine/dbal": "^3.0|^4.0|^5.0", - "phpunit/phpunit": "11.5.15", - "pestphp/pest": "3.8", - "nunomaduro/collision": "^8.8" - - }, - "require-dev": { - "intervention/image": "^2.7", - "pestphp/pest-plugin-drift": "^3.0", - "laravel/browser-kit-testing": "^7.2" - }, - "autoload": { - "psr-4": { - "OpenAdmin\\Admin\\": "src/" + "name": "open-admin-org/open-admin", + "description": "open-admin. Open-source Laravel Admin panel. No pro or paid package, free & open. Based on laravel-admin, with special thanks to z-song", + "type": "library", + "keywords": ["laravel", "admin", "grid", "form", "open-admin","open","free"], + "homepage": "https://github.com/open-admin-org/open-admin", + "license": "MIT", + "authors": [ + { + "name": "Sjors Broersen | Open-Admin.org", + "email": "info@open-admin.org" + } + ], + "require": { + "php": "~7.3|~8.0", + "symfony/dom-crawler": "~3.1|~4.0|~5.0|~6.0|~7.0", + "laravel/framework": ">=7.0", + "doctrine/dbal": "2.*|3.*|4.*|5.*" }, - "files": [ - "src/helpers.php" - ] - }, - "autoload-dev": { - "psr-4": { - "Tests\\": "tests/" + "require-dev": { + "laravel/laravel": ">=8.0|^10.0|^11.0|^12.0", + "fzaninotto/faker": "~1.4", + "intervention/image": "~2.3", + "laravel/browser-kit-testing": "^6.0", + "spatie/phpunit-watcher": "^1.22.0" }, - "classmap": [ - "tests/TestCase.php" - ] - }, - "scripts": { - "sass": "sass --watch resources/assets/open-admin/scss/styles.scss:resources/assets/open-admin/css/styles.css resources/assets/open-admin/scss/pages:resources/assets/open-admin/css/pages --style compressed", - "test": "./vendor/bin/phpunit" - }, - "suggest": { - "intervention/image": "Required to handling and manipulation upload images (~2.3).", - "spatie/eloquent-sortable": "Required to built orderable gird." - }, - "extra": { - "laravel": { - "providers": [ - "OpenAdmin\\Admin\\AdminServiceProvider" - ], - "aliases": { - "Admin": "OpenAdmin\\Admin\\Facades\\Admin" - } - } - }, - "config": { - "process-timeout": 0, - "allow-plugins": { - "pestphp/pest-plugin": true + "autoload": { + "psr-4": { + "OpenAdmin\\Admin\\": "src/" + }, + "files": [ + "src/helpers.php" + ] + }, + "autoload-dev": { + "psr-4": { + "Tests\\Models\\": "tests/models", + "Tests\\Controllers\\": "tests/controllers" + }, + "classmap": [ + "tests/TestCase.php" + ] + }, + "scripts": { + "sass": "sass --watch resources/assets/open-admin/scss/styles.scss:resources/assets/open-admin/css/styles.css resources/assets/open-admin/scss/pages:resources/assets/open-admin/css/pages --style compressed", + "test": "./vendor/bin/phpunit" + }, + "suggest": { + "intervention/image": "Required to handling and manipulation upload images (~2.3).", + "spatie/eloquent-sortable": "Required to built orderable gird." + }, + "extra": { + "laravel": { + "providers": [ + "OpenAdmin\\Admin\\AdminServiceProvider" + ], + "aliases": { + "Admin": "OpenAdmin\\Admin\\Facades\\Admin" + } + } + }, + "config": { + "process-timeout": 0 } - } } diff --git a/phpunit.xml.dist b/phpunit.xml.dist index f8966410..b9440089 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,18 +1,18 @@ - - + convertErrorsToExceptions="true" + convertNoticesToExceptions="true" + convertWarningsToExceptions="true" + processIsolation="false" + stopOnFailure="true" + verbose="true" + > - - ./tests + + tests/ - - - - app - - - + \ No newline at end of file diff --git a/tests/AuthTest.php b/tests/AuthTest.php index 7d48c00f..3b491ff4 100644 --- a/tests/AuthTest.php +++ b/tests/AuthTest.php @@ -1,55 +1,61 @@ visit('admin/auth/login') - ->see('login'); -}); - -test('visit without login', function () { - $this->visit('admin') - ->dontSeeIsAuthenticated('admin') - ->seePageIs('admin/auth/login'); -}); - -test('login', function () { - $credentials = ['username' => 'admin', 'password' => 'admin']; - - $this->visit('admin/auth/login') - ->see('login') - ->submitForm('Login', $credentials) - ->see('dashboard') - ->seeCredentials($credentials, 'admin') - ->seeIsAuthenticated('admin') - ->seePageIs('admin') - ->see('Dashboard') - ->see('Description...') - - ->see('Environment') - ->see('PHP version') - ->see('Laravel version') - - ->see('Available extensions') - ->seeLink('laravel-admin-ext/helpers', 'https://github.com/laravel-admin-extensions/helpers') - ->seeLink('laravel-admin-ext/backup', 'https://github.com/laravel-admin-extensions/backup') - ->seeLink('laravel-admin-ext/media-manager', 'https://github.com/laravel-admin-extensions/media-manager') - - ->see('Dependencies') - ->see('php') +class AuthTest extends TestCase +{ + public function testLoginPage() + { + $this->visit('admin/auth/login') + ->see('login'); + } + + public function testVisitWithoutLogin() + { + $this->visit('admin') + ->dontSeeIsAuthenticated('admin') + ->seePageIs('admin/auth/login'); + } + + public function testLogin() + { + $credentials = ['username' => 'admin', 'password' => 'admin']; + + $this->visit('admin/auth/login') + ->see('login') + ->submitForm('Login', $credentials) + ->see('dashboard') + ->seeCredentials($credentials, 'admin') + ->seeIsAuthenticated('admin') + ->seePageIs('admin') + ->see('Dashboard') + ->see('Description...') + + ->see('Environment') + ->see('PHP version') + ->see('Laravel version') + + ->see('Available extensions') + ->seeLink('open-admin-ext/helpers', 'https://github.com/open-admin-extensions/helpers') + ->seeLink('open-admin-ext/backup', 'https://github.com/open-admin-extensions/backup') + ->seeLink('open-admin-ext/media-manager', 'https://github.com/open-admin-extensions/media-manager') + + ->see('Dependencies') + ->see('php') // ->see('>=7.0.0') - ->see('laravel/framework'); - - $this - ->see('Admin') - ->see('Users') - ->see('Roles') - ->see('Permission') - ->see('Operation log') - ->see('Menu'); -}); - -test('logout', function () { - $this->visit('admin/auth/logout') - ->seePageIs('admin/auth/login') - ->dontSeeIsAuthenticated('admin'); -}); + ->see('laravel/framework'); + + $this + ->see('Admin') + ->see('Users') + ->see('Roles') + ->see('Permission') + ->see('Operation log') + ->see('Menu'); + } + + public function testLogout() + { + $this->visit('admin/auth/logout') + ->seePageIs('admin/auth/login') + ->dontSeeIsAuthenticated('admin'); + } +} diff --git a/tests/FileUploadTest.php b/tests/FileUploadTest.php index 32c2a594..947fb130 100644 --- a/tests/FileUploadTest.php +++ b/tests/FileUploadTest.php @@ -1,147 +1,164 @@ be(Administrator::first(), 'admin'); -}); -test('file upload page', function () { - $this->visit('admin/files/create') - ->see('Files') - ->seeInElement('h3[class=box-title]', 'Create') - ->seeElement('input[name=file1]') - ->seeElement('input[name=file2]') - ->seeElement('input[name=file3]') - ->seeElement('input[name=file4]') - ->seeElement('input[name=file5]') - ->seeElement('input[name=file6]') -// ->seeInElement('a[href="/admin/files"]', 'List') - ->seeInElement('button[type=reset]', 'Reset') - ->seeInElement('button[type=submit]', 'Submit'); -}); -function uploadFiles() + +class FileUploadTest extends TestCase { - return $this->visit('admin/files/create') - ->attach(__DIR__.'/AuthTest.php', 'file1') - ->attach(__DIR__.'/InstallTest.php', 'file2') - ->attach(__DIR__.'/IndexTest.php', 'file3') - ->attach(__DIR__.'/LaravelTest.php', 'file4') - ->attach(__DIR__.'/routes.php', 'file5') - ->attach(__DIR__.'/migrations/2016_11_22_093148_create_test_tables.php', 'file6') - ->press('Submit'); -} -test('upload file', function () { - File::cleanDirectory(public_path('uploads/files')); + protected function setUp(): void + { + parent::setUp(); + + $this->be(Administrator::first(), 'admin'); + } + + public function testFileUploadPage() + { + $this->visit('admin/files/create') + ->see('Files') + ->seeInElement('h3[class=box-title]', 'Create') + ->seeElement('input[name=file1]') + ->seeElement('input[name=file2]') + ->seeElement('input[name=file3]') + ->seeElement('input[name=file4]') + ->seeElement('input[name=file5]') + ->seeElement('input[name=file6]') +// ->seeInElement('a[href="/admin/files"]', 'List') + ->seeInElement('button[type=reset]', 'Reset') + ->seeInElement('button[type=submit]', 'Submit'); + } + + protected function uploadFiles() + { + return $this->visit('admin/files/create') + ->attach(__DIR__.'/AuthTest.php', 'file1') + ->attach(__DIR__.'/InstallTest.php', 'file2') + ->attach(__DIR__.'/IndexTest.php', 'file3') + ->attach(__DIR__.'/LaravelTest.php', 'file4') + ->attach(__DIR__.'/routes.php', 'file5') + ->attach(__DIR__.'/migrations/2016_11_22_093148_create_test_tables.php', 'file6') + ->press('Submit'); + } - uploadFiles() - ->seePageIs('admin/files'); + public function testUploadFile() + { + File::cleanDirectory(public_path('uploads/files')); - expect(1)->toEqual(FileModel::count()); + $this->uploadFiles() + ->seePageIs('admin/files'); - $where = [ - 'file1' => 'files/AuthTest.php', - 'file2' => 'files/InstallTest.php', - 'file3' => 'files/IndexTest.php', - 'file4' => 'files/LaravelTest.php', - 'file5' => 'files/routes.php', - 'file6' => 'files/2016_11_22_093148_create_test_tables.php', - ]; + $this->assertEquals(FileModel::count(), 1); - $this->seeInDatabase('test_files', $where); + $where = [ + 'file1' => 'files/AuthTest.php', + 'file2' => 'files/InstallTest.php', + 'file3' => 'files/IndexTest.php', + 'file4' => 'files/LaravelTest.php', + 'file5' => 'files/routes.php', + 'file6' => 'files/2016_11_22_093148_create_test_tables.php', + ]; - $files = FileModel::first()->toArray(); + $this->seeInDatabase('test_files', $where); - foreach (range(1, 6) as $index) { - expect(public_path('uploads/'.$files['file'.$index]))->toBeFile(); + $files = FileModel::first()->toArray(); + + foreach (range(1, 6) as $index) { + $this->assertFileExists(public_path('uploads/'.$files['file'.$index])); + } + + File::cleanDirectory(public_path('uploads/files')); } - File::cleanDirectory(public_path('uploads/files')); -}); -test('update file', function () { - File::cleanDirectory(public_path('uploads/files')); - - uploadFiles(); - - $old = FileModel::first(); - - $this->visit('admin/files/1/edit') - ->see('ID') - ->see('Created At') - ->see('Updated At') - ->seeElement('input[name=file1]') - ->seeElement('input[name=file2]') - ->seeElement('input[name=file3]') - ->seeElement('input[name=file4]') - ->seeElement('input[name=file5]') - ->seeElement('input[name=file6]') + public function testUpdateFile() + { + File::cleanDirectory(public_path('uploads/files')); + + $this->uploadFiles(); + + $old = FileModel::first(); + + $this->visit('admin/files/1/edit') + ->see('ID') + ->see('Created At') + ->see('Updated At') + ->seeElement('input[name=file1]') + ->seeElement('input[name=file2]') + ->seeElement('input[name=file3]') + ->seeElement('input[name=file4]') + ->seeElement('input[name=file5]') + ->seeElement('input[name=file6]') // ->seeInElement('a[href="/admin/files"]', 'List') - ->seeInElement('button[type=reset]', 'Reset') - ->seeInElement('button[type=submit]', 'Submit'); + ->seeInElement('button[type=reset]', 'Reset') + ->seeInElement('button[type=submit]', 'Submit'); - $this->attach(__DIR__.'/RolesTest.php', 'file3') - ->attach(__DIR__.'/MenuTest.php', 'file4') - ->attach(__DIR__.'/TestCase.php', 'file5') - ->press('Submit'); + $this->attach(__DIR__.'/RolesTest.php', 'file3') + ->attach(__DIR__.'/MenuTest.php', 'file4') + ->attach(__DIR__.'/TestCase.php', 'file5') + ->press('Submit'); - $new = FileModel::first(); + $new = FileModel::first(); - expect($new->id)->toEqual($old->id); - expect($new->file1)->toEqual($old->file1); - expect($new->file2)->toEqual($old->file2); - expect($new->file6)->toEqual($old->file6); + $this->assertEquals($old->id, $new->id); + $this->assertEquals($old->file1, $new->file1); + $this->assertEquals($old->file2, $new->file2); + $this->assertEquals($old->file6, $new->file6); - $this->assertNotEquals($old->file3, $new->file3); - $this->assertNotEquals($old->file4, $new->file4); - $this->assertNotEquals($old->file5, $new->file5); + $this->assertNotEquals($old->file3, $new->file3); + $this->assertNotEquals($old->file4, $new->file4); + $this->assertNotEquals($old->file5, $new->file5); - File::cleanDirectory(public_path('uploads/files')); -}); -test('delete files', function () { - File::cleanDirectory(public_path('uploads/files')); + File::cleanDirectory(public_path('uploads/files')); + } + + public function testDeleteFiles() + { + File::cleanDirectory(public_path('uploads/files')); + + $this->uploadFiles(); - uploadFiles(); + $this->visit('admin/files') + ->seeInElement('td', 1); - $this->visit('admin/files') - ->seeInElement('td', 1); + $files = FileModel::first()->toArray(); - $files = FileModel::first()->toArray(); + $this->delete('admin/files/1') + ->dontSeeInDatabase('test_files', ['id' => 1]); - $this->delete('admin/files/1') - ->dontSeeInDatabase('test_files', ['id' => 1]); + foreach (range(1, 6) as $index) { + $this->assertFileDoesNotExist(public_path('uploads/'.$files['file'.$index])); + } - foreach (range(1, 6) as $index) { - $this->assertFileDoesNotExist(public_path('uploads/'.$files['file'.$index])); + $this->visit('admin/files') + ->seeInElement('td', 'svg'); } - $this->visit('admin/files') - ->seeInElement('td', 'svg'); -}); -test('batch delete', function () { - File::cleanDirectory(public_path('uploads/files')); + public function testBatchDelete() + { + File::cleanDirectory(public_path('uploads/files')); - uploadFiles(); - uploadFiles(); - uploadFiles(); + $this->uploadFiles(); + $this->uploadFiles(); + $this->uploadFiles(); - $this->visit('admin/files') - ->seeInElement('td', 1) - ->seeInElement('td', 2) - ->seeInElement('td', 3); + $this->visit('admin/files') + ->seeInElement('td', 1) + ->seeInElement('td', 2) + ->seeInElement('td', 3); - $fi = new FilesystemIterator(public_path('uploads/files'), FilesystemIterator::SKIP_DOTS); + $fi = new FilesystemIterator(public_path('uploads/files'), FilesystemIterator::SKIP_DOTS); - expect(18)->toEqual(iterator_count($fi)); + $this->assertEquals(iterator_count($fi), 18); - expect(3)->toEqual(FileModel::count()); + $this->assertEquals(FileModel::count(), 3); - $this->delete('admin/files/1,2,3'); + $this->delete('admin/files/1,2,3'); - expect(0)->toEqual(FileModel::count()); + $this->assertEquals(FileModel::count(), 0); - $this->visit('admin/files') - ->seeInElement('td', 'svg'); + $this->visit('admin/files') + ->seeInElement('td', 'svg'); - expect(0)->toEqual(iterator_count($fi)); -}); + $this->assertEquals(iterator_count($fi), 0); + } +} diff --git a/tests/ImageUploadTest.php b/tests/ImageUploadTest.php index ab6e9c6e..d96f6ee7 100644 --- a/tests/ImageUploadTest.php +++ b/tests/ImageUploadTest.php @@ -1,211 +1,235 @@ be(Administrator::first(), 'admin'); -}); -test('disable filter', function () { - $this->visit('admin/images') - ->dontSeeElement('input[name=id]'); -}); -test('image upload page', function () { - $this->visit('admin/images/create') - ->see('Images') - ->seeInElement('h3[class=box-title]', 'Create') - ->seeElement('input[name=image1]') - ->seeElement('input[name=image2]') - ->seeElement('input[name=image3]') - ->seeElement('input[name=image4]') - ->seeElement('input[name=image5]') - ->seeElement('input[name=image6]') - ->seeInElement('button[type=reset]', 'Reset') - ->seeInElement('button[type=submit]', 'Submit'); -}); -function uploadImages() + +class ImageUploadTest extends TestCase { -// return $this->visit('admin/images/create') -// ->attach(__DIR__.'/assets/test.jpg', 'image1') -// ->attach(__DIR__.'/assets/test.jpg', 'image2') -// ->attach(__DIR__.'/assets/test.jpg', 'image3') -// ->attach(__DIR__.'/assets/test.jpg', 'image4') -// ->attach(__DIR__.'/assets/test.jpg', 'image5') -// ->attach(__DIR__.'/assets/test.jpg', 'image6') -// ->press('Submit'); -} -test('upload image', function () { - File::cleanDirectory(public_path('uploads/images')); + protected function setUp(): void + { + parent::setUp(); + + $this->be(Administrator::first(), 'admin'); + } + + public function testDisableFilter() + { + $this->visit('admin/images') + ->dontSeeElement('input[name=id]'); + } + + public function testImageUploadPage() + { + $this->visit('admin/images/create') + ->see('Images') + ->seeInElement('h3[class=box-title]', 'Create') + ->seeElement('input[name=image1]') + ->seeElement('input[name=image2]') + ->seeElement('input[name=image3]') + ->seeElement('input[name=image4]') + ->seeElement('input[name=image5]') + ->seeElement('input[name=image6]') + ->seeInElement('button[type=reset]', 'Reset') + ->seeInElement('button[type=submit]', 'Submit'); + } + + protected function uploadImages() + { + return $this->visit('admin/images/create') + ->attach(__DIR__.'/assets/test.jpg', 'image1') + ->attach(__DIR__.'/assets/test.jpg', 'image2') + ->attach(__DIR__.'/assets/test.jpg', 'image3') + ->attach(__DIR__.'/assets/test.jpg', 'image4') + ->attach(__DIR__.'/assets/test.jpg', 'image5') + ->attach(__DIR__.'/assets/test.jpg', 'image6') + ->press('Submit'); + } + + public function testUploadImage() + { + File::cleanDirectory(public_path('uploads/images')); + + $this->uploadImages() + ->seePageIs('admin/images'); - uploadImages() - ->seePageIs('admin/images'); + $this->assertEquals(Image::count(), 1); - expect(1)->toEqual(Image::count()); + $this->seeInDatabase('test_images', ['image4' => 'images/renamed.jpeg']); - $this->seeInDatabase('test_images', ['image4' => 'images/renamed.jpeg']); + $images = Image::first()->toArray(); - $images = Image::first()->toArray(); + foreach (range(1, 6) as $index) { + $this->assertFileExists(public_path('uploads/'.$images['image'.$index])); + } - foreach (range(1, 6) as $index) { - expect(public_path('uploads/'.$images['image'.$index]))->toBeFile(); + $this->assertFileExists(public_path('uploads/images/asdasdasdasdasd.jpeg')); + + File::cleanDirectory(public_path('uploads/images')); } - expect(public_path('uploads/images/asdasdasdasdasd.jpeg'))->toBeFile(); + public function testRemoveImage() + { + File::cleanDirectory(public_path('uploads/images')); + + $this->uploadImages(); + + $this->assertEquals($this->fileCountInImageDir(), 6); + } - File::cleanDirectory(public_path('uploads/images')); -}); -test('remove image', function () { - File::cleanDirectory(public_path('uploads/images')); + public function testUpdateImage() + { + File::cleanDirectory(public_path('uploads/images')); - uploadImages(); + $this->uploadImages(); - expect(6)->toEqual(fileCountInImageDir()); -}); -test('update image', function () { - File::cleanDirectory(public_path('uploads/images')); + $old = Image::first(); - uploadImages(); + $this->visit('admin/images/1/edit') + ->see('ID') + ->see('Created At') + ->see('Updated At') + ->seeElement('input[name=image1]') + ->seeElement('input[name=image2]') + ->seeElement('input[name=image3]') + ->seeElement('input[name=image4]') + ->seeElement('input[name=image5]') + ->seeElement('input[name=image6]') + ->seeInElement('button[type=reset]', 'Reset') + ->seeInElement('button[type=submit]', 'Submit'); - $old = Image::first(); + $this->attach(__DIR__.'/assets/test.jpg', 'image3') + ->attach(__DIR__.'/assets/test.jpg', 'image4') + ->attach(__DIR__.'/assets/test.jpg', 'image5') + ->press('Submit'); - $this->visit('admin/images/1/edit') - ->see('ID') - ->see('Created At') - ->see('Updated At') - ->seeElement('input[name=image1]') - ->seeElement('input[name=image2]') - ->seeElement('input[name=image3]') - ->seeElement('input[name=image4]') - ->seeElement('input[name=image5]') - ->seeElement('input[name=image6]') - ->seeInElement('button[type=reset]', 'Reset') - ->seeInElement('button[type=submit]', 'Submit'); + $new = Image::first(); - $this->attach(__DIR__.'/assets/test.jpg', 'image3') - ->attach(__DIR__.'/assets/test.jpg', 'image4') - ->attach(__DIR__.'/assets/test.jpg', 'image5') - ->press('Submit'); + $this->assertEquals($old->id, $new->id); + $this->assertEquals($old->image1, $new->image1); + $this->assertEquals($old->image2, $new->image2); + $this->assertEquals($old->image6, $new->image6); - $new = Image::first(); + $this->assertNotEquals($old->image3, $new->image3); + $this->assertNotEquals($old->image4, $new->image4); + $this->assertNotEquals($old->image5, $new->image5); - expect($new->id)->toEqual($old->id); - expect($new->image1)->toEqual($old->image1); - expect($new->image2)->toEqual($old->image2); - expect($new->image6)->toEqual($old->image6); + File::cleanDirectory(public_path('uploads/images')); + } - $this->assertNotEquals($old->image3, $new->image3); - $this->assertNotEquals($old->image4, $new->image4); - $this->assertNotEquals($old->image5, $new->image5); + public function testDeleteImages() + { + File::cleanDirectory(public_path('uploads/images')); - File::cleanDirectory(public_path('uploads/images')); -}); -test('delete images', function () { - File::cleanDirectory(public_path('uploads/images')); + $this->uploadImages(); - uploadImages(); + $this->visit('admin/images') + ->seeInElement('td', 1); - $this->visit('admin/images') - ->seeInElement('td', 1); + $images = Image::first()->toArray(); - $images = Image::first()->toArray(); + $this->delete('admin/images/1') + ->dontSeeInDatabase('test_images', ['id' => 1]); - $this->delete('admin/images/1') - ->dontSeeInDatabase('test_images', ['id' => 1]); + foreach (range(1, 6) as $index) { + $this->assertFileDoesNotExist(public_path('uploads/'.$images['image'.$index])); + } - foreach (range(1, 6) as $index) { - $this->assertFileDoesNotExist(public_path('uploads/'.$images['image'.$index])); + $this->visit('admin/images') + ->seeInElement('td', 'svg'); } - $this->visit('admin/images') - ->seeInElement('td', 'svg'); -}); -test('batch delete', function () { - File::cleanDirectory(public_path('uploads/images')); + public function testBatchDelete() + { + File::cleanDirectory(public_path('uploads/images')); + + $this->uploadImages(); + $this->uploadImages(); + $this->uploadImages(); - uploadImages(); - uploadImages(); - uploadImages(); + $this->visit('admin/images') + ->seeInElement('td', 1) + ->seeInElement('td', 2) + ->seeInElement('td', 3); - $this->visit('admin/images') - ->seeInElement('td', 1) - ->seeInElement('td', 2) - ->seeInElement('td', 3); + $this->assertEquals($this->fileCountInImageDir(), 18); - expect(18)->toEqual(fileCountInImageDir()); + $this->assertEquals(Image::count(), 3); - expect(3)->toEqual(Image::count()); + $this->delete('admin/images/1,2,3'); - $this->delete('admin/images/1,2,3'); + $this->assertEquals(Image::count(), 0); - expect(0)->toEqual(Image::count()); + $this->visit('admin/images') + ->seeInElement('td', 'svg'); - $this->visit('admin/images') - ->seeInElement('td', 'svg'); + $this->assertEquals($this->fileCountInImageDir(), 0); + } - expect(0)->toEqual(fileCountInImageDir()); -}); -test('upload multiple image', function () { - File::cleanDirectory(public_path('uploads/images')); + public function testUploadMultipleImage() + { + File::cleanDirectory(public_path('uploads/images')); - $this->visit('admin/multiple-images/create') - ->seeElement('input[type=file][name="pictures[]"][multiple]'); + $this->visit('admin/multiple-images/create') + ->seeElement('input[type=file][name="pictures[]"][multiple]'); - $path = __DIR__.'/assets/test.jpg'; + $path = __DIR__.'/assets/test.jpg'; - $file = new \Illuminate\Http\UploadedFile($path, 'test.jpg', 'image/jpeg', null, true); + $file = new \Illuminate\Http\UploadedFile($path, 'test.jpg', 'image/jpeg', null, true); - $size = rand(10, 20); - $files = ['pictures' => array_pad([], $size, $file)]; + $size = rand(10, 20); + $files = ['pictures' => array_pad([], $size, $file)]; - $this->call( - 'POST', // $method - '/admin/multiple-images', // $action - [], // $parameters - [], - $files - ); + $this->call( + 'POST', // $method + '/admin/multiple-images', // $action + [], // $parameters + [], + $files + ); - $this->assertResponseStatus(302); - $this->assertRedirectedTo('/admin/multiple-images'); + $this->assertResponseStatus(302); + $this->assertRedirectedTo('/admin/multiple-images'); - expect($size)->toEqual(fileCountInImageDir()); + $this->assertEquals($this->fileCountInImageDir(), $size); - $pictures = MultipleImage::first()->pictures; + $pictures = MultipleImage::first()->pictures; - expect($pictures)->toHaveCount($size); + $this->assertCount($size, $pictures); - foreach ($pictures as $picture) { - expect(public_path('uploads/'.$picture))->toBeFile(); + foreach ($pictures as $picture) { + $this->assertFileExists(public_path('uploads/'.$picture)); + } } -}); -test('remove multiple files', function () { - File::cleanDirectory(public_path('uploads/images')); - // upload files - $path = __DIR__.'/assets/test.jpg'; + public function testRemoveMultipleFiles() + { + File::cleanDirectory(public_path('uploads/images')); - $file = new \Illuminate\Http\UploadedFile($path, 'test.jpg', 'image/jpeg', null, true); + // upload files + $path = __DIR__.'/assets/test.jpg'; - $size = rand(10, 20); - $files = ['pictures' => array_pad([], $size, $file)]; + $file = new \Illuminate\Http\UploadedFile($path, 'test.jpg', 'image/jpeg', null, true); - $this->call( - 'POST', // $method - '/admin/multiple-images', // $action - [], // $parameters - [], - $files - ); + $size = rand(10, 20); + $files = ['pictures' => array_pad([], $size, $file)]; - expect($size)->toEqual(fileCountInImageDir()); -}); -function fileCountInImageDir($dir = 'uploads/images') -{ - $file = new FilesystemIterator(public_path($dir), FilesystemIterator::SKIP_DOTS); + $this->call( + 'POST', // $method + '/admin/multiple-images', // $action + [], // $parameters + [], + $files + ); + + $this->assertEquals($this->fileCountInImageDir(), $size); + } + + protected function fileCountInImageDir($dir = 'uploads/images') + { + $file = new FilesystemIterator(public_path($dir), FilesystemIterator::SKIP_DOTS); - return iterator_count($file); + return iterator_count($file); + } } diff --git a/tests/IndexTest.php b/tests/IndexTest.php index 1406ceee..6ff03b04 100644 --- a/tests/IndexTest.php +++ b/tests/IndexTest.php @@ -1,39 +1,49 @@ be(Administrator::first(), 'admin'); -}); -test('index', function () { - $this->visit('admin/') - ->see('Dashboard') - ->see('Description...') - - ->see('Environment') - ->see('PHP version') - ->see('Laravel version') - - ->see('Available extensions') - ->seeLink('laravel-admin-ext/helpers', 'https://github.com/laravel-admin-extensions/helpers') - ->seeLink('laravel-admin-ext/backup', 'https://github.com/laravel-admin-extensions/backup') - ->seeLink('laravel-admin-ext/media-manager', 'https://github.com/laravel-admin-extensions/media-manager') - - ->see('Dependencies') - ->see('php') +use OpenAdmin\Admin\Auth\Database\Administrator; + +class IndexTest extends TestCase +{ + protected function setUp(): void + { + parent::setUp(); + + $this->be(Administrator::first(), 'admin'); + } + + public function testIndex() + { + $this->visit('admin/') + ->see('Dashboard') + ->see('Description...') + + ->see('Environment') + ->see('PHP version') + ->see('Laravel version') + + ->see('Available extensions') + ->seeLink('open-admin-ext/helpers', 'https://github.com/open-admin-extensions/helpers') + ->seeLink('open-admin-ext/backup', 'https://github.com/open-admin-extensions/backup') + ->seeLink('open-admin-ext/media-manager', 'https://github.com/open-admin-extensions/media-manager') + + ->see('Dependencies') + ->see('php') // ->see('>=7.0.0') - ->see('laravel/framework'); -}); -test('click menu', function () { - $this->visit('admin/') - ->click('Users') - ->seePageis('admin/auth/users') - ->click('Roles') - ->seePageis('admin/auth/roles') - ->click('Permission') - ->seePageis('admin/auth/permissions') - ->click('Menu') - ->seePageis('admin/auth/menu') - ->click('Operation log') - ->seePageis('admin/auth/logs'); -}); + ->see('laravel/framework'); + } + + public function testClickMenu() + { + $this->visit('admin/') + ->click('Users') + ->seePageis('admin/auth/users') + ->click('Roles') + ->seePageis('admin/auth/roles') + ->click('Permission') + ->seePageis('admin/auth/permissions') + ->click('Menu') + ->seePageis('admin/auth/menu') + ->click('Operation log') + ->seePageis('admin/auth/logs'); + } +} diff --git a/tests/InstallTest.php b/tests/InstallTest.php index f21427ea..ec451562 100644 --- a/tests/InstallTest.php +++ b/tests/InstallTest.php @@ -1,22 +1,25 @@ toBeFile(); +class InstallTest extends TestCase +{ + public function testInstalledDirectories() + { + $this->assertFileExists(admin_path()); - expect(admin_path('Controllers'))->toBeFile(); + $this->assertFileExists(admin_path('Controllers')); - expect(admin_path('routes.php'))->toBeFile(); + $this->assertFileExists(admin_path('routes.php')); - expect(admin_path('bootstrap.php'))->toBeFile(); + $this->assertFileExists(admin_path('bootstrap.php')); - expect(admin_path('Controllers/HomeController.php'))->toBeFile(); + $this->assertFileExists(admin_path('Controllers/HomeController.php')); - expect(admin_path('Controllers/AuthController.php'))->toBeFile(); + $this->assertFileExists(admin_path('Controllers/AuthController.php')); - expect(admin_path('Controllers/ExampleController.php'))->toBeFile(); + $this->assertFileExists(admin_path('Controllers/ExampleController.php')); - expect(config_path('admin.php'))->toBeFile(); + $this->assertFileExists(config_path('admin.php')); - expect(public_path('vendor/laravel-admin'))->toBeFile(); -}); + $this->assertFileExists(public_path('vendor/open-admin')); + } +} diff --git a/tests/LaravelTest.php b/tests/LaravelTest.php index 42f58b11..541521c9 100644 --- a/tests/LaravelTest.php +++ b/tests/LaravelTest.php @@ -1,8 +1,11 @@ visit('/') - ->assertResponseStatus(200) - ->see('Laravel'); -}); +class LaravelTest extends TestCase +{ + public function testLaravel() + { + $this->visit('/') + ->assertResponseStatus(200) + ->see('Laravel'); + } +} diff --git a/tests/MenuTest.php b/tests/MenuTest.php index 482aa2ba..e78675a1 100644 --- a/tests/MenuTest.php +++ b/tests/MenuTest.php @@ -1,58 +1,76 @@ be(Administrator::first(), 'admin'); -}); -test('menu index', function () { - $this->visit('admin/auth/menu') - ->see('Menu') - ->see('Index') - ->see('Auth') - ->see('Users') - ->see('Roles') - ->see('Permission') - ->see('Menu'); -}); -test('add menu', function () { - $item = ['parent_id' => '0', 'title' => 'Test', 'uri' => 'test']; - - $this->visit('admin/auth/menu') - ->seePageIs('admin/auth/menu') - ->see('Menu') - ->submitForm('Submit', $item) - ->seePageIs('admin/auth/menu') - ->seeInDatabase(config('admin.database.menu_table'), $item) - ->assertEquals(8, Menu::count()); - - // $this->expectException(\Laravel\BrowserKitTesting\HttpException::class); - // - // $this->visit('admin') - // ->see('Test') - // ->click('Test'); -}); -test('delete menu', function () { - $this->delete('admin/auth/menu/8') - ->assertEquals(7, Menu::count()); -}); -test('edit menu', function () { - $this->visit('admin/auth/menu/1/edit') - ->see('Menu') - ->submitForm('Submit', ['title' => 'blablabla']) - ->seePageIs('admin/auth/menu') - ->seeInDatabase(config('admin.database.menu_table'), ['title' => 'blablabla']) - ->assertEquals(7, Menu::count()); -}); -test('show page', function () { - $this->visit('admin/auth/menu/1/edit') - ->seePageIs('admin/auth/menu/1/edit'); -}); -test('edit menu parent', function () { - $this->expectException(\Laravel\BrowserKitTesting\HttpException::class); - - $this->visit('admin/auth/menu/5/edit') - ->see('Menu') - ->submitForm('Submit', ['parent_id' => 5]); -}); +use OpenAdmin\Admin\Auth\Database\Administrator; +use OpenAdmin\Admin\Auth\Database\Menu; + +class MenuTest extends TestCase +{ + protected function setUp(): void + { + parent::setUp(); + + $this->be(Administrator::first(), 'admin'); + } + + public function testMenuIndex() + { + $this->visit('admin/auth/menu') + ->see('Menu') + ->see('Index') + ->see('Auth') + ->see('Users') + ->see('Roles') + ->see('Permission') + ->see('Menu'); + } + + public function testAddMenu() + { + $item = ['parent_id' => '0', 'title' => 'Test', 'uri' => 'test']; + + $this->visit('admin/auth/menu') + ->seePageIs('admin/auth/menu') + ->see('Menu') + ->submitForm('Submit', $item) + ->seePageIs('admin/auth/menu') + ->seeInDatabase(config('admin.database.menu_table'), $item) + ->assertEquals(8, Menu::count()); + +// $this->expectException(\Laravel\BrowserKitTesting\HttpException::class); +// +// $this->visit('admin') +// ->see('Test') +// ->click('Test'); + } + + public function testDeleteMenu() + { + $this->delete('admin/auth/menu/8') + ->assertEquals(7, Menu::count()); + } + + public function testEditMenu() + { + $this->visit('admin/auth/menu/1/edit') + ->see('Menu') + ->submitForm('Submit', ['title' => 'blablabla']) + ->seePageIs('admin/auth/menu') + ->seeInDatabase(config('admin.database.menu_table'), ['title' => 'blablabla']) + ->assertEquals(7, Menu::count()); + } + + public function testShowPage() + { + $this->visit('admin/auth/menu/1/edit') + ->seePageIs('admin/auth/menu/1/edit'); + } + + public function testEditMenuParent() + { + $this->expectException(\Laravel\BrowserKitTesting\HttpException::class); + + $this->visit('admin/auth/menu/5/edit') + ->see('Menu') + ->submitForm('Submit', ['parent_id' => 5]); + } +} diff --git a/tests/ModelTreeTest.php b/tests/ModelTreeTest.php index 2c35e653..0bed689b 100644 --- a/tests/ModelTreeTest.php +++ b/tests/ModelTreeTest.php @@ -1,18 +1,25 @@ where('uri', ''); - }, $rootText); +class ModelTreeTest extends TestCase +{ + protected function setUp(): void + { + parent::setUp(); + } - $count = Tree::query()->where('uri', '')->count(); + public function testSelectOptions() + { + $rootText = 'Root Text'; - expect($rootText)->toEqual(array_shift($options)); - expect($count)->toEqual(count($options)); -}); + $options = Tree::selectOptions(function ($query) { + return $query->where('uri', ''); + }, $rootText); + + $count = Tree::query()->where('uri', '')->count(); + + $this->assertEquals(array_shift($options), $rootText); + $this->assertEquals(count($options), $count); + } +} diff --git a/tests/OperationLogTest.php b/tests/OperationLogTest.php index 8c0530b1..738a00b7 100644 --- a/tests/OperationLogTest.php +++ b/tests/OperationLogTest.php @@ -1,70 +1,84 @@ be(Administrator::first(), 'admin'); -}); -test('operation log index', function () { - $this->visit('admin/auth/logs') - ->see('Operation log') - ->see('List') - ->see('GET') - ->see('admin/auth/logs'); -}); -test('generate logs', function () { - $table = config('admin.database.operation_log_table'); - - $this->visit('admin/auth/menu') - ->seePageIs('admin/auth/menu') - ->visit('admin/auth/users') - ->seePageIs('admin/auth/users') - ->visit('admin/auth/permissions') - ->seePageIs('admin/auth/permissions') - ->visit('admin/auth/roles') - ->seePageIs('admin/auth/roles') - ->visit('admin/auth/logs') - ->seePageIs('admin/auth/logs') - ->seeInDatabase($table, ['path' => 'admin/auth/menu', 'method' => 'GET']) - ->seeInDatabase($table, ['path' => 'admin/auth/users', 'method' => 'GET']) - ->seeInDatabase($table, ['path' => 'admin/auth/permissions', 'method' => 'GET']) - ->seeInDatabase($table, ['path' => 'admin/auth/roles', 'method' => 'GET']); - - expect(OperationLog::count())->toEqual(4); -}); -test('delete logs', function () { - $table = config('admin.database.operation_log_table'); - - $this->visit('admin/auth/logs') - ->seePageIs('admin/auth/logs') - ->assertEquals(0, OperationLog::count()); - - $this->visit('admin/auth/users'); - - $this->seeInDatabase($table, ['path' => 'admin/auth/users', 'method' => 'GET']); - - $this->delete('admin/auth/logs/1') - ->assertEquals(0, OperationLog::count()); -}); -test('delete multiple logs', function () { - $table = config('admin.database.operation_log_table'); - - $this->visit('admin/auth/menu') - ->visit('admin/auth/users') - ->visit('admin/auth/permissions') - ->visit('admin/auth/roles') - ->seeInDatabase($table, ['path' => 'admin/auth/menu', 'method' => 'GET']) - ->seeInDatabase($table, ['path' => 'admin/auth/users', 'method' => 'GET']) - ->seeInDatabase($table, ['path' => 'admin/auth/permissions', 'method' => 'GET']) - ->seeInDatabase($table, ['path' => 'admin/auth/roles', 'method' => 'GET']) - ->assertEquals(4, OperationLog::count()); - - $this->delete('admin/auth/logs/1,2,3,4') - ->notSeeInDatabase($table, ['path' => 'admin/auth/menu', 'method' => 'GET']) - ->notSeeInDatabase($table, ['path' => 'admin/auth/users', 'method' => 'GET']) - ->notSeeInDatabase($table, ['path' => 'admin/auth/permissions', 'method' => 'GET']) - ->notSeeInDatabase($table, ['path' => 'admin/auth/roles', 'method' => 'GET']) - - ->assertEquals(0, OperationLog::count()); -}); +use OpenAdmin\Admin\Auth\Database\Administrator; +use OpenAdmin\Admin\Auth\Database\OperationLog; + +class OperationLogTest extends TestCase +{ + protected function setUp(): void + { + parent::setUp(); + + $this->be(Administrator::first(), 'admin'); + } + + public function testOperationLogIndex() + { + $this->visit('admin/auth/logs') + ->see('Operation log') + ->see('List') + ->see('GET') + ->see('admin/auth/logs'); + } + + public function testGenerateLogs() + { + $table = config('admin.database.operation_log_table'); + + $this->visit('admin/auth/menu') + ->seePageIs('admin/auth/menu') + ->visit('admin/auth/users') + ->seePageIs('admin/auth/users') + ->visit('admin/auth/permissions') + ->seePageIs('admin/auth/permissions') + ->visit('admin/auth/roles') + ->seePageIs('admin/auth/roles') + ->visit('admin/auth/logs') + ->seePageIs('admin/auth/logs') + ->seeInDatabase($table, ['path' => 'admin/auth/menu', 'method' => 'GET']) + ->seeInDatabase($table, ['path' => 'admin/auth/users', 'method' => 'GET']) + ->seeInDatabase($table, ['path' => 'admin/auth/permissions', 'method' => 'GET']) + ->seeInDatabase($table, ['path' => 'admin/auth/roles', 'method' => 'GET']); + + $this->assertEquals(4, OperationLog::count()); + } + + public function testDeleteLogs() + { + $table = config('admin.database.operation_log_table'); + + $this->visit('admin/auth/logs') + ->seePageIs('admin/auth/logs') + ->assertEquals(0, OperationLog::count()); + + $this->visit('admin/auth/users'); + + $this->seeInDatabase($table, ['path' => 'admin/auth/users', 'method' => 'GET']); + + $this->delete('admin/auth/logs/1') + ->assertEquals(0, OperationLog::count()); + } + + public function testDeleteMultipleLogs() + { + $table = config('admin.database.operation_log_table'); + + $this->visit('admin/auth/menu') + ->visit('admin/auth/users') + ->visit('admin/auth/permissions') + ->visit('admin/auth/roles') + ->seeInDatabase($table, ['path' => 'admin/auth/menu', 'method' => 'GET']) + ->seeInDatabase($table, ['path' => 'admin/auth/users', 'method' => 'GET']) + ->seeInDatabase($table, ['path' => 'admin/auth/permissions', 'method' => 'GET']) + ->seeInDatabase($table, ['path' => 'admin/auth/roles', 'method' => 'GET']) + ->assertEquals(4, OperationLog::count()); + + $this->delete('admin/auth/logs/1,2,3,4') + ->notSeeInDatabase($table, ['path' => 'admin/auth/menu', 'method' => 'GET']) + ->notSeeInDatabase($table, ['path' => 'admin/auth/users', 'method' => 'GET']) + ->notSeeInDatabase($table, ['path' => 'admin/auth/permissions', 'method' => 'GET']) + ->notSeeInDatabase($table, ['path' => 'admin/auth/roles', 'method' => 'GET']) + + ->assertEquals(0, OperationLog::count()); + } +} diff --git a/tests/PermissionsTest.php b/tests/PermissionsTest.php index 90db02a2..e31b4724 100644 --- a/tests/PermissionsTest.php +++ b/tests/PermissionsTest.php @@ -1,194 +1,214 @@ be(Administrator::first(), 'admin'); -}); -test('permissions index', function () { - expect(Administrator::first()->isAdministrator())->toBeTrue(); - - $this->visit('admin/auth/permissions') - ->see('Permissions'); -}); -test('add and delete permissions', function () { - $this->visit('admin/auth/permissions/create') - ->see('Permissions') - ->submitForm('Submit', ['slug' => 'can-edit', 'name' => 'Can edit', 'http_path' => 'users/1/edit', 'http_method' => ['GET']]) - ->seePageIs('admin/auth/permissions') - ->visit('admin/auth/permissions/create') - ->see('Permissions') - ->submitForm('Submit', ['slug' => 'can-delete', 'name' => 'Can delete', 'http_path' => 'users/1', 'http_method' => ['DELETE']]) - ->seePageIs('admin/auth/permissions') - ->seeInDatabase(config('admin.database.permissions_table'), ['slug' => 'can-edit', 'name' => 'Can edit', 'http_path' => 'users/1/edit', 'http_method' => 'GET']) - ->seeInDatabase(config('admin.database.permissions_table'), ['slug' => 'can-delete', 'name' => 'Can delete', 'http_path' => 'users/1', 'http_method' => 'DELETE']) - ->assertEquals(7, Permission::count()); - - expect(Administrator::first()->can('can-edit'))->toBeTrue(); - expect(Administrator::first()->can('can-delete'))->toBeTrue(); - - $this->delete('admin/auth/permissions/6') - ->assertEquals(6, Permission::count()); - - $this->delete('admin/auth/permissions/7') - ->assertEquals(5, Permission::count()); -}); -test('add permission to role', function () { - $this->visit('admin/auth/permissions/create') - ->see('Permissions') - ->submitForm('Submit', ['slug' => 'can-create', 'name' => 'Can Create', 'http_path' => 'users/create', 'http_method' => ['GET']]) - ->seePageIs('admin/auth/permissions'); - - expect(Permission::count())->toEqual(6); - - $this->visit('admin/auth/roles/1/edit') - ->see('Edit') - ->submitForm('Submit', ['permissions' => [1]]) - ->seePageIs('admin/auth/roles') - ->seeInDatabase(config('admin.database.role_permissions_table'), ['role_id' => 1, 'permission_id' => 1]); -}); -test('add permission to user', function () { - $this->visit('admin/auth/permissions/create') - ->see('Permissions') - ->submitForm('Submit', ['slug' => 'can-create', 'name' => 'Can Create', 'http_path' => 'users/create', 'http_method' => ['GET']]) - ->seePageIs('admin/auth/permissions'); - - expect(Permission::count())->toEqual(6); - - $this->visit('admin/auth/users/1/edit') - ->see('Edit') - ->submitForm('Submit', ['permissions' => [1], 'roles' => [1]]) - ->seePageIs('admin/auth/users') - ->seeInDatabase(config('admin.database.user_permissions_table'), ['user_id' => 1, 'permission_id' => 1]) - ->seeInDatabase(config('admin.database.role_users_table'), ['user_id' => 1, 'role_id' => 1]); -}); -test('add user and assign permission', function () { - $user = [ - 'username' => 'Test', - 'name' => 'Name', - 'password' => '123456', - 'password_confirmation' => '123456', - ]; - - $this->visit('admin/auth/users/create') - ->see('Create') - ->submitForm('Submit', $user) - ->seePageIs('admin/auth/users') - ->seeInDatabase(config('admin.database.users_table'), ['username' => 'Test']); - - expect(Administrator::find(2)->isAdministrator())->toBeFalse(); - - $this->visit('admin/auth/permissions/create') - ->see('Permissions') - ->submitForm('Submit', ['slug' => 'can-update', 'name' => 'Can Update', 'http_path' => 'users/*/edit', 'http_method' => ['GET']]) - ->seePageIs('admin/auth/permissions'); - - expect(Permission::count())->toEqual(6); - - $this->visit('admin/auth/permissions/create') - ->see('Permissions') - ->submitForm('Submit', ['slug' => 'can-remove', 'name' => 'Can Remove', 'http_path' => 'users/*', 'http_method' => ['DELETE']]) - ->seePageIs('admin/auth/permissions'); - - expect(Permission::count())->toEqual(7); - - $this->visit('admin/auth/users/2/edit') - ->see('Edit') - ->submitForm('Submit', ['permissions' => [6]]) - ->seePageIs('admin/auth/users') - ->seeInDatabase(config('admin.database.user_permissions_table'), ['user_id' => 2, 'permission_id' => 6]); - - expect(Administrator::find(2)->can('can-update'))->toBeTrue(); - expect(Administrator::find(2)->cannot('can-remove'))->toBeTrue(); - - $this->visit('admin/auth/users/2/edit') - ->see('Edit') - ->submitForm('Submit', ['permissions' => [7]]) - ->seePageIs('admin/auth/users') - ->seeInDatabase(config('admin.database.user_permissions_table'), ['user_id' => 2, 'permission_id' => 7]); - - expect(Administrator::find(2)->can('can-remove'))->toBeTrue(); - - $this->visit('admin/auth/users/2/edit') - ->see('Edit') - ->submitForm('Submit', ['permissions' => []]) - ->seePageIs('admin/auth/users') - ->missingFromDatabase(config('admin.database.user_permissions_table'), ['user_id' => 2, 'permission_id' => 6]) - ->missingFromDatabase(config('admin.database.user_permissions_table'), ['user_id' => 2, 'permission_id' => 7]); - - expect(Administrator::find(2)->cannot('can-update'))->toBeTrue(); - expect(Administrator::find(2)->cannot('can-remove'))->toBeTrue(); -}); -test('permission through role', function () { - $user = [ - 'username' => 'Test', - 'name' => 'Name', - 'password' => '123456', - 'password_confirmation' => '123456', - ]; - - // 1.add a user - $this->visit('admin/auth/users/create') - ->see('Create') - ->submitForm('Submit', $user) - ->seePageIs('admin/auth/users') - ->seeInDatabase(config('admin.database.users_table'), ['username' => 'Test']); - - expect(Administrator::find(2)->isAdministrator())->toBeFalse(); - - // 2.add a role - $this->visit('admin/auth/roles/create') - ->see('Roles') - ->submitForm('Submit', ['slug' => 'developer', 'name' => 'Developer...']) - ->seePageIs('admin/auth/roles') - ->seeInDatabase(config('admin.database.roles_table'), ['slug' => 'developer', 'name' => 'Developer...']) - ->assertEquals(2, Role::count()); - - expect(Administrator::find(2)->isRole('developer'))->toBeFalse(); - - // 3.assign role to user - $this->visit('admin/auth/users/2/edit') - ->see('Edit') - ->submitForm('Submit', ['roles' => [2]]) - ->seePageIs('admin/auth/users') - ->seeInDatabase(config('admin.database.role_users_table'), ['user_id' => 2, 'role_id' => 2]); - - expect(Administrator::find(2)->isRole('developer'))->toBeTrue(); - - // 4.add a permission - $this->visit('admin/auth/permissions/create') - ->see('Permissions') - ->submitForm('Submit', ['slug' => 'can-remove', 'name' => 'Can Remove', 'http_path' => 'users/*', 'http_method' => ['DELETE']]) - ->seePageIs('admin/auth/permissions'); - - expect(Permission::count())->toEqual(6); - - expect(Administrator::find(2)->cannot('can-remove'))->toBeTrue(); - - // 5.assign permission to role - $this->visit('admin/auth/roles/2/edit') - ->see('Edit') - ->submitForm('Submit', ['permissions' => [6]]) - ->seePageIs('admin/auth/roles') - ->seeInDatabase(config('admin.database.role_permissions_table'), ['role_id' => 2, 'permission_id' => 6]); - - expect(Administrator::find(2)->can('can-remove'))->toBeTrue(); -}); -test('edit permission', function () { - $this->visit('admin/auth/permissions/create') - ->see('Permissions') - ->submitForm('Submit', ['slug' => 'can-edit', 'name' => 'Can edit', 'http_path' => 'users/1/edit', 'http_method' => ['GET']]) - ->seePageIs('admin/auth/permissions') - ->seeInDatabase(config('admin.database.permissions_table'), ['slug' => 'can-edit']) - ->seeInDatabase(config('admin.database.permissions_table'), ['name' => 'Can edit']) - ->assertEquals(6, Permission::count()); - - $this->visit('admin/auth/permissions/1/edit') - ->see('Permissions') - ->submitForm('Submit', ['slug' => 'can-delete']) - ->seePageIs('admin/auth/permissions') - ->seeInDatabase(config('admin.database.permissions_table'), ['slug' => 'can-delete']) - ->assertEquals(6, Permission::count()); -}); +use OpenAdmin\Admin\Auth\Database\Administrator; +use OpenAdmin\Admin\Auth\Database\Permission; +use OpenAdmin\Admin\Auth\Database\Role; + +class PermissionsTest extends TestCase +{ + protected function setUp(): void + { + parent::setUp(); + + $this->be(Administrator::first(), 'admin'); + } + + public function testPermissionsIndex() + { + $this->assertTrue(Administrator::first()->isAdministrator()); + + $this->visit('admin/auth/permissions') + ->see('Permissions'); + } + + public function testAddAndDeletePermissions() + { + $this->visit('admin/auth/permissions/create') + ->see('Permissions') + ->submitForm('Submit', ['slug' => 'can-edit', 'name' => 'Can edit', 'http_path' => 'users/1/edit', 'http_method' => ['GET']]) + ->seePageIs('admin/auth/permissions') + ->visit('admin/auth/permissions/create') + ->see('Permissions') + ->submitForm('Submit', ['slug' => 'can-delete', 'name' => 'Can delete', 'http_path' => 'users/1', 'http_method' => ['DELETE']]) + ->seePageIs('admin/auth/permissions') + ->seeInDatabase(config('admin.database.permissions_table'), ['slug' => 'can-edit', 'name' => 'Can edit', 'http_path' => 'users/1/edit', 'http_method' => 'GET']) + ->seeInDatabase(config('admin.database.permissions_table'), ['slug' => 'can-delete', 'name' => 'Can delete', 'http_path' => 'users/1', 'http_method' => 'DELETE']) + ->assertEquals(7, Permission::count()); + + $this->assertTrue(Administrator::first()->can('can-edit')); + $this->assertTrue(Administrator::first()->can('can-delete')); + + $this->delete('admin/auth/permissions/6') + ->assertEquals(6, Permission::count()); + + $this->delete('admin/auth/permissions/7') + ->assertEquals(5, Permission::count()); + } + + public function testAddPermissionToRole() + { + $this->visit('admin/auth/permissions/create') + ->see('Permissions') + ->submitForm('Submit', ['slug' => 'can-create', 'name' => 'Can Create', 'http_path' => 'users/create', 'http_method' => ['GET']]) + ->seePageIs('admin/auth/permissions'); + + $this->assertEquals(6, Permission::count()); + + $this->visit('admin/auth/roles/1/edit') + ->see('Edit') + ->submitForm('Submit', ['permissions' => [1]]) + ->seePageIs('admin/auth/roles') + ->seeInDatabase(config('admin.database.role_permissions_table'), ['role_id' => 1, 'permission_id' => 1]); + } + + public function testAddPermissionToUser() + { + $this->visit('admin/auth/permissions/create') + ->see('Permissions') + ->submitForm('Submit', ['slug' => 'can-create', 'name' => 'Can Create', 'http_path' => 'users/create', 'http_method' => ['GET']]) + ->seePageIs('admin/auth/permissions'); + + $this->assertEquals(6, Permission::count()); + + $this->visit('admin/auth/users/1/edit') + ->see('Edit') + ->submitForm('Submit', ['permissions' => [1], 'roles' => [1]]) + ->seePageIs('admin/auth/users') + ->seeInDatabase(config('admin.database.user_permissions_table'), ['user_id' => 1, 'permission_id' => 1]) + ->seeInDatabase(config('admin.database.role_users_table'), ['user_id' => 1, 'role_id' => 1]); + } + + public function testAddUserAndAssignPermission() + { + $user = [ + 'username' => 'Test', + 'name' => 'Name', + 'password' => '123456', + 'password_confirmation' => '123456', + ]; + + $this->visit('admin/auth/users/create') + ->see('Create') + ->submitForm('Submit', $user) + ->seePageIs('admin/auth/users') + ->seeInDatabase(config('admin.database.users_table'), ['username' => 'Test']); + + $this->assertFalse(Administrator::find(2)->isAdministrator()); + + $this->visit('admin/auth/permissions/create') + ->see('Permissions') + ->submitForm('Submit', ['slug' => 'can-update', 'name' => 'Can Update', 'http_path' => 'users/*/edit', 'http_method' => ['GET']]) + ->seePageIs('admin/auth/permissions'); + + $this->assertEquals(6, Permission::count()); + + $this->visit('admin/auth/permissions/create') + ->see('Permissions') + ->submitForm('Submit', ['slug' => 'can-remove', 'name' => 'Can Remove', 'http_path' => 'users/*', 'http_method' => ['DELETE']]) + ->seePageIs('admin/auth/permissions'); + + $this->assertEquals(7, Permission::count()); + + $this->visit('admin/auth/users/2/edit') + ->see('Edit') + ->submitForm('Submit', ['permissions' => [6]]) + ->seePageIs('admin/auth/users') + ->seeInDatabase(config('admin.database.user_permissions_table'), ['user_id' => 2, 'permission_id' => 6]); + + $this->assertTrue(Administrator::find(2)->can('can-update')); + $this->assertTrue(Administrator::find(2)->cannot('can-remove')); + + $this->visit('admin/auth/users/2/edit') + ->see('Edit') + ->submitForm('Submit', ['permissions' => [7]]) + ->seePageIs('admin/auth/users') + ->seeInDatabase(config('admin.database.user_permissions_table'), ['user_id' => 2, 'permission_id' => 7]); + + $this->assertTrue(Administrator::find(2)->can('can-remove')); + + $this->visit('admin/auth/users/2/edit') + ->see('Edit') + ->submitForm('Submit', ['permissions' => []]) + ->seePageIs('admin/auth/users') + ->missingFromDatabase(config('admin.database.user_permissions_table'), ['user_id' => 2, 'permission_id' => 6]) + ->missingFromDatabase(config('admin.database.user_permissions_table'), ['user_id' => 2, 'permission_id' => 7]); + + $this->assertTrue(Administrator::find(2)->cannot('can-update')); + $this->assertTrue(Administrator::find(2)->cannot('can-remove')); + } + + public function testPermissionThroughRole() + { + $user = [ + 'username' => 'Test', + 'name' => 'Name', + 'password' => '123456', + 'password_confirmation' => '123456', + ]; + + // 1.add a user + $this->visit('admin/auth/users/create') + ->see('Create') + ->submitForm('Submit', $user) + ->seePageIs('admin/auth/users') + ->seeInDatabase(config('admin.database.users_table'), ['username' => 'Test']); + + $this->assertFalse(Administrator::find(2)->isAdministrator()); + + // 2.add a role + $this->visit('admin/auth/roles/create') + ->see('Roles') + ->submitForm('Submit', ['slug' => 'developer', 'name' => 'Developer...']) + ->seePageIs('admin/auth/roles') + ->seeInDatabase(config('admin.database.roles_table'), ['slug' => 'developer', 'name' => 'Developer...']) + ->assertEquals(2, Role::count()); + + $this->assertFalse(Administrator::find(2)->isRole('developer')); + + // 3.assign role to user + $this->visit('admin/auth/users/2/edit') + ->see('Edit') + ->submitForm('Submit', ['roles' => [2]]) + ->seePageIs('admin/auth/users') + ->seeInDatabase(config('admin.database.role_users_table'), ['user_id' => 2, 'role_id' => 2]); + + $this->assertTrue(Administrator::find(2)->isRole('developer')); + + // 4.add a permission + $this->visit('admin/auth/permissions/create') + ->see('Permissions') + ->submitForm('Submit', ['slug' => 'can-remove', 'name' => 'Can Remove', 'http_path' => 'users/*', 'http_method' => ['DELETE']]) + ->seePageIs('admin/auth/permissions'); + + $this->assertEquals(6, Permission::count()); + + $this->assertTrue(Administrator::find(2)->cannot('can-remove')); + + // 5.assign permission to role + $this->visit('admin/auth/roles/2/edit') + ->see('Edit') + ->submitForm('Submit', ['permissions' => [6]]) + ->seePageIs('admin/auth/roles') + ->seeInDatabase(config('admin.database.role_permissions_table'), ['role_id' => 2, 'permission_id' => 6]); + + $this->assertTrue(Administrator::find(2)->can('can-remove')); + } + + public function testEditPermission() + { + $this->visit('admin/auth/permissions/create') + ->see('Permissions') + ->submitForm('Submit', ['slug' => 'can-edit', 'name' => 'Can edit', 'http_path' => 'users/1/edit', 'http_method' => ['GET']]) + ->seePageIs('admin/auth/permissions') + ->seeInDatabase(config('admin.database.permissions_table'), ['slug' => 'can-edit']) + ->seeInDatabase(config('admin.database.permissions_table'), ['name' => 'Can edit']) + ->assertEquals(6, Permission::count()); + + $this->visit('admin/auth/permissions/1/edit') + ->see('Permissions') + ->submitForm('Submit', ['slug' => 'can-delete']) + ->seePageIs('admin/auth/permissions') + ->seeInDatabase(config('admin.database.permissions_table'), ['slug' => 'can-delete']) + ->assertEquals(6, Permission::count()); + } +} diff --git a/tests/RolesTest.php b/tests/RolesTest.php index d2b1b010..e3f359c0 100644 --- a/tests/RolesTest.php +++ b/tests/RolesTest.php @@ -1,89 +1,105 @@ be(Administrator::first(), 'admin'); -}); -test('roles index', function () { - $this->visit('admin/auth/roles') - ->see('Roles') - ->see('administrator'); -}); -test('add role', function () { - $this->visit('admin/auth/roles/create') - ->see('Roles') - ->submitForm('Submit', ['slug' => 'developer', 'name' => 'Developer...']) - ->seePageIs('admin/auth/roles') - ->seeInDatabase(config('admin.database.roles_table'), ['slug' => 'developer', 'name' => 'Developer...']) - ->assertEquals(2, Role::count()); -}); -test('add role to user', function () { - $user = [ - 'username' => 'Test', - 'name' => 'Name', - 'password' => '123456', - 'password_confirmation' => '123456', - - ]; - - $this->visit('admin/auth/users/create') - ->see('Create') - ->submitForm('Submit', $user) - ->seePageIs('admin/auth/users') - ->seeInDatabase(config('admin.database.users_table'), ['username' => 'Test']); - - expect(Role::count())->toEqual(1); - - $this->visit('admin/auth/roles/create') - ->see('Roles') - ->submitForm('Submit', ['slug' => 'developer', 'name' => 'Developer...']) - ->seePageIs('admin/auth/roles') - ->seeInDatabase(config('admin.database.roles_table'), ['slug' => 'developer', 'name' => 'Developer...']) - ->assertEquals(2, Role::count()); - - expect(Administrator::find(2)->isRole('developer'))->toBeFalse(); - - $this->visit('admin/auth/users/2/edit') - ->see('Edit') - ->submitForm('Submit', ['roles' => [2]]) - ->seePageIs('admin/auth/users') - ->seeInDatabase(config('admin.database.role_users_table'), ['user_id' => 2, 'role_id' => 2]); - - expect(Administrator::find(2)->isRole('developer'))->toBeTrue(); - - expect(Administrator::find(2)->inRoles(['editor', 'operator']))->toBeFalse(); - expect(Administrator::find(2)->inRoles(['developer', 'operator', 'editor']))->toBeTrue(); -}); -test('delete role', function () { - expect(Role::count())->toEqual(1); - - $this->visit('admin/auth/roles/create') - ->see('Roles') - ->submitForm('Submit', ['slug' => 'developer', 'name' => 'Developer...']) - ->seePageIs('admin/auth/roles') - ->seeInDatabase(config('admin.database.roles_table'), ['slug' => 'developer', 'name' => 'Developer...']) - ->assertEquals(2, Role::count()); - - $this->delete('admin/auth/roles/2') - ->assertEquals(1, Role::count()); - - $this->delete('admin/auth/roles/1') - ->assertEquals(0, Role::count()); -}); -test('edit role', function () { - $this->visit('admin/auth/roles/create') - ->see('Roles') - ->submitForm('Submit', ['slug' => 'developer', 'name' => 'Developer...']) - ->seePageIs('admin/auth/roles') - ->seeInDatabase(config('admin.database.roles_table'), ['slug' => 'developer', 'name' => 'Developer...']) - ->assertEquals(2, Role::count()); - - $this->visit('admin/auth/roles/2/edit') - ->see('Roles') - ->submitForm('Submit', ['name' => 'blablabla']) - ->seePageIs('admin/auth/roles') - ->seeInDatabase(config('admin.database.roles_table'), ['name' => 'blablabla']) - ->assertEquals(2, Role::count()); -}); +use OpenAdmin\Admin\Auth\Database\Administrator; +use OpenAdmin\Admin\Auth\Database\Role; + +class RolesTest extends TestCase +{ + protected function setUp(): void + { + parent::setUp(); + + $this->be(Administrator::first(), 'admin'); + } + + public function testRolesIndex() + { + $this->visit('admin/auth/roles') + ->see('Roles') + ->see('administrator'); + } + + public function testAddRole() + { + $this->visit('admin/auth/roles/create') + ->see('Roles') + ->submitForm('Submit', ['slug' => 'developer', 'name' => 'Developer...']) + ->seePageIs('admin/auth/roles') + ->seeInDatabase(config('admin.database.roles_table'), ['slug' => 'developer', 'name' => 'Developer...']) + ->assertEquals(2, Role::count()); + } + + public function testAddRoleToUser() + { + $user = [ + 'username' => 'Test', + 'name' => 'Name', + 'password' => '123456', + 'password_confirmation' => '123456', + + ]; + + $this->visit('admin/auth/users/create') + ->see('Create') + ->submitForm('Submit', $user) + ->seePageIs('admin/auth/users') + ->seeInDatabase(config('admin.database.users_table'), ['username' => 'Test']); + + $this->assertEquals(1, Role::count()); + + $this->visit('admin/auth/roles/create') + ->see('Roles') + ->submitForm('Submit', ['slug' => 'developer', 'name' => 'Developer...']) + ->seePageIs('admin/auth/roles') + ->seeInDatabase(config('admin.database.roles_table'), ['slug' => 'developer', 'name' => 'Developer...']) + ->assertEquals(2, Role::count()); + + $this->assertFalse(Administrator::find(2)->isRole('developer')); + + $this->visit('admin/auth/users/2/edit') + ->see('Edit') + ->submitForm('Submit', ['roles' => [2]]) + ->seePageIs('admin/auth/users') + ->seeInDatabase(config('admin.database.role_users_table'), ['user_id' => 2, 'role_id' => 2]); + + $this->assertTrue(Administrator::find(2)->isRole('developer')); + + $this->assertFalse(Administrator::find(2)->inRoles(['editor', 'operator'])); + $this->assertTrue(Administrator::find(2)->inRoles(['developer', 'operator', 'editor'])); + } + + public function testDeleteRole() + { + $this->assertEquals(1, Role::count()); + + $this->visit('admin/auth/roles/create') + ->see('Roles') + ->submitForm('Submit', ['slug' => 'developer', 'name' => 'Developer...']) + ->seePageIs('admin/auth/roles') + ->seeInDatabase(config('admin.database.roles_table'), ['slug' => 'developer', 'name' => 'Developer...']) + ->assertEquals(2, Role::count()); + + $this->delete('admin/auth/roles/2') + ->assertEquals(1, Role::count()); + + $this->delete('admin/auth/roles/1') + ->assertEquals(0, Role::count()); + } + + public function testEditRole() + { + $this->visit('admin/auth/roles/create') + ->see('Roles') + ->submitForm('Submit', ['slug' => 'developer', 'name' => 'Developer...']) + ->seePageIs('admin/auth/roles') + ->seeInDatabase(config('admin.database.roles_table'), ['slug' => 'developer', 'name' => 'Developer...']) + ->assertEquals(2, Role::count()); + + $this->visit('admin/auth/roles/2/edit') + ->see('Roles') + ->submitForm('Submit', ['name' => 'blablabla']) + ->seePageIs('admin/auth/roles') + ->seeInDatabase(config('admin.database.roles_table'), ['name' => 'blablabla']) + ->assertEquals(2, Role::count()); + } +} diff --git a/tests/TestCase.php b/tests/TestCase.php index 2932d4a6..3d471d02 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -1,10 +1,98 @@ booting(function () { + $loader = \Illuminate\Foundation\AliasLoader::getInstance(); + $loader->alias('Admin', \OpenAdmin\Admin\Facades\Admin::class); + }); + + $app->make('Illuminate\Contracts\Console\Kernel')->bootstrap(); + + $app->register('OpenAdmin\Admin\AdminServiceProvider'); + + return $app; + } + + protected function setUp(): void + { + parent::setUp(); + + $adminConfig = require __DIR__.'/config/admin.php'; + + $this->app['config']->set('database.default', env('DB_CONNECTION', 'mysql')); + $this->app['config']->set('database.connections.mysql.host', env('MYSQL_HOST', 'localhost')); + $this->app['config']->set('database.connections.mysql.database', env('MYSQL_DATABASE', 'laravel_admin_test')); + $this->app['config']->set('database.connections.mysql.username', env('MYSQL_USER', 'root')); + $this->app['config']->set('database.connections.mysql.password', env('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' => 'OpenAdmin\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'; + +// \OpenAdmin\Admin\Admin::$css = []; +// \OpenAdmin\Admin\Admin::$js = []; +// \OpenAdmin\Admin\Admin::$script = []; + } + + protected function tearDown(): void + { + (new CreateAdminTables())->down(); + + (new CreateTestTables())->down(); + + DB::select("delete from `migrations` where `migration` = '2016_01_04_173148_create_admin_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(); + } } diff --git a/tests/UserFormTest.php b/tests/UserFormTest.php index ae9a09c6..aad90758 100644 --- a/tests/UserFormTest.php +++ b/tests/UserFormTest.php @@ -1,188 +1,209 @@ be(Administrator::first(), 'admin'); -}); -test('create page', function () { - $this->visit('admin/users/create') - ->seeElement('input[type=text][name=username]') - ->seeElement('input[type=email][name=email]') - ->seeElement('input[type=text][name=mobile]') - ->seeElement('input[type=file][name=avatar]') - ->seeElement('hr') - ->seeElement("input[type=text][name='profile[first_name]']") - ->seeElement("input[type=text][name='profile[last_name]']") - ->seeElement("input[type=text][name='profile[postcode]']") - ->seeElement("textarea[name='profile[address]'][rows=15]") - ->seeElement("input[type=hidden][name='profile[latitude]']") - ->seeElement("input[type=hidden][name='profile[longitude]']") - ->seeElement("input[type=text][name='profile[color]']") - ->seeElement("input[type=text][name='profile[start_at]']") - ->seeElement("input[type=text][name='profile[end_at]']") - ->seeElement('span[class=help-block] i[class*=fa-info-circle]') - ->seeInElement('span[class=help-block]', 'Please input your postcode') - ->seeElement('span[class=help-block] i[class*=fa-image]') - ->seeInElement('span[class=help-block]', '上传头像') - ->seeElement("select[name='tags[]'][multiple=multiple]") - ->seeInElement('a[html-field]', 'html...'); -}); -test('submit form', function () { - $data = [ - 'username' => 'John Doe', - 'email' => 'hello@world.com', - 'mobile' => '13421234123', - 'password' => '123456', - 'password_confirmation' => '123456', - //"avatar" => "test.jpg", - 'profile' => [ - 'first_name' => 'John', - 'last_name' => 'Doe', - 'postcode' => '123456', - 'address' => 'Jinshajiang RD', - 'latitude' => '131.2123123456', - 'longitude' => '21.342123456', - 'color' => '#ffffff', - 'start_at' => date('Y-m-d H:i:s', time()), - 'end_at' => date('Y-m-d H:i:s', time()), - ], - ]; - - $this->visit('admin/users/create') - ->attach(__DIR__.'/assets/test.jpg', 'avatar') - - ->submitForm('Submit', $data) - ->seePageIs('admin/users') - ->seeInElement('td', 1) - ->seeInElement('td', $data['username']) - ->seeInElement('td', $data['email']) - ->seeInElement('td', $data['mobile']) - ->seeInElement('td', "{$data['profile']['first_name']} {$data['profile']['last_name']}") - ->seeElement('td img') - ->seeInElement('td', $data['profile']['postcode']) - ->seeInElement('td', $data['profile']['address']) - ->seeInElement('td', "{$data['profile']['latitude']} {$data['profile']['longitude']}") - ->seeInElement('td', $data['profile']['color']) - ->seeInElement('td', $data['profile']['start_at']) - ->seeInElement('td', $data['profile']['end_at']); - - expect(UserModel::all())->toHaveCount(1); - - $this->seeInDatabase('test_users', ['username' => $data['username']]); - $this->seeInDatabase('test_users', ['email' => $data['email']]); - $this->seeInDatabase('test_users', ['mobile' => $data['mobile']]); - $this->seeInDatabase('test_users', ['password' => $data['password']]); - - $this->seeInDatabase('test_user_profiles', ['first_name' => $data['profile']['first_name']]); - $this->seeInDatabase('test_user_profiles', ['last_name' => $data['profile']['last_name']]); - $this->seeInDatabase('test_user_profiles', ['postcode' => $data['profile']['postcode']]); - $this->seeInDatabase('test_user_profiles', ['address' => $data['profile']['address']]); - $this->seeInDatabase('test_user_profiles', ['latitude' => $data['profile']['latitude']]); - $this->seeInDatabase('test_user_profiles', ['longitude' => $data['profile']['longitude']]); - $this->seeInDatabase('test_user_profiles', ['color' => $data['profile']['color']]); - $this->seeInDatabase('test_user_profiles', ['start_at' => $data['profile']['start_at']]); - $this->seeInDatabase('test_user_profiles', ['end_at' => $data['profile']['end_at']]); - - $avatar = UserModel::first()->avatar; - - expect(public_path('uploads/'.$avatar))->toBeFile(); -}); -function seedsTable($count = 100) + +class UserFormTest extends TestCase { - 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()); - }); + protected function setUp(): void + { + parent::setUp(); + + $this->be(Administrator::first(), 'admin'); + } + + public function testCreatePage() + { + $this->visit('admin/users/create') + ->seeElement('input[type=text][name=username]') + ->seeElement('input[type=email][name=email]') + ->seeElement('input[type=text][name=mobile]') + ->seeElement('input[type=file][name=avatar]') + ->seeElement('hr') + ->seeElement("input[type=text][name='profile[first_name]']") + ->seeElement("input[type=text][name='profile[last_name]']") + ->seeElement("input[type=text][name='profile[postcode]']") + ->seeElement("textarea[name='profile[address]'][rows=15]") + ->seeElement("input[type=hidden][name='profile[latitude]']") + ->seeElement("input[type=hidden][name='profile[longitude]']") + ->seeElement("input[type=text][name='profile[color]']") + ->seeElement("input[type=text][name='profile[start_at]']") + ->seeElement("input[type=text][name='profile[end_at]']") + ->seeElement('span[class=help-block] i[class*=fa-info-circle]') + ->seeInElement('span[class=help-block]', 'Please input your postcode') + ->seeElement('span[class=help-block] i[class*=fa-image]') + ->seeInElement('span[class=help-block]', '上传头像') + ->seeElement("select[name='tags[]'][multiple=multiple]") + ->seeInElement('a[html-field]', 'html...'); + } + + public function testSubmitForm() + { + $data = [ + 'username' => 'John Doe', + 'email' => 'hello@world.com', + 'mobile' => '13421234123', + 'password' => '123456', + 'password_confirmation' => '123456', + //"avatar" => "test.jpg", + 'profile' => [ + 'first_name' => 'John', + 'last_name' => 'Doe', + 'postcode' => '123456', + 'address' => 'Jinshajiang RD', + 'latitude' => '131.2123123456', + 'longitude' => '21.342123456', + 'color' => '#ffffff', + 'start_at' => date('Y-m-d H:i:s', time()), + 'end_at' => date('Y-m-d H:i:s', time()), + ], + ]; + + $this->visit('admin/users/create') + ->attach(__DIR__.'/assets/test.jpg', 'avatar') + + ->submitForm('Submit', $data) + ->seePageIs('admin/users') + ->seeInElement('td', 1) + ->seeInElement('td', $data['username']) + ->seeInElement('td', $data['email']) + ->seeInElement('td', $data['mobile']) + ->seeInElement('td', "{$data['profile']['first_name']} {$data['profile']['last_name']}") + ->seeElement('td img') + ->seeInElement('td', $data['profile']['postcode']) + ->seeInElement('td', $data['profile']['address']) + ->seeInElement('td', "{$data['profile']['latitude']} {$data['profile']['longitude']}") + ->seeInElement('td', $data['profile']['color']) + ->seeInElement('td', $data['profile']['start_at']) + ->seeInElement('td', $data['profile']['end_at']); + + $this->assertCount(1, UserModel::all()); + + $this->seeInDatabase('test_users', ['username' => $data['username']]); + $this->seeInDatabase('test_users', ['email' => $data['email']]); + $this->seeInDatabase('test_users', ['mobile' => $data['mobile']]); + $this->seeInDatabase('test_users', ['password' => $data['password']]); + + $this->seeInDatabase('test_user_profiles', ['first_name' => $data['profile']['first_name']]); + $this->seeInDatabase('test_user_profiles', ['last_name' => $data['profile']['last_name']]); + $this->seeInDatabase('test_user_profiles', ['postcode' => $data['profile']['postcode']]); + $this->seeInDatabase('test_user_profiles', ['address' => $data['profile']['address']]); + $this->seeInDatabase('test_user_profiles', ['latitude' => $data['profile']['latitude']]); + $this->seeInDatabase('test_user_profiles', ['longitude' => $data['profile']['longitude']]); + $this->seeInDatabase('test_user_profiles', ['color' => $data['profile']['color']]); + $this->seeInDatabase('test_user_profiles', ['start_at' => $data['profile']['start_at']]); + $this->seeInDatabase('test_user_profiles', ['end_at' => $data['profile']['end_at']]); + + $avatar = UserModel::first()->avatar; + + $this->assertFileExists(public_path('uploads/'.$avatar)); + } + + 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()); + }); + } + + public function testEditForm() + { + $this->seedsTable(10); + + $id = rand(1, 10); + + $user = UserModel::with('profile')->find($id); + + $this->visit("admin/users/$id/edit") + ->seeElement("input[type=text][name=username][value='{$user->username}']") + ->seeElement("input[type=email][name=email][value='{$user->email}']") + ->seeElement("input[type=text][name=mobile][value='{$user->mobile}']") + ->seeElement('hr') + ->seeElement("input[type=text][name='profile[first_name]'][value='{$user->profile->first_name}']") + ->seeElement("input[type=text][name='profile[last_name]'][value='{$user->profile->last_name}']") + ->seeElement("input[type=text][name='profile[postcode]'][value='{$user->profile->postcode}']") + ->seeInElement("textarea[name='profile[address]']", $user->profile->address) + ->seeElement("input[type=hidden][name='profile[latitude]'][value='{$user->profile->latitude}']") + ->seeElement("input[type=hidden][name='profile[longitude]'][value='{$user->profile->longitude}']") + ->seeElement("input[type=text][name='profile[color]'][value='{$user->profile->color}']") + ->seeElement("input[type=text][name='profile[start_at]'][value='{$user->profile->start_at}']") + ->seeElement("input[type=text][name='profile[end_at]'][value='{$user->profile->end_at}']") + ->seeElement("select[name='tags[]'][multiple=multiple]"); + + $this->assertCount(50, $this->crawler()->filter("select[name='tags[]'] option")); + $this->assertCount(5, $this->crawler()->filter("select[name='tags[]'] option[selected]")); + } + + public function testUpdateForm() + { + $this->seedsTable(10); + + $id = rand(1, 10); + + $this->visit("admin/users/$id/edit") + ->type('hello world', 'username') + ->type('123', 'password') + ->type('123', 'password_confirmation') + ->press('Submit') + ->seePageIs('admin/users') + ->seeInDatabase('test_users', ['username' => 'hello world']); + + $user = UserModel::with('profile')->find($id); + + $this->assertEquals($user->username, 'hello world'); + } + + public function testUpdateFormWithRule() + { + $this->seedsTable(10); + + $id = rand(1, 10); + + $this->visit("admin/users/$id/edit") + ->type('', 'email') + ->press('Submit') + ->seePageIs("admin/users/$id/edit") + ->see('The email field is required'); + + $this->type('xxaxx', 'email') + ->press('Submit') + ->seePageIs("admin/users/$id/edit") + ->see('The email must be a valid email address.'); + + $this->visit("admin/users/$id/edit") + ->type('123', 'password') + ->type('1234', 'password_confirmation') + ->press('Submit') + ->seePageIs("admin/users/$id/edit") + ->see('The Password confirmation does not match.'); + + $this->type('xx@xx.xx', 'email') + ->type('123', 'password') + ->type('123', 'password_confirmation') + ->press('Submit') + ->seePageIs('admin/users') + ->seeInDatabase('test_users', ['email' => 'xx@xx.xx']); + } + + public function testFormHeader() + { + $this->seedsTable(1); + + $this->visit('admin/users/1/edit') + ->seeInElement('a[class*=btn-danger]', 'Delete') + ->seeInElement('a[class*=btn-default]', 'List') + ->seeInElement('a[class*=btn-primary]', 'View'); + } + + public function testFormFooter() + { + $this->seedsTable(1); + + $this->visit('admin/users/1/edit') + ->seeElement('input[type=checkbox][value=1]') + ->seeElement('input[type=checkbox][value=2]'); + } } -test('edit form', function () { - seedsTable(10); - - $id = rand(1, 10); - - $user = UserModel::with('profile')->find($id); - - $this->visit("admin/users/$id/edit") - ->seeElement("input[type=text][name=username][value='{$user->username}']") - ->seeElement("input[type=email][name=email][value='{$user->email}']") - ->seeElement("input[type=text][name=mobile][value='{$user->mobile}']") - ->seeElement('hr') - ->seeElement("input[type=text][name='profile[first_name]'][value='{$user->profile->first_name}']") - ->seeElement("input[type=text][name='profile[last_name]'][value='{$user->profile->last_name}']") - ->seeElement("input[type=text][name='profile[postcode]'][value='{$user->profile->postcode}']") - ->seeInElement("textarea[name='profile[address]']", $user->profile->address) - ->seeElement("input[type=hidden][name='profile[latitude]'][value='{$user->profile->latitude}']") - ->seeElement("input[type=hidden][name='profile[longitude]'][value='{$user->profile->longitude}']") - ->seeElement("input[type=text][name='profile[color]'][value='{$user->profile->color}']") - ->seeElement("input[type=text][name='profile[start_at]'][value='{$user->profile->start_at}']") - ->seeElement("input[type=text][name='profile[end_at]'][value='{$user->profile->end_at}']") - ->seeElement("select[name='tags[]'][multiple=multiple]"); - - expect($this->crawler()->filter("select[name='tags[]'] option"))->toHaveCount(50); - expect($this->crawler()->filter("select[name='tags[]'] option[selected]"))->toHaveCount(5); -}); -test('update form', function () { - seedsTable(10); - - $id = rand(1, 10); - - $this->visit("admin/users/$id/edit") - ->type('hello world', 'username') - ->type('123', 'password') - ->type('123', 'password_confirmation') - ->press('Submit') - ->seePageIs('admin/users') - ->seeInDatabase('test_users', ['username' => 'hello world']); - - $user = UserModel::with('profile')->find($id); - - expect('hello world')->toEqual($user->username); -}); -test('update form with rule', function () { - seedsTable(10); - - $id = rand(1, 10); - - $this->visit("admin/users/$id/edit") - ->type('', 'email') - ->press('Submit') - ->seePageIs("admin/users/$id/edit") - ->see('The email field is required'); - - $this->type('xxaxx', 'email') - ->press('Submit') - ->seePageIs("admin/users/$id/edit") - ->see('The email must be a valid email address.'); - - $this->visit("admin/users/$id/edit") - ->type('123', 'password') - ->type('1234', 'password_confirmation') - ->press('Submit') - ->seePageIs("admin/users/$id/edit") - ->see('The Password confirmation does not match.'); - - $this->type('xx@xx.xx', 'email') - ->type('123', 'password') - ->type('123', 'password_confirmation') - ->press('Submit') - ->seePageIs('admin/users') - ->seeInDatabase('test_users', ['email' => 'xx@xx.xx']); -}); -test('form header', function () { - seedsTable(1); - - $this->visit('admin/users/1/edit') - ->seeInElement('a[class*=btn-danger]', 'Delete') - ->seeInElement('a[class*=btn-default]', 'List') - ->seeInElement('a[class*=btn-primary]', 'View'); -}); -test('form footer', function () { - seedsTable(1); - - $this->visit('admin/users/1/edit') - ->seeElement('input[type=checkbox][value=1]') - ->seeElement('input[type=checkbox][value=2]'); -}); diff --git a/tests/UserGridTest.php b/tests/UserGridTest.php index cfbcc4e2..b4694be3 100644 --- a/tests/UserGridTest.php +++ b/tests/UserGridTest.php @@ -1,218 +1,249 @@ be(Administrator::first(), 'admin'); -}); -test('index page', function () { - $this->visit('admin/users') - ->see('Users') - ->seeInElement('tr th', 'Username') - ->seeInElement('tr th', 'Email') - ->seeInElement('tr th', 'Mobile') - ->seeInElement('tr th', 'Full name') - ->seeInElement('tr th', 'Avatar') - ->seeInElement('tr th', 'Post code') - ->seeInElement('tr th', 'Address') - ->seeInElement('tr th', 'Position') - ->seeInElement('tr th', 'Color') - ->seeInElement('tr th', '开始时间') - ->seeInElement('tr th', '结束时间') - ->seeInElement('tr th', 'Color') - ->seeInElement('tr th', 'Created at') - ->seeInElement('tr th', 'Updated at'); - - $action = url('/admin/users'); - - $this->seeElement("form[action='$action'][method=get]") - ->seeElement("form[action='$action'][method=get] input[name=id]") - ->seeElement("form[action='$action'][method=get] input[name=username]") - ->seeElement("form[action='$action'][method=get] input[name=email]") - ->seeElement("form[action='$action'][method=get] input[name='profile[start_at][start]']") - ->seeElement("form[action='$action'][method=get] input[name='profile[start_at][end]']") - ->seeElement("form[action='$action'][method=get] input[name='profile[end_at][start]']") - ->seeElement("form[action='$action'][method=get] input[name='profile[end_at][end]']"); - - $urlAll = url('/admin/users?_export_=all'); - $urlNew = url('/admin/users/create'); - $this->seeInElement("a[href=\"{$urlAll}\"]", 'All') - ->seeInElement("a[href=\"{$urlNew}\"]", 'New'); -}); -function seedsTable($count = 100) + +class UserGridTest extends TestCase { - 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()); - $u->data = ['json' => ['field' => random_int(0, 50)]]; - $u->save(); - }); -} -test('grid with data', function () { - seedsTable(); - - $this->visit('admin/users') - ->see('Users'); - - expect(UserModel::all())->toHaveCount(100); - expect(ProfileModel::all())->toHaveCount(100); -}); -test('grid pagination', function () { - seedsTable(65); - - $this->visit('admin/users') - ->see('Users'); - - $this->visit('admin/users?page=2'); - expect($this->crawler()->filter('td a i[class*=fa-edit]'))->toHaveCount(20); - - $this->visit('admin/users?page=3'); - expect($this->crawler()->filter('td a i[class*=fa-edit]'))->toHaveCount(20); - - $this->visit('admin/users?page=4'); - expect($this->crawler()->filter('td a i[class*=fa-edit]'))->toHaveCount(5); - - $this->click(1)->seePageIs('admin/users?page=1'); - expect($this->crawler()->filter('td a i[class*=fa-edit]'))->toHaveCount(20); -}); -test('order by json', function () { - seedsTable(10); - expect(UserModel::all())->toHaveCount(10); - - $this->visit('admin/users?_sort[column]=data.json.field&_sort[type]=desc&_sort[cast]=unsigned'); - - $jsonTds = $this->crawler->filter('table.table tbody td.column-data-json-field'); - expect($jsonTds)->toHaveCount(10); - $prevValue = PHP_INT_MAX; - foreach ($jsonTds as $jsonTd) { - $currentValue = (int) $jsonTd->nodeValue; - expect($currentValue <= $prevValue)->toBeTrue(); - $prevValue = $currentValue; + protected function setUp(): void + { + parent::setUp(); + + $this->be(Administrator::first(), 'admin'); + } + + public function testIndexPage() + { + $this->visit('admin/users') + ->see('Users') + ->seeInElement('tr th', 'Username') + ->seeInElement('tr th', 'Email') + ->seeInElement('tr th', 'Mobile') + ->seeInElement('tr th', 'Full name') + ->seeInElement('tr th', 'Avatar') + ->seeInElement('tr th', 'Post code') + ->seeInElement('tr th', 'Address') + ->seeInElement('tr th', 'Position') + ->seeInElement('tr th', 'Color') + ->seeInElement('tr th', '开始时间') + ->seeInElement('tr th', '结束时间') + ->seeInElement('tr th', 'Color') + ->seeInElement('tr th', 'Created at') + ->seeInElement('tr th', 'Updated at'); + + $action = url('/admin/users'); + + $this->seeElement("form[action='$action'][method=get]") + ->seeElement("form[action='$action'][method=get] input[name=id]") + ->seeElement("form[action='$action'][method=get] input[name=username]") + ->seeElement("form[action='$action'][method=get] input[name=email]") + ->seeElement("form[action='$action'][method=get] input[name='profile[start_at][start]']") + ->seeElement("form[action='$action'][method=get] input[name='profile[start_at][end]']") + ->seeElement("form[action='$action'][method=get] input[name='profile[end_at][start]']") + ->seeElement("form[action='$action'][method=get] input[name='profile[end_at][end]']"); + + $urlAll = url('/admin/users?_export_=all'); + $urlNew = url('/admin/users/create'); + $this->seeInElement("a[href=\"{$urlAll}\"]", 'All') + ->seeInElement("a[href=\"{$urlNew}\"]", 'New'); + } + + 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()); + $u->data = ['json' => ['field' => random_int(0, 50)]]; + $u->save(); + }); + } + + public function testGridWithData() + { + $this->seedsTable(); + + $this->visit('admin/users') + ->see('Users'); + + $this->assertCount(100, UserModel::all()); + $this->assertCount(100, ProfileModel::all()); + } + + public function testGridPagination() + { + $this->seedsTable(65); + + $this->visit('admin/users') + ->see('Users'); + + $this->visit('admin/users?page=2'); + $this->assertCount(20, $this->crawler()->filter('td a i[class*=fa-edit]')); + + $this->visit('admin/users?page=3'); + $this->assertCount(20, $this->crawler()->filter('td a i[class*=fa-edit]')); + + $this->visit('admin/users?page=4'); + $this->assertCount(5, $this->crawler()->filter('td a i[class*=fa-edit]')); + + $this->click(1)->seePageIs('admin/users?page=1'); + $this->assertCount(20, $this->crawler()->filter('td a i[class*=fa-edit]')); + } + + public function testOrderByJson() + { + $this->seedsTable(10); + $this->assertCount(10, UserModel::all()); + + $this->visit('admin/users?_sort[column]=data.json.field&_sort[type]=desc&_sort[cast]=unsigned'); + + $jsonTds = $this->crawler->filter('table.table tbody td.column-data-json-field'); + $this->assertCount(10, $jsonTds); + $prevValue = PHP_INT_MAX; + foreach ($jsonTds as $jsonTd) { + $currentValue = (int) $jsonTd->nodeValue; + $this->assertTrue($currentValue <= $prevValue); + $prevValue = $currentValue; + } + } + + public function testEqualFilter() + { + $this->seedsTable(50); + + $this->visit('admin/users') + ->see('Users'); + + $this->assertCount(50, UserModel::all()); + $this->assertCount(50, ProfileModel::all()); + + $id = rand(1, 50); + + $user = UserModel::find($id); + + $this->visit('admin/users?id='.$id) + ->seeInElement('td', $user->username) + ->seeInElement('td', $user->email) + ->seeInElement('td', $user->mobile) + ->seeElement("img[src='{$user->avatar}']") + ->seeInElement('td', "{$user->profile->first_name} {$user->profile->last_name}") + ->seeInElement('td', $user->postcode) + ->seeInElement('td', $user->address) + ->seeInElement('td', "{$user->profile->latitude} {$user->profile->longitude}") + ->seeInElement('td', $user->color) + ->seeInElement('td', $user->start_at) + ->seeInElement('td', $user->end_at); + } + + public function testLikeFilter() + { + $this->seedsTable(50); + + $this->visit('admin/users') + ->see('Users'); + + $this->assertCount(50, UserModel::all()); + $this->assertCount(50, ProfileModel::all()); + + $users = UserModel::where('username', 'like', '%mi%')->get(); + + $this->visit('admin/users?username=mi'); + + $this->assertCount($this->crawler()->filter('table tr')->count() - 1, $users); + + foreach ($users as $user) { + $this->seeInElement('td', $user->username); + } + } + + public function testFilterRelation() + { + $this->seedsTable(50); + + $user = UserModel::with('profile')->find(rand(1, 50)); + + $this->visit('admin/users?email='.$user->email) + ->seeInElement('td', $user->username) + ->seeInElement('td', $user->email) + ->seeInElement('td', $user->mobile) + ->seeElement("img[src='{$user->avatar}']") + ->seeInElement('td', "{$user->profile->first_name} {$user->profile->last_name}") + ->seeInElement('td', $user->postcode) + ->seeInElement('td', $user->address) + ->seeInElement('td', "{$user->profile->latitude} {$user->profile->longitude}") + ->seeInElement('td', $user->color) + ->seeInElement('td', $user->start_at) + ->seeInElement('td', $user->end_at); + } + + public function testDisplayCallback() + { + $this->seedsTable(1); + + $user = UserModel::with('profile')->find(1); + + $this->visit('admin/users') + ->seeInElement('th', 'Column1 not in table') + ->seeInElement('th', 'Column2 not in table') + ->seeInElement('td', "full name:{$user->profile->first_name} {$user->profile->last_name}") + ->seeInElement('td', "{$user->email}#{$user->profile->color}"); + } + + public function testHasManyRelation() + { + factory(\Tests\Models\User::class, 10) + ->create() + ->each(function ($u) { + $u->profile()->save(factory(\Tests\Models\Profile::class)->make()); + $u->tags()->saveMany(factory(\Tests\Models\Tag::class, 5)->make()); + }); + + $this->visit('admin/users') + ->seeElement('td code'); + + $this->assertCount(50, $this->crawler()->filter('td code')); } -}); -test('equal filter', function () { - seedsTable(50); - $this->visit('admin/users') - ->see('Users'); + public function testGridActions() + { + $this->seedsTable(15); - expect(UserModel::all())->toHaveCount(50); - expect(ProfileModel::all())->toHaveCount(50); + $this->visit('admin/users'); - $id = rand(1, 50); + $this->assertCount(15, $this->crawler()->filter('td a i[class*=fa-edit]')); + $this->assertCount(15, $this->crawler()->filter('td a i[class*=fa-trash]')); + } - $user = UserModel::find($id); + public function testGridRows() + { + $this->seedsTable(10); - $this->visit('admin/users?id='.$id) - ->seeInElement('td', $user->username) - ->seeInElement('td', $user->email) - ->seeInElement('td', $user->mobile) - ->seeElement("img[src='{$user->avatar}']") - ->seeInElement('td', "{$user->profile->first_name} {$user->profile->last_name}") - ->seeInElement('td', $user->postcode) - ->seeInElement('td', $user->address) - ->seeInElement('td', "{$user->profile->latitude} {$user->profile->longitude}") - ->seeInElement('td', $user->color) - ->seeInElement('td', $user->start_at) - ->seeInElement('td', $user->end_at); -}); -test('like filter', function () { - seedsTable(50); + $this->visit('admin/users') + ->seeInElement('td a[class*=btn]', 'detail'); - $this->visit('admin/users') - ->see('Users'); + $this->assertCount(5, $this->crawler()->filter('td a[class*=btn]')); + } - expect(UserModel::all())->toHaveCount(50); - expect(ProfileModel::all())->toHaveCount(50); + public function testGridPerPage() + { + $this->seedsTable(98); - $users = UserModel::where('username', 'like', '%mi%')->get(); + $this->visit('admin/users') + ->seeElement('select[class*=per-page][name=per-page]') + ->seeInElement('select option', 10) + ->seeInElement('select option[selected]', 20) + ->seeInElement('select option', 30) + ->seeInElement('select option', 50) + ->seeInElement('select option', 100); - $this->visit('admin/users?username=mi'); + $this->assertEquals('http://localhost:8000/admin/users?per_page=20', $this->crawler()->filter('select option[selected]')->attr('value')); - expect($users)->toHaveCount($this->crawler()->filter('table tr')->count() - 1); + $perPage = rand(1, 98); - foreach ($users as $user) { - $this->seeInElement('td', $user->username); + $this->visit('admin/users?per_page='.$perPage) + ->seeInElement('select option[selected]', $perPage) + ->assertCount($perPage + 1, $this->crawler()->filter('tr')); } -}); -test('filter relation', function () { - seedsTable(50); - - $user = UserModel::with('profile')->find(rand(1, 50)); - - $this->visit('admin/users?email='.$user->email) - ->seeInElement('td', $user->username) - ->seeInElement('td', $user->email) - ->seeInElement('td', $user->mobile) - ->seeElement("img[src='{$user->avatar}']") - ->seeInElement('td', "{$user->profile->first_name} {$user->profile->last_name}") - ->seeInElement('td', $user->postcode) - ->seeInElement('td', $user->address) - ->seeInElement('td', "{$user->profile->latitude} {$user->profile->longitude}") - ->seeInElement('td', $user->color) - ->seeInElement('td', $user->start_at) - ->seeInElement('td', $user->end_at); -}); -test('display callback', function () { - seedsTable(1); - - $user = UserModel::with('profile')->find(1); - - $this->visit('admin/users') - ->seeInElement('th', 'Column1 not in table') - ->seeInElement('th', 'Column2 not in table') - ->seeInElement('td', "full name:{$user->profile->first_name} {$user->profile->last_name}") - ->seeInElement('td', "{$user->email}#{$user->profile->color}"); -}); -test('has many relation', function () { - factory(\Tests\Models\User::class, 10) - ->create() - ->each(function ($u) { - $u->profile()->save(factory(\Tests\Models\Profile::class)->make()); - $u->tags()->saveMany(factory(\Tests\Models\Tag::class, 5)->make()); - }); - - $this->visit('admin/users') - ->seeElement('td code'); - - expect($this->crawler()->filter('td code'))->toHaveCount(50); -}); -test('grid actions', function () { - seedsTable(15); - - $this->visit('admin/users'); - - expect($this->crawler()->filter('td a i[class*=fa-edit]'))->toHaveCount(15); - expect($this->crawler()->filter('td a i[class*=fa-trash]'))->toHaveCount(15); -}); -test('grid rows', function () { - seedsTable(10); - - $this->visit('admin/users') - ->seeInElement('td a[class*=btn]', 'detail'); - - expect($this->crawler()->filter('td a[class*=btn]'))->toHaveCount(5); -}); -test('grid per page', function () { - seedsTable(98); - - $this->visit('admin/users') - ->seeElement('select[class*=per-page][name=per-page]') - ->seeInElement('select option', 10) - ->seeInElement('select option[selected]', 20) - ->seeInElement('select option', 30) - ->seeInElement('select option', 50) - ->seeInElement('select option', 100); - - expect($this->crawler()->filter('select option[selected]')->attr('value'))->toEqual('http://localhost:8000/admin/users?per_page=20'); - - $perPage = rand(1, 98); - - $this->visit('admin/users?per_page='.$perPage) - ->seeInElement('select option[selected]', $perPage) - ->assertCount($perPage + 1, $this->crawler()->filter('tr')); -}); +} diff --git a/tests/UserSettingTest.php b/tests/UserSettingTest.php index 4ccb286e..5d7fbfa0 100644 --- a/tests/UserSettingTest.php +++ b/tests/UserSettingTest.php @@ -1,80 +1,96 @@ be(Administrator::first(), 'admin'); -}); -test('visit setting page', function () { - $this->visit('admin/auth/setting') - ->see('User setting') - ->see('Username') - ->see('Name') - ->see('Avatar') - ->see('Password') - ->see('Password confirmation'); - - $this->seeElement('input[value=Administrator]') - ->seeInElement('.box-body', 'administrator'); -}); -test('update name', function () { - $data = [ - 'name' => 'tester', - ]; - - $this->visit('admin/auth/setting') - ->submitForm('Submit', $data) - ->seePageIs('admin/auth/setting'); - - $this->seeInDatabase('admin_users', ['name' => $data['name']]); -}); -test('update avatar', function () { - File::cleanDirectory(public_path('uploads/images')); - - $this->visit('admin/auth/setting') - ->attach(__DIR__.'/assets/test.jpg', 'avatar') - ->press('Submit') - ->seePageIs('admin/auth/setting'); - - $avatar = Administrator::first()->avatar; - - expect($avatar)->toEqual('http://localhost:8000/uploads/images/test.jpg'); -}); -test('update password confirmation', function () { - $data = [ - 'password' => '123456', - 'password_confirmation' => '123', - ]; - - $this->visit('admin/auth/setting') - ->submitForm('Submit', $data) - ->seePageIs('admin/auth/setting') - ->see('The Password confirmation does not match.'); -}); -test('update password', function () { - $data = [ - 'password' => '123456', - 'password_confirmation' => '123456', - ]; - - $this->visit('admin/auth/setting') - ->submitForm('Submit', $data) - ->seePageIs('admin/auth/setting'); - - expect(app('hash')->check($data['password'], Administrator::first()->makeVisible('password')->password))->toBeTrue(); - - $this->visit('admin/auth/logout') - ->seePageIs('admin/auth/login') - ->dontSeeIsAuthenticated('admin'); - - $credentials = ['username' => 'admin', 'password' => '123456']; - - $this->visit('admin/auth/login') - ->see('login') - ->submitForm('Login', $credentials) - ->see('dashboard') - ->seeCredentials($credentials, 'admin') - ->seeIsAuthenticated('admin') - ->seePageIs('admin'); -}); +use OpenAdmin\Admin\Auth\Database\Administrator; + +class UserSettingTest extends TestCase +{ + protected function setUp(): void + { + parent::setUp(); + + $this->be(Administrator::first(), 'admin'); + } + + public function testVisitSettingPage() + { + $this->visit('admin/auth/setting') + ->see('User setting') + ->see('Username') + ->see('Name') + ->see('Avatar') + ->see('Password') + ->see('Password confirmation'); + + $this->seeElement('input[value=Administrator]') + ->seeInElement('.box-body', 'administrator'); + } + + public function testUpdateName() + { + $data = [ + 'name' => 'tester', + ]; + + $this->visit('admin/auth/setting') + ->submitForm('Submit', $data) + ->seePageIs('admin/auth/setting'); + + $this->seeInDatabase('admin_users', ['name' => $data['name']]); + } + + public function testUpdateAvatar() + { + File::cleanDirectory(public_path('uploads/images')); + + $this->visit('admin/auth/setting') + ->attach(__DIR__.'/assets/test.jpg', 'avatar') + ->press('Submit') + ->seePageIs('admin/auth/setting'); + + $avatar = Administrator::first()->avatar; + + $this->assertEquals('http://localhost:8000/uploads/images/test.jpg', $avatar); + } + + public function testUpdatePasswordConfirmation() + { + $data = [ + 'password' => '123456', + 'password_confirmation' => '123', + ]; + + $this->visit('admin/auth/setting') + ->submitForm('Submit', $data) + ->seePageIs('admin/auth/setting') + ->see('The Password confirmation does not match.'); + } + + public function testUpdatePassword() + { + $data = [ + 'password' => '123456', + 'password_confirmation' => '123456', + ]; + + $this->visit('admin/auth/setting') + ->submitForm('Submit', $data) + ->seePageIs('admin/auth/setting'); + + $this->assertTrue(app('hash')->check($data['password'], Administrator::first()->makeVisible('password')->password)); + + $this->visit('admin/auth/logout') + ->seePageIs('admin/auth/login') + ->dontSeeIsAuthenticated('admin'); + + $credentials = ['username' => 'admin', 'password' => '123456']; + + $this->visit('admin/auth/login') + ->see('login') + ->submitForm('Login', $credentials) + ->see('dashboard') + ->seeCredentials($credentials, 'admin') + ->seeIsAuthenticated('admin') + ->seePageIs('admin'); + } +} diff --git a/tests/UsersTest.php b/tests/UsersTest.php index 653fbeb9..8ff7a335 100644 --- a/tests/UsersTest.php +++ b/tests/UsersTest.php @@ -1,79 +1,95 @@ user = Administrator::first(); - - $this->be($this->user, 'admin'); -}); -test('users index page', function () { - $this->visit('admin/auth/users') - ->see('Administrator'); -}); -test('create user', function () { - $user = [ - 'username' => 'Test', - 'name' => 'Name', - 'password' => '123456', - 'password_confirmation' => '123456', - ]; - - // create user - $this->visit('admin/auth/users/create') - ->see('Create') - ->submitForm('Submit', $user) - ->seePageIs('admin/auth/users') - ->seeInDatabase(config('admin.database.users_table'), ['username' => 'Test']); - - // assign role to user - $this->visit('admin/auth/users/2/edit') - ->see('Edit') - ->submitForm('Submit', ['roles' => [1]]) - ->seePageIs('admin/auth/users') - ->seeInDatabase(config('admin.database.role_users_table'), ['user_id' => 2, 'role_id' => 1]); - - $this->visit('admin/auth/logout') - ->dontSeeIsAuthenticated('admin') - ->seePageIs('admin/auth/login') - ->submitForm('Login', ['username' => $user['username'], 'password' => $user['password']]) - ->see('dashboard') - ->seeIsAuthenticated('admin') - ->seePageIs('admin'); - - expect($this->app['auth']->guard('admin')->getUser()->isAdministrator())->toBeTrue(); - - $this->see('Users') - ->see('Roles') - ->see('Permission') - ->see('Operation log') - ->see('Menu'); -}); -test('update user', function () { - $this->visit('admin/auth/users/'.$this->user->id.'/edit') - ->see('Create') - ->submitForm('Submit', ['name' => 'test', 'roles' => [1]]) - ->seePageIs('admin/auth/users') - ->seeInDatabase(config('admin.database.users_table'), ['name' => 'test']); -}); -test('reset password', function () { - $password = 'odjwyufkglte'; - - $data = [ - 'password' => $password, - 'password_confirmation' => $password, - 'roles' => [1], - ]; - - $this->visit('admin/auth/users/'.$this->user->id.'/edit') - ->see('Create') - ->submitForm('Submit', $data) - ->seePageIs('admin/auth/users') - ->visit('admin/auth/logout') - ->dontSeeIsAuthenticated('admin') - ->seePageIs('admin/auth/login') - ->submitForm('Login', ['username' => $this->user->username, 'password' => $password]) - ->see('dashboard') - ->seeIsAuthenticated('admin') - ->seePageIs('admin'); -}); +use OpenAdmin\Admin\Auth\Database\Administrator; + +class UsersTest extends TestCase +{ + protected $user; + + protected function setUp(): void + { + parent::setUp(); + + $this->user = Administrator::first(); + + $this->be($this->user, 'admin'); + } + + public function testUsersIndexPage() + { + $this->visit('admin/auth/users') + ->see('Administrator'); + } + + public function testCreateUser() + { + $user = [ + 'username' => 'Test', + 'name' => 'Name', + 'password' => '123456', + 'password_confirmation' => '123456', + ]; + + // create user + $this->visit('admin/auth/users/create') + ->see('Create') + ->submitForm('Submit', $user) + ->seePageIs('admin/auth/users') + ->seeInDatabase(config('admin.database.users_table'), ['username' => 'Test']); + + // assign role to user + $this->visit('admin/auth/users/2/edit') + ->see('Edit') + ->submitForm('Submit', ['roles' => [1]]) + ->seePageIs('admin/auth/users') + ->seeInDatabase(config('admin.database.role_users_table'), ['user_id' => 2, 'role_id' => 1]); + + $this->visit('admin/auth/logout') + ->dontSeeIsAuthenticated('admin') + ->seePageIs('admin/auth/login') + ->submitForm('Login', ['username' => $user['username'], 'password' => $user['password']]) + ->see('dashboard') + ->seeIsAuthenticated('admin') + ->seePageIs('admin'); + + $this->assertTrue($this->app['auth']->guard('admin')->getUser()->isAdministrator()); + + $this->see('Users') + ->see('Roles') + ->see('Permission') + ->see('Operation log') + ->see('Menu'); + } + + public function testUpdateUser() + { + $this->visit('admin/auth/users/'.$this->user->id.'/edit') + ->see('Create') + ->submitForm('Submit', ['name' => 'test', 'roles' => [1]]) + ->seePageIs('admin/auth/users') + ->seeInDatabase(config('admin.database.users_table'), ['name' => 'test']); + } + + public function testResetPassword() + { + $password = 'odjwyufkglte'; + + $data = [ + 'password' => $password, + 'password_confirmation' => $password, + 'roles' => [1], + ]; + + $this->visit('admin/auth/users/'.$this->user->id.'/edit') + ->see('Create') + ->submitForm('Submit', $data) + ->seePageIs('admin/auth/users') + ->visit('admin/auth/logout') + ->dontSeeIsAuthenticated('admin') + ->seePageIs('admin/auth/login') + ->submitForm('Login', ['username' => $this->user->username, 'password' => $password]) + ->see('dashboard') + ->seeIsAuthenticated('admin') + ->seePageIs('admin'); + } +} diff --git a/tests/config/admin.php b/tests/config/admin.php index b155b940..48adec81 100644 --- a/tests/config/admin.php +++ b/tests/config/admin.php @@ -3,9 +3,9 @@ return [ /* - * Laravel-admin name. + * Open-admin name. */ - 'name' => 'Laravel-admin', + 'name' => 'Open-admin', /* * Logo in admin panel header. @@ -30,12 +30,12 @@ ], /* - * Laravel-admin install directory. + * Open-admin install directory. */ 'directory' => app_path('Admin'), /* - * Laravel-admin html title. + * Open-admin html title. */ 'title' => 'Admin', @@ -45,7 +45,7 @@ 'secure' => false, /* - * Laravel-admin auth setting. + * Open-admin auth setting. */ 'auth' => [ 'guards' => [ @@ -58,13 +58,13 @@ 'providers' => [ 'admin' => [ 'driver' => 'eloquent', - 'model' => Encore\Admin\Auth\Database\Administrator::class, + 'model' => OpenAdmin\Admin\Auth\Database\Administrator::class, ], ], ], /* - * Laravel-admin upload setting. + * Open-admin upload setting. */ 'upload' => [ @@ -77,7 +77,7 @@ ], /* - * Laravel-admin database setting. + * Open-admin database setting. */ 'database' => [ @@ -86,19 +86,19 @@ // User tables and model. 'users_table' => 'admin_users', - 'users_model' => Encore\Admin\Auth\Database\Administrator::class, + 'users_model' => OpenAdmin\Admin\Auth\Database\Administrator::class, // Role table and model. 'roles_table' => 'admin_roles', - 'roles_model' => Encore\Admin\Auth\Database\Role::class, + 'roles_model' => OpenAdmin\Admin\Auth\Database\Role::class, // Permission table and model. 'permissions_table' => 'admin_permissions', - 'permissions_model' => Encore\Admin\Auth\Database\Permission::class, + 'permissions_model' => OpenAdmin\Admin\Auth\Database\Permission::class, // Menu table and model. 'menu_table' => 'admin_menu', - 'menu_model' => Encore\Admin\Auth\Database\Menu::class, + 'menu_model' => OpenAdmin\Admin\Auth\Database\Menu::class, // Pivot table for table above. 'operation_log_table' => 'admin_operation_log', @@ -109,7 +109,7 @@ ], /* - * By setting this option to open or close operation log in laravel-admin. + * By setting this option to open or close operation log in open-admin. */ 'operation_log' => [ diff --git a/tests/config/filesystems.php b/tests/config/filesystems.php index 4b0a99ea..3cd874e8 100644 --- a/tests/config/filesystems.php +++ b/tests/config/filesystems.php @@ -86,7 +86,7 @@ 'driver' => 'oss', 'access_id' => 'LTAIsOQNIDQN78Jr', 'access_key' => 'ChsYewaCxm1mi7AIBPRniuncEbFHNO', - 'bucket' => 'laravel-admin', + 'bucket' => 'open-admin', 'endpoint' => 'oss-cn-shanghai.aliyuncs.com', ], diff --git a/tests/controllers/FileController.php b/tests/controllers/FileController.php index 565f0d28..62a0db19 100644 --- a/tests/controllers/FileController.php +++ b/tests/controllers/FileController.php @@ -2,9 +2,9 @@ namespace Tests\Controllers; -use Encore\Admin\Controllers\AdminController; -use Encore\Admin\Form; -use Encore\Admin\Grid; +use OpenAdmin\Admin\Controllers\AdminController; +use OpenAdmin\Admin\Form; +use OpenAdmin\Admin\Grid; use Tests\Models\File; class FileController extends AdminController diff --git a/tests/controllers/ImageController.php b/tests/controllers/ImageController.php index 8a1a44f7..0cf08cc2 100644 --- a/tests/controllers/ImageController.php +++ b/tests/controllers/ImageController.php @@ -2,9 +2,9 @@ namespace Tests\Controllers; -use Encore\Admin\Controllers\AdminController; -use Encore\Admin\Form; -use Encore\Admin\Grid; +use OpenAdmin\Admin\Controllers\AdminController; +use OpenAdmin\Admin\Form; +use OpenAdmin\Admin\Grid; use Tests\Models\Image; class ImageController extends AdminController diff --git a/tests/controllers/MultipleImageController.php b/tests/controllers/MultipleImageController.php index 78811759..d0c88e32 100644 --- a/tests/controllers/MultipleImageController.php +++ b/tests/controllers/MultipleImageController.php @@ -2,9 +2,9 @@ namespace Tests\Controllers; -use Encore\Admin\Controllers\AdminController; -use Encore\Admin\Form; -use Encore\Admin\Grid; +use OpenAdmin\Admin\Controllers\AdminController; +use OpenAdmin\Admin\Form; +use OpenAdmin\Admin\Grid; use Tests\Models\MultipleImage; class MultipleImageController extends AdminController diff --git a/tests/controllers/UserController.php b/tests/controllers/UserController.php index 6f6317d1..847c3800 100644 --- a/tests/controllers/UserController.php +++ b/tests/controllers/UserController.php @@ -2,9 +2,9 @@ namespace Tests\Controllers; -use Encore\Admin\Controllers\AdminController; -use Encore\Admin\Form; -use Encore\Admin\Grid; +use OpenAdmin\Admin\Controllers\AdminController; +use OpenAdmin\Admin\Form; +use OpenAdmin\Admin\Grid; use Tests\Models\Tag; use Tests\Models\User; diff --git a/tests/models/Tree.php b/tests/models/Tree.php index c42419a0..4d444a72 100644 --- a/tests/models/Tree.php +++ b/tests/models/Tree.php @@ -2,8 +2,8 @@ namespace Tests\Models; -use Encore\Admin\Traits\ModelTree; use Illuminate\Database\Eloquent\Model; +use OpenAdmin\Admin\Traits\ModelTree; class Tree extends Model { From 4377465d7633d8b381c57c87d3b387838b30260f Mon Sep 17 00:00:00 2001 From: Talemul Islam Date: Fri, 23 May 2025 21:00:43 +0600 Subject: [PATCH 08/10] update test --- .env.test.mysql | 8 ++++ .env.test.pgsql | 8 ++++ .env.test.sqlite | 4 ++ .github/workflows/ci.yml | 46 ++++++++++++++++++++++ .github/workflows/tests.yml | 51 +++++++++++++++++++++++++ .phpunit.result.cache | 1 + Dockerfile | 18 +++++++++ composer.json_bk | 72 +++++++++++++++++++++++++++++++++++ composer.zip | Bin 0 -> 1116 bytes docker-compose.yml | 44 +++++++++++++++++++++ pest.php | 6 +++ test-all.bat | 48 +++++++++++++++++++++++ test-all.sh | 20 ++++++++++ test-coverage-all.bat | 32 ++++++++++++++++ test-coverage-sqlite.bat | 5 +++ test-coverage.bat | 5 +++ test-sqlite.bat | 4 ++ tests/CreatesApplication.php | 17 +++++++++ tests/ExampleTest.php | 5 +++ tests/Feature/DummyTest.php | 5 +++ tests/Unit/DummyUnitTest.php | 5 +++ 21 files changed, 404 insertions(+) create mode 100644 .env.test.mysql create mode 100644 .env.test.pgsql create mode 100644 .env.test.sqlite create mode 100644 .github/workflows/ci.yml create mode 100644 .github/workflows/tests.yml create mode 100644 .phpunit.result.cache create mode 100644 Dockerfile create mode 100644 composer.json_bk create mode 100644 composer.zip create mode 100644 docker-compose.yml create mode 100644 pest.php create mode 100644 test-all.bat create mode 100644 test-all.sh create mode 100644 test-coverage-all.bat create mode 100644 test-coverage-sqlite.bat create mode 100644 test-coverage.bat create mode 100644 test-sqlite.bat create mode 100644 tests/CreatesApplication.php create mode 100644 tests/ExampleTest.php create mode 100644 tests/Feature/DummyTest.php create mode 100644 tests/Unit/DummyUnitTest.php diff --git a/.env.test.mysql b/.env.test.mysql new file mode 100644 index 00000000..552988ee --- /dev/null +++ b/.env.test.mysql @@ -0,0 +1,8 @@ +APP_ENV=testing +APP_KEY=base64:SomeFakeKeyForTesting== +DB_CONNECTION=mysql +DB_HOST=mysql +DB_PORT=3306 +DB_DATABASE=open_admin_test +DB_USERNAME=root +DB_PASSWORD=root diff --git a/.env.test.pgsql b/.env.test.pgsql new file mode 100644 index 00000000..466776f5 --- /dev/null +++ b/.env.test.pgsql @@ -0,0 +1,8 @@ +APP_ENV=testing +APP_KEY=base64:SomeFakeKeyForTesting== +DB_CONNECTION=pgsql +DB_HOST=postgres +DB_PORT=5432 +DB_DATABASE=open_admin_test +DB_USERNAME=root +DB_PASSWORD=root diff --git a/.env.test.sqlite b/.env.test.sqlite new file mode 100644 index 00000000..f606c836 --- /dev/null +++ b/.env.test.sqlite @@ -0,0 +1,4 @@ +APP_ENV=testing +APP_KEY=base64:SomeFakeKeyForTesting== +DB_CONNECTION=sqlite +DB_DATABASE=:memory: diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 00000000..c48ad064 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,46 @@ + +name: Pest Tests (SQLite) + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +jobs: + pest-tests: + runs-on: ubuntu-latest + + services: + sqlite: + image: nouchka/sqlite3 + ports: + - 3306:3306 + + steps: + - uses: actions/checkout@v3 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: '8.3' + extensions: mbstring, pdo_sqlite + coverage: xdebug + + - name: Install Composer dependencies + run: composer install --no-interaction --prefer-dist --optimize-autoloader + + - name: Prepare environment + run: cp .env.test.sqlite .env + + - name: Generate Application Key + run: php artisan key:generate || true + + - name: Run Pest Tests with Coverage + run: ./vendor/bin/pest --coverage-html=coverage-report + + - name: Upload coverage report + uses: actions/upload-artifact@v3 + with: + name: coverage-report + path: coverage-report diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 00000000..ded482ef --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,51 @@ + +name: Pest Test Suite + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +jobs: + pest: + runs-on: ubuntu-latest + services: + mysql: + image: mysql:8 + env: + MYSQL_ROOT_PASSWORD: root + MYSQL_DATABASE: open_admin_test + ports: + - 3306:3306 + options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3 + + postgres: + image: postgres:15 + env: + POSTGRES_DB: open_admin_test + POSTGRES_USER: root + POSTGRES_PASSWORD: root + ports: + - 5432:5432 + options: >- + --health-cmd="pg_isready -U root -d open_admin_test" + --health-interval=10s + --health-timeout=5s + --health-retries=3 + + steps: + - uses: actions/checkout@v3 + + - name: Set up PHP + uses: shivammathur/setup-php@v2 + with: + php-version: '8.3' + extensions: mbstring, pdo_mysql, pdo_pgsql, sqlite3 + coverage: xdebug + + - name: Install dependencies + run: composer install --prefer-dist --no-interaction + + - name: Run Pest Tests with Coverage + run: vendor/bin/pest --coverage --min=85 diff --git a/.phpunit.result.cache b/.phpunit.result.cache new file mode 100644 index 00000000..5002870c --- /dev/null +++ b/.phpunit.result.cache @@ -0,0 +1 @@ +{"version":1,"defects":{"AuthTest::testLoginPage":3,"\/var\/www\/tests\/Feature\/DummyTest.php::it":4,"C:\\Users\\LAPTOP GADGET\\Downloads\\laravel plugin\\laravel_plugin_with_coverage_and_ci_final\\tests\\Feature\\DummyTest.php::it dummy test runs":4},"times":{"AuthTest::testLoginPage":2.052,"\/var\/www\/tests\/Feature\/DummyTest.php::it":24.811,"C:\\Users\\LAPTOP GADGET\\Downloads\\laravel plugin\\laravel_plugin_with_coverage_and_ci_final\\tests\\Unit\\DummyUnitTest.php::it dummy unit test runs":0.01,"C:\\Users\\LAPTOP GADGET\\Downloads\\laravel plugin\\laravel_plugin_with_coverage_and_ci_final\\tests\\Feature\\DummyTest.php::it dummy test runs":16.784}} \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..79aeb062 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,18 @@ +FROM php:8.3-fpm + +# Install system dependencies + pdo extensions +RUN apt-get update \ + && apt-get install -y \ + git curl zip unzip libzip-dev libpng-dev libonig-dev libxml2-dev libsqlite3-dev libpq-dev \ + && docker-php-ext-install \ + pdo_mysql \ + pdo_sqlite \ + pdo_pgsql \ + zip + +# Install Composer +COPY --from=composer:latest /usr/bin/composer /usr/bin/composer + +WORKDIR /var/www +COPY . . +CMD ["sh", "-c", "composer install && vendor/bin/pest"] diff --git a/composer.json_bk b/composer.json_bk new file mode 100644 index 00000000..d2560441 --- /dev/null +++ b/composer.json_bk @@ -0,0 +1,72 @@ +{ + "name": "open-admin-org/open-admin", + "description": "open-admin. Open-source Laravel Admin panel. No pro or paid package, free & open. Based on laravel-admin, with special thanks to z-song", + "type": "library", + "keywords": ["laravel", "admin", "grid", "form", "open-admin","open","free"], + "homepage": "https://github.com/open-admin-org/open-admin", + "license": "MIT", + "authors": [ + { + "name": "Sjors Broersen | Open-Admin.org", + "email": "info@open-admin.org" + } + ], + "require": { + "php": "~7.3|~8.0", + "symfony/dom-crawler": "~3.1|~4.0|~5.0|~6.0|~7.0", + "laravel/framework": ">=7.0|>=8.0|^10.0|^11.0|^12.0", + "doctrine/dbal": "2.*|3.*|4.*|5.*", + "fakerphp/faker": "^1.24" + }, + "require-dev": { + "laravel/laravel": ">=8.0|^10.0|^11.0|^12.0", + "intervention/image": "~2.3", + "spatie/phpunit-watcher": "^1.22.0", + "phpunit/phpunit": "9.6", + "laravel/browser-kit-testing": "^6.4", + "orchestra/testbench": "8.13", + "pestphp/pest": "^1.22", + "pestphp/pest-plugin-laravel": "^1.4" + }, + "autoload": { + "psr-4": { + "OpenAdmin\\Admin\\": "src/" + }, + "files": [ + "src/helpers.php" + ] + }, + "autoload-dev": { + "psr-4": { + "Tests\\Models\\": "tests/models", + "Tests\\Controllers\\": "tests/controllers" + }, + "classmap": [ + "tests/TestCase.php" + ] + }, + "scripts": { + "sass": "sass --watch resources/assets/open-admin/scss/styles.scss:resources/assets/open-admin/css/styles.css resources/assets/open-admin/scss/pages:resources/assets/open-admin/css/pages --style compressed", + "test": "./vendor/bin/phpunit" + }, + "suggest": { + "intervention/image": "Required to handling and manipulation upload images (~2.3).", + "spatie/eloquent-sortable": "Required to built orderable gird." + }, + "extra": { + "laravel": { + "providers": [ + "OpenAdmin\\Admin\\AdminServiceProvider" + ], + "aliases": { + "Admin": "OpenAdmin\\Admin\\Facades\\Admin" + } + } + }, + "config": { + "process-timeout": 0, + "allow-plugins": { + "pestphp/pest-plugin": true + } + } +} diff --git a/composer.zip b/composer.zip new file mode 100644 index 0000000000000000000000000000000000000000..cd6df952fd285e205f1f1ae60b719d782999f591 GIT binary patch literal 1116 zcmWIWW@Zs#-~d9&ip^0BNPw3?fgw3Rw;;bbwMZ|kI6tqnf}4Sn1*8H@gof}kuseU& z%3z7o$w+k7%4iLX&cAIYQm236zr%~fi0+OqVe_|4TW&-pI5d`NU)!gv>EM0bD7`C$ zf8~xmng8GBIiD0ic}^!n#kKDFsp5}+FRM4rJF<#vQuf3hQaP)-yl!7focY#n@@Brs zhVy~f9j$MxPk59cSA9K!?@_Z;DZAUBgYJvM#Ck;PEdv(|^JO}Vn>;BFJv4KMQo|2d z1AWbVTKugAVKb(=p8o5jQ!;}y-g(_r!Ng^6?sPvm!aphF^xCS#NO$L+c?%9bEvx4{ z-Fo=Y<(vCGk6T&_d#2Cv@Vdf!KDb@<{O@JQ`DaC(e^Pe1=$Y0E&w4R)?uFm3M}|$B zbk^nBx>J6;FTIdi)Bi>Oe*Mk7)oN#C+gSSVQX%Acf?Is zDLY)^%|7)~8|T)!yY7F_>py7y#(DRhTU{U4UOXZ6UBvTMaX^q)S>`s+3Cy|?$D zO|z_apWzB$YPqVFvFCxeWz^c^pK7+&9Xu?`ug|{aE^BJAit)>P&wPG9Gd&oVA2)fy z)$124W!ww*NK6pd<6ohha@55&S^vrBtEzjGtKv^QxBU=umht2y9X*M^r7HTz<{Hbf z$$4<^kgiBv{6=lnqE*YMUNK|1*Z9=uRLND=OTV1rzTJ&jy+Bc!ReH7at^mdPZ?DK0 zy-kp|I9xY5+`ZP?ar=jcmveToeQ*pGGrX>C`R<|YBnSC`)Sg)lXVZJCRo!b{v#nCi zKkW&9ALtS_d)bmJH;SbMWh&+t9h6+&mH432=lI{fJI)`JPyYXG+3Xn`kK5ete|zt3 zHgj`G_FX>{V*}HrQ=b^zm%VSd=+VRz6+UP6pD@%Hf4(T1P_tV3_qFuUJC+`|`2L@} z*>EmE>1)TQyWf(-p1D=Vul&`qP?vw&hd!?NoYA*0y=PCWN|O8Qv)SXefG9_<`UlCk zOr1Bb&N}n_Ub>ym$*+^HU;od3@9?EhCh>YFms`4tXi8ghuexp;81VQdYt9R&$h0ZT zTMy?rU73AFYS%K&(_(e?MkoJgW_up|+btEDsPUcU?4qEs>%Dv6nEj*c{P%oE$;V=`w$_VYZQSI(qJdZD)yFTKf9se6yxBQax7IPt zU}j*L%E`bG;LXS+!i>oD$a1_467V8mTO){xzX)JuU<4Hb0p6@^AjOP87!0I81Fd3U F008O2>&yTE literal 0 HcmV?d00001 diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 00000000..5f9e6bd0 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,44 @@ +services: + app: + build: + context: . + dockerfile: Dockerfile + volumes: + - .:/var/www + working_dir: /var/www + depends_on: + - mysql + - postgres + environment: + DB_CONNECTION: mysql + DB_HOST: mysql + DB_PORT: 3306 + DB_DATABASE: open_admin_test + DB_USERNAME: root + DB_PASSWORD: root + tty: true + + mysql: + image: mysql:8 + environment: + MYSQL_ROOT_PASSWORD: root + MYSQL_DATABASE: open_admin_test + ports: + - "3307:3306" + volumes: + - db_data:/var/lib/mysql + + postgres: + image: postgres:14 + environment: + POSTGRES_USER: root + POSTGRES_PASSWORD: root + POSTGRES_DB: open_admin_test + ports: + - "5433:5432" + volumes: + - pg_data:/var/lib/postgresql/data + +volumes: + db_data: + pg_data: \ No newline at end of file diff --git a/pest.php b/pest.php new file mode 100644 index 00000000..95620395 --- /dev/null +++ b/pest.php @@ -0,0 +1,6 @@ +in('tests/Unit'); diff --git a/test-all.bat b/test-all.bat new file mode 100644 index 00000000..73d7d50b --- /dev/null +++ b/test-all.bat @@ -0,0 +1,48 @@ +@echo off +echo Installing Composer dependencies... +docker compose run --rm app composer install + +echo. +echo ================================================ +echo Running Pest Tests with MySQL... +echo ================================================ +docker compose run --rm ^ + -e DB_CONNECTION=mysql ^ + -e DB_HOST=mysql ^ + -e DB_PORT=3306 ^ + -e DB_DATABASE=open_admin_test ^ + -e DB_USERNAME=root ^ + -e DB_PASSWORD=root ^ + app vendor/bin/pest + +echo. +echo ================================================ +echo Running Pest Tests with PostgreSQL... +echo ================================================ +docker compose run --rm ^ + -e DB_CONNECTION=pgsql ^ + -e DB_HOST=postgres ^ + -e DB_PORT=5432 ^ + -e DB_DATABASE=open_admin_test ^ + -e DB_USERNAME=root ^ + -e DB_PASSWORD=root ^ + app vendor/bin/pest + +echo. +echo ================================================ +echo Preparing SQLite database file... +echo ================================================ +docker compose run --rm app sh -c "mkdir -p database && touch database/database.sqlite" + +echo. +echo ================================================ +echo Running Pest Tests with SQLite... +echo ================================================ +docker compose run --rm ^ + -e DB_CONNECTION=sqlite ^ + -e DB_DATABASE=/var/www/database/database.sqlite ^ + app vendor/bin/pest + +echo. +echo All tests completed across MySQL, PostgreSQL, and SQLite! +pause diff --git a/test-all.sh b/test-all.sh new file mode 100644 index 00000000..53591abe --- /dev/null +++ b/test-all.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +set -e + +echo "🔄 Installing composer dependencies..." +docker-compose run --rm app composer install + +echo "🔍 Running Pest Tests with MySQL..." +cp .env.mysql .env +docker-compose run --rm app vendor/bin/pest --coverage + +echo "🔍 Running Pest Tests with PostgreSQL..." +cp .env.pgsql .env +docker-compose run --rm app vendor/bin/pest --coverage + +echo "🔍 Running Pest Tests with SQLite..." +cp .env.sqlite .env +docker-compose run --rm app vendor/bin/pest --coverage + +echo "✅ All tests completed across MySQL, PostgreSQL, and SQLite!" \ No newline at end of file diff --git a/test-coverage-all.bat b/test-coverage-all.bat new file mode 100644 index 00000000..89a815ee --- /dev/null +++ b/test-coverage-all.bat @@ -0,0 +1,32 @@ +@echo off +echo Cleaning up previous coverage files... +rmdir /S /Q coverage-mysql 2>nul +rmdir /S /Q coverage-pgsql 2>nul +rmdir /S /Q coverage-sqlite 2>nul +rmdir /S /Q coverage-report 2>nul + +echo ================================================ +echo Running Pest Tests with MySQL... +echo ================================================ +docker compose run --rm -e DB_CONNECTION=mysql -e DB_HOST=mysql -e DB_PORT=3307 -e DB_DATABASE=testing -e DB_USERNAME=root -e DB_PASSWORD=root -e PEST_ARGS="--coverage-html coverage-mysql" app vendor/bin/pest --coverage-html coverage-mysql + +echo ================================================ +echo Running Pest Tests with PostgreSQL... +echo ================================================ +docker compose run --rm -e DB_CONNECTION=pgsql -e DB_HOST=pgsql -e DB_PORT=5433 -e DB_DATABASE=testing -e DB_USERNAME=postgres -e DB_PASSWORD=postgres -e PEST_ARGS="--coverage-html coverage-pgsql" app vendor/bin/pest --coverage-html coverage-pgsql + +echo ================================================ +echo Running Pest Tests with SQLite... +echo ================================================ +docker compose run --rm -e DB_CONNECTION=sqlite -e DB_DATABASE=/var/www/database/database.sqlite -e PEST_ARGS="--coverage-html coverage-sqlite" app vendor/bin/pest --coverage-html coverage-sqlite + +echo ================================================ +echo Merging Coverage... +echo ================================================ +php vendor\bin\phpcov merge coverage-mysql coverage-pgsql coverage-sqlite --html coverage-report + +echo Opening combined coverage report... +start coverage-report\index.html + +echo Done +pause diff --git a/test-coverage-sqlite.bat b/test-coverage-sqlite.bat new file mode 100644 index 00000000..dbd79673 --- /dev/null +++ b/test-coverage-sqlite.bat @@ -0,0 +1,5 @@ +@echo off +echo Running Pest HTML coverage for SQLite... +docker compose run --rm -e DB_CONNECTION=sqlite -e DB_DATABASE=/var/www/database/database.sqlite app vendor/bin/pest --coverage-html coverage-sqlite +start coverage-sqlite\index.html +pause diff --git a/test-coverage.bat b/test-coverage.bat new file mode 100644 index 00000000..969816f2 --- /dev/null +++ b/test-coverage.bat @@ -0,0 +1,5 @@ +@echo off +echo Running Pest Test Suite with HTML Coverage... +docker compose run --rm -e PEST_ARGS="--coverage-html coverage-report" app vendor/bin/pest --coverage-html coverage-report +start coverage-report\index.html +pause diff --git a/test-sqlite.bat b/test-sqlite.bat new file mode 100644 index 00000000..e5a3b1a6 --- /dev/null +++ b/test-sqlite.bat @@ -0,0 +1,4 @@ +@echo off +echo Running Pest Tests with SQLite... +docker compose run --rm -e DB_CONNECTION=sqlite -e DB_DATABASE=/var/www/database/database.sqlite app vendor/bin/pest +pause diff --git a/tests/CreatesApplication.php b/tests/CreatesApplication.php new file mode 100644 index 00000000..1ad372d3 --- /dev/null +++ b/tests/CreatesApplication.php @@ -0,0 +1,17 @@ +make(Kernel::class)->bootstrap(); + + return $app; + } +} diff --git a/tests/ExampleTest.php b/tests/ExampleTest.php new file mode 100644 index 00000000..61cd84c3 --- /dev/null +++ b/tests/ExampleTest.php @@ -0,0 +1,5 @@ +toBeTrue(); +}); diff --git a/tests/Feature/DummyTest.php b/tests/Feature/DummyTest.php new file mode 100644 index 00000000..521dcbc4 --- /dev/null +++ b/tests/Feature/DummyTest.php @@ -0,0 +1,5 @@ +toBeTrue(); +}); diff --git a/tests/Unit/DummyUnitTest.php b/tests/Unit/DummyUnitTest.php new file mode 100644 index 00000000..44e7b2f1 --- /dev/null +++ b/tests/Unit/DummyUnitTest.php @@ -0,0 +1,5 @@ +toBeTrue(); +}); From e415efb0dc58a61def755d997a763574ded064c2 Mon Sep 17 00:00:00 2001 From: Talemul Islam Date: Sun, 25 May 2025 00:19:22 +0600 Subject: [PATCH 09/10] update name --- .github/FUNDING.yml | 1 + .github/ISSUE_TEMPLATE/bug.yml | 66 +++++++++++++ .github/ISSUE_TEMPLATE/bug_report.md | 2 +- .github/ISSUE_TEMPLATE/config.yml | 11 +++ .github/dependabot.yml | 19 ++++ .github/workflows/dependabot-auto-merge.yml | 33 +++++++ .../workflows/fix-php-code-style-issues.yml | 28 ++++++ .github/workflows/phpstan.yml | 28 ++++++ .github/workflows/run-tests.yml | 63 +++++++++++++ .github/workflows/update-changelog.yml | 32 +++++++ .gitignore | 4 +- .phpunit.result.cache | 2 +- CHANGELOG.md | 2 +- CONTRIBUTING.md | 4 +- README.md | 94 +++++++++---------- composer.json | 20 ++-- composer.json_bk | 18 ++-- config/admin.php | 48 +++++----- resources/assets/open-admin/scss/styles.scss | 2 +- .../views/dashboard/extensions.blade.php | 2 +- resources/views/dashboard/title.blade.php | 6 +- resources/views/form/hasmanytab.blade.php | 8 +- resources/views/form/hasmanytable.blade.php | 2 +- resources/views/grid/batch-actions.blade.php | 2 +- .../grid/inline-edit/belongsto.blade.php | 6 +- resources/views/grid/selector.blade.php | 6 +- resources/views/login.blade.php | 2 +- resources/views/partials/exception.blade.php | 4 +- resources/views/partials/footer.blade.php | 4 +- resources/views/widgets/tab.blade.php | 4 +- src/Actions/Action.php | 6 +- src/Actions/Authorizable.php | 4 +- src/Actions/BatchAction.php | 2 +- src/Actions/GridAction.php | 4 +- src/Actions/Interactor/Dialog.php | 2 +- src/Actions/Interactor/Form.php | 16 ++-- src/Actions/Interactor/Interactor.php | 4 +- src/Actions/Response.php | 2 +- src/Actions/RowAction.php | 6 +- src/Actions/SweatAlert2.php | 2 +- src/Actions/Toastr.php | 2 +- src/Admin.php | 36 +++---- src/AdminServiceProvider.php | 16 ++-- src/Auth/Database/AdminTablesSeeder.php | 2 +- src/Auth/Database/Administrator.php | 6 +- src/Auth/Database/HasPermissions.php | 2 +- src/Auth/Database/Menu.php | 6 +- src/Auth/Database/OperationLog.php | 4 +- src/Auth/Database/Permission.php | 4 +- src/Auth/Database/Role.php | 4 +- src/Auth/Permission.php | 6 +- src/Console/ActionCommand.php | 2 +- src/Console/AdminCommand.php | 4 +- src/Console/ConfigCommand.php | 4 +- src/Console/ControllerCommand.php | 2 +- src/Console/CreateUserCommand.php | 2 +- src/Console/DevLinksCommand.php | 8 +- src/Console/ExportSeedCommand.php | 4 +- src/Console/ExtendCommand.php | 4 +- src/Console/FormCommand.php | 2 +- src/Console/GenerateMenuCommand.php | 4 +- src/Console/ImportCommand.php | 6 +- src/Console/InstallCommand.php | 4 +- src/Console/MakeCommand.php | 4 +- src/Console/MenuCommand.php | 4 +- src/Console/MinifyCommand.php | 6 +- src/Console/PermissionCommand.php | 4 +- src/Console/PublishCommand.php | 6 +- src/Console/ResetPasswordCommand.php | 2 +- src/Console/ResourceGenerator.php | 2 +- src/Console/UninstallCommand.php | 8 +- src/Console/stubs/AuthController.stub | 2 +- src/Console/stubs/ExampleController.stub | 8 +- src/Console/stubs/HomeController.stub | 12 +-- src/Console/stubs/action.stub | 2 +- src/Console/stubs/blank.stub | 2 +- src/Console/stubs/bootstrap.stub | 8 +- src/Console/stubs/controller.stub | 8 +- src/Console/stubs/extension/README.md.stub | 2 +- .../stubs/extension/composer.json.stub | 4 +- src/Console/stubs/extension/controller.stub | 2 +- src/Console/stubs/extension/extension.stub | 2 +- src/Console/stubs/extension/view.stub | 2 +- src/Console/stubs/form.stub | 2 +- src/Console/stubs/grid-batch-action.stub | 2 +- src/Console/stubs/grid-row-action.stub | 2 +- src/Console/stubs/step-form.stub | 2 +- src/Controllers/AdminController.php | 6 +- src/Controllers/AuthController.php | 8 +- src/Controllers/Dashboard.php | 44 ++++----- src/Controllers/HandleController.php | 14 +-- src/Controllers/HasResourceActions.php | 4 +- src/Controllers/LogController.php | 6 +- src/Controllers/MenuController.php | 18 ++-- src/Controllers/ModelForm.php | 2 +- src/Controllers/PermissionController.php | 8 +- src/Controllers/RoleController.php | 8 +- src/Controllers/UserController.php | 8 +- src/Exception/Handler.php | 2 +- src/Extension.php | 8 +- src/Facades/Admin.php | 16 ++-- src/Form.php | 28 +++--- src/Form/Builder.php | 8 +- src/Form/Concerns/HandleCascadeFields.php | 4 +- src/Form/Concerns/HasFields.php | 4 +- src/Form/Concerns/HasFormAttributes.php | 2 +- src/Form/Concerns/HasHooks.php | 2 +- src/Form/EmbeddedForm.php | 6 +- src/Form/Field.php | 10 +- src/Form/Field/BelongsTo.php | 4 +- src/Form/Field/BelongsToMany.php | 4 +- src/Form/Field/Button.php | 4 +- src/Form/Field/Captcha.php | 4 +- src/Form/Field/CascadeGroup.php | 4 +- src/Form/Field/Checkbox.php | 2 +- src/Form/Field/CheckboxButton.php | 2 +- src/Form/Field/CheckboxCard.php | 2 +- src/Form/Field/Color.php | 6 +- src/Form/Field/Currency.php | 4 +- src/Form/Field/Date.php | 2 +- src/Form/Field/DateMultiple.php | 2 +- src/Form/Field/DateRange.php | 6 +- src/Form/Field/Datetime.php | 2 +- src/Form/Field/DatetimeRange.php | 2 +- src/Form/Field/Decimal.php | 4 +- src/Form/Field/Display.php | 4 +- src/Form/Field/Divider.php | 4 +- src/Form/Field/Editor.php | 4 +- src/Form/Field/Email.php | 4 +- src/Form/Field/Embeds.php | 8 +- src/Form/Field/Fieldset.php | 2 +- src/Form/Field/File.php | 12 +-- src/Form/Field/HasMany.php | 14 +-- src/Form/Field/Hidden.php | 4 +- src/Form/Field/Html.php | 4 +- src/Form/Field/Icon.php | 4 +- src/Form/Field/Id.php | 4 +- src/Form/Field/Image.php | 6 +- src/Form/Field/Ip.php | 4 +- src/Form/Field/KeyValue.php | 6 +- src/Form/Field/ListField.php | 8 +- src/Form/Field/Listbox.php | 6 +- src/Form/Field/Map.php | 8 +- src/Form/Field/Month.php | 2 +- src/Form/Field/MultipleFile.php | 14 +-- src/Form/Field/MultipleImage.php | 4 +- src/Form/Field/MultipleSelect.php | 2 +- src/Form/Field/Nullable.php | 4 +- src/Form/Field/Number.php | 6 +- src/Form/Field/Password.php | 2 +- src/Form/Field/PhoneNumber.php | 4 +- src/Form/Field/Radio.php | 6 +- src/Form/Field/RadioButton.php | 2 +- src/Form/Field/RadioCard.php | 4 +- src/Form/Field/Rate.php | 2 +- src/Form/Field/Select.php | 14 +-- src/Form/Field/Slider.php | 6 +- src/Form/Field/SwitchField.php | 4 +- src/Form/Field/Table.php | 6 +- src/Form/Field/Tags.php | 4 +- src/Form/Field/Text.php | 8 +- src/Form/Field/Textarea.php | 8 +- src/Form/Field/Time.php | 2 +- src/Form/Field/TimeRange.php | 6 +- src/Form/Field/Timezone.php | 2 +- src/Form/Field/Traits/BelongsToRelation.php | 10 +- src/Form/Field/Traits/CanCascadeFields.php | 6 +- src/Form/Field/Traits/HasMediaPicker.php | 10 +- src/Form/Field/Traits/HasNumberModifiers.php | 2 +- src/Form/Field/Traits/HasValuePicker.php | 8 +- src/Form/Field/Traits/ImageField.php | 2 +- src/Form/Field/Traits/PlainInput.php | 2 +- src/Form/Field/Traits/Sortable.php | 4 +- src/Form/Field/Traits/UploadField.php | 4 +- src/Form/Field/Url.php | 4 +- src/Form/Field/ValuePicker.php | 6 +- src/Form/Field/Year.php | 2 +- src/Form/Footer.php | 2 +- src/Form/Layout/Column.php | 4 +- src/Form/Layout/Layout.php | 4 +- src/Form/NestedForm.php | 12 +-- src/Form/Row.php | 4 +- src/Form/Tab.php | 4 +- src/Form/Tools.php | 2 +- src/Grid.php | 20 ++-- src/Grid/Actions/Delete.php | 6 +- src/Grid/Actions/Edit.php | 4 +- src/Grid/Actions/Show.php | 4 +- src/Grid/Column.php | 10 +- src/Grid/Column/CheckFilter.php | 6 +- src/Grid/Column/ExtendDisplay.php | 8 +- src/Grid/Column/Filter.php | 6 +- src/Grid/Column/HasHeader.php | 6 +- src/Grid/Column/Help.php | 2 +- src/Grid/Column/InlineEditing.php | 4 +- src/Grid/Column/InputFilter.php | 6 +- src/Grid/Column/RangeFilter.php | 6 +- src/Grid/Column/Sorter.php | 2 +- src/Grid/Concerns/CanDoubleClick.php | 4 +- src/Grid/Concerns/CanExportGrid.php | 8 +- src/Grid/Concerns/CanFixColumns.php | 4 +- src/Grid/Concerns/CanFixHeader.php | 4 +- src/Grid/Concerns/CanHidesColumns.php | 6 +- src/Grid/Concerns/HasActions.php | 4 +- src/Grid/Concerns/HasElementNames.php | 2 +- src/Grid/Concerns/HasFilter.php | 6 +- src/Grid/Concerns/HasFooter.php | 4 +- src/Grid/Concerns/HasHeader.php | 4 +- src/Grid/Concerns/HasHotKeys.php | 4 +- src/Grid/Concerns/HasQuickCreate.php | 4 +- src/Grid/Concerns/HasQuickSearch.php | 8 +- src/Grid/Concerns/HasSelector.php | 6 +- src/Grid/Concerns/HasTools.php | 4 +- src/Grid/Concerns/HasTotalRow.php | 4 +- src/Grid/Displayers/AbstractDisplayer.php | 6 +- src/Grid/Displayers/Actions/Actions.php | 16 ++-- .../Displayers/Actions/ContextMenuActions.php | 2 +- .../Displayers/Actions/DropdownActions.php | 2 +- src/Grid/Displayers/Badge.php | 2 +- src/Grid/Displayers/BelongsTo.php | 10 +- src/Grid/Displayers/BelongsToMany.php | 2 +- src/Grid/Displayers/Button.php | 2 +- src/Grid/Displayers/Carousel.php | 4 +- src/Grid/Displayers/Checkbox.php | 4 +- src/Grid/Displayers/Copyable.php | 4 +- src/Grid/Displayers/DateFormat.php | 2 +- src/Grid/Displayers/Datetime.php | 4 +- src/Grid/Displayers/Downloadable.php | 2 +- src/Grid/Displayers/Editable.php | 4 +- src/Grid/Displayers/Expand.php | 6 +- src/Grid/Displayers/Image.php | 2 +- src/Grid/Displayers/Input.php | 4 +- src/Grid/Displayers/Label.php | 2 +- src/Grid/Displayers/Limit.php | 4 +- src/Grid/Displayers/Link.php | 2 +- src/Grid/Displayers/Modal.php | 6 +- src/Grid/Displayers/MultipleSelect.php | 4 +- src/Grid/Displayers/Orderable.php | 4 +- src/Grid/Displayers/Prefix.php | 2 +- src/Grid/Displayers/ProgressBar.php | 2 +- src/Grid/Displayers/QRCode.php | 2 +- src/Grid/Displayers/Radio.php | 4 +- src/Grid/Displayers/RowSelector.php | 2 +- src/Grid/Displayers/Secret.php | 4 +- src/Grid/Displayers/Select.php | 4 +- src/Grid/Displayers/Suffix.php | 2 +- src/Grid/Displayers/SwitchDisplay.php | 4 +- src/Grid/Displayers/SwitchGroup.php | 4 +- src/Grid/Displayers/Table.php | 2 +- src/Grid/Displayers/Text.php | 2 +- src/Grid/Displayers/Textarea.php | 4 +- src/Grid/Displayers/Upload.php | 4 +- src/Grid/Exporter.php | 6 +- src/Grid/Exporters/AbstractExporter.php | 6 +- src/Grid/Exporters/CsvExporter.php | 4 +- src/Grid/Exporters/ExcelExporter.php | 2 +- src/Grid/Exporters/ExporterInterface.php | 2 +- src/Grid/Filter.php | 8 +- src/Grid/Filter/AbstractFilter.php | 18 ++-- src/Grid/Filter/Between.php | 4 +- src/Grid/Filter/Date.php | 2 +- src/Grid/Filter/Day.php | 2 +- src/Grid/Filter/EndsWith.php | 2 +- src/Grid/Filter/Equal.php | 2 +- src/Grid/Filter/Group.php | 4 +- src/Grid/Filter/Gt.php | 2 +- src/Grid/Filter/Hidden.php | 2 +- src/Grid/Filter/Ilike.php | 2 +- src/Grid/Filter/In.php | 2 +- src/Grid/Filter/Layout/Column.php | 4 +- src/Grid/Filter/Layout/Layout.php | 4 +- src/Grid/Filter/Like.php | 2 +- src/Grid/Filter/Lt.php | 2 +- src/Grid/Filter/Month.php | 2 +- src/Grid/Filter/NotEqual.php | 2 +- src/Grid/Filter/NotIn.php | 2 +- src/Grid/Filter/Presenter/Checkbox.php | 2 +- src/Grid/Filter/Presenter/DateTime.php | 4 +- src/Grid/Filter/Presenter/MultipleSelect.php | 4 +- src/Grid/Filter/Presenter/Presenter.php | 4 +- src/Grid/Filter/Presenter/Radio.php | 4 +- src/Grid/Filter/Presenter/Select.php | 4 +- src/Grid/Filter/Presenter/Text.php | 4 +- src/Grid/Filter/Scope.php | 2 +- src/Grid/Filter/StartsWith.php | 2 +- src/Grid/Filter/Time.php | 2 +- src/Grid/Filter/Where.php | 2 +- src/Grid/Filter/Year.php | 2 +- src/Grid/Model.php | 6 +- src/Grid/Row.php | 2 +- src/Grid/Selectable.php | 8 +- src/Grid/Selectable/BrowserBtn.php | 2 +- src/Grid/Selectable/Checkbox.php | 4 +- src/Grid/Selectable/Radio.php | 4 +- src/Grid/Simple.php | 4 +- src/Grid/Tools.php | 16 ++-- src/Grid/Tools/AbstractTool.php | 4 +- src/Grid/Tools/BatchActions.php | 10 +- src/Grid/Tools/BatchDelete.php | 4 +- src/Grid/Tools/BatchEdit.php | 4 +- src/Grid/Tools/ColumnSelector.php | 6 +- src/Grid/Tools/CreateButton.php | 4 +- src/Grid/Tools/ExportButton.php | 6 +- src/Grid/Tools/FilterButton.php | 4 +- src/Grid/Tools/FixColumns.php | 4 +- src/Grid/Tools/Footer.php | 4 +- src/Grid/Tools/Header.php | 4 +- src/Grid/Tools/Paginator.php | 4 +- src/Grid/Tools/PerPageSelector.php | 6 +- src/Grid/Tools/QuickCreate.php | 10 +- src/Grid/Tools/QuickSearch.php | 4 +- src/Grid/Tools/Selector.php | 2 +- src/Grid/Tools/TotalRow.php | 4 +- src/Layout/Buildable.php | 2 +- src/Layout/Column.php | 4 +- src/Layout/Content.php | 4 +- src/Layout/Row.php | 2 +- src/Middleware/Authenticate.php | 4 +- src/Middleware/Bootstrap.php | 4 +- src/Middleware/LogOperation.php | 6 +- src/Middleware/Permission.php | 6 +- src/Middleware/Pjax.php | 4 +- src/Middleware/Session.php | 2 +- src/Middleware/Throttle.php | 4 +- src/Show.php | 12 +-- src/Show/AbstractField.php | 2 +- src/Show/Divider.php | 2 +- src/Show/Field.php | 8 +- src/Show/Panel.php | 4 +- src/Show/Relation.php | 6 +- src/Show/Tools.php | 2 +- src/Traits/AdminBuilder.php | 8 +- src/Traits/DefaultDatetimeFormat.php | 2 +- src/Traits/HasAssets.php | 64 ++++++------- src/Traits/HasCustomHooks.php | 2 +- src/Traits/ModelTree.php | 4 +- src/Traits/Resizable.php | 2 +- src/Traits/ShouldSnakeAttributes.php | 4 +- src/Tree.php | 4 +- src/Tree/Tools.php | 4 +- src/Widgets/Alert.php | 2 +- src/Widgets/Box.php | 2 +- src/Widgets/Callout.php | 2 +- src/Widgets/Carousel.php | 2 +- src/Widgets/Collapse.php | 2 +- src/Widgets/ContainsForms.php | 4 +- src/Widgets/Form.php | 12 +-- src/Widgets/InfoBox.php | 2 +- src/Widgets/MultipleSteps.php | 4 +- src/Widgets/Navbar.php | 2 +- src/Widgets/Navbar/Fullscreen.php | 4 +- src/Widgets/Navbar/RefreshButton.php | 4 +- src/Widgets/StepForm.php | 2 +- src/Widgets/Tab.php | 2 +- src/Widgets/Table.php | 2 +- src/Widgets/Widget.php | 2 +- test-all.bat | 48 ---------- test-all.sh | 20 ---- test-coverage-all.bat | 32 ------- test-coverage-sqlite.bat | 5 - test-coverage.bat | 5 - test-sqlite.bat | 4 - tests/AuthTest.php | 6 +- tests/FileUploadTest.php | 2 +- tests/ImageUploadTest.php | 2 +- tests/IndexTest.php | 8 +- tests/InstallTest.php | 2 +- tests/MenuTest.php | 4 +- tests/OperationLogTest.php | 4 +- tests/PermissionsTest.php | 6 +- tests/RolesTest.php | 4 +- tests/TestCase.php | 12 +-- tests/UserFormTest.php | 2 +- tests/UserGridTest.php | 2 +- tests/UserSettingTest.php | 2 +- tests/UsersTest.php | 2 +- tests/config/admin.php | 26 ++--- tests/config/filesystems.php | 2 +- tests/controllers/FileController.php | 6 +- tests/controllers/ImageController.php | 6 +- tests/controllers/MultipleImageController.php | 6 +- tests/controllers/UserController.php | 6 +- tests/models/Tree.php | 2 +- 383 files changed, 1280 insertions(+), 1113 deletions(-) create mode 100644 .github/FUNDING.yml create mode 100644 .github/ISSUE_TEMPLATE/bug.yml create mode 100644 .github/ISSUE_TEMPLATE/config.yml create mode 100644 .github/dependabot.yml create mode 100644 .github/workflows/dependabot-auto-merge.yml create mode 100644 .github/workflows/fix-php-code-style-issues.yml create mode 100644 .github/workflows/phpstan.yml create mode 100644 .github/workflows/run-tests.yml create mode 100644 .github/workflows/update-changelog.yml delete mode 100644 test-all.bat delete mode 100644 test-all.sh delete mode 100644 test-coverage-all.bat delete mode 100644 test-coverage-sqlite.bat delete mode 100644 test-coverage.bat delete mode 100644 test-sqlite.bat diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 00000000..1e4744c3 --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1 @@ +github: talemul diff --git a/.github/ISSUE_TEMPLATE/bug.yml b/.github/ISSUE_TEMPLATE/bug.yml new file mode 100644 index 00000000..81363300 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug.yml @@ -0,0 +1,66 @@ +name: Bug Report +description: Report an Issue or Bug with the Package +title: "[Bug]: " +labels: ["bug"] +body: + - type: markdown + attributes: + value: | + We're sorry to hear you have a problem. Can you help us solve it by providing the following details. + - type: textarea + id: what-happened + attributes: + label: What happened? + description: What did you expect to happen? + placeholder: I cannot currently do X thing because when I do, it breaks X thing. + validations: + required: true + - type: textarea + id: how-to-reproduce + attributes: + label: How to reproduce the bug + description: How did this occur, please add any config values used and provide a set of reliable steps if possible. + placeholder: When I do X I see Y. + validations: + required: true + - type: input + id: package-version + attributes: + label: Package Version + description: What version of our Package are you running? Please be as specific as possible + placeholder: 2.0.0 + validations: + required: true + - type: input + id: php-version + attributes: + label: PHP Version + description: What version of PHP are you running? Please be as specific as possible + placeholder: 8.2.0 + validations: + required: true + - type: input + id: laravel-version + attributes: + label: Laravel Version + description: What version of Laravel are you running? Please be as specific as possible + placeholder: 9.0.0 + validations: + required: true + - type: dropdown + id: operating-systems + attributes: + label: Which operating systems does this happen with? + description: You may select more than one. + multiple: true + options: + - macOS + - Windows + - Linux + - type: textarea + id: notes + attributes: + label: Notes + description: Use this field to provide any other notes that you feel might be relevant to the issue. + validations: + required: false diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index ebd366c9..9a75fd73 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -20,7 +20,7 @@ Steps to reproduce the behavior, for example: A clear and concise description of what you expected to happen. **System** - - Open-admin version + - super-admin version - PHP version - Laravel Version - OS: [e.g. Linux / Win / Mac] diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml new file mode 100644 index 00000000..1e710334 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/config.yml @@ -0,0 +1,11 @@ +blank_issues_enabled: false +contact_links: + - name: Ask a question + url: https://github.com/talemul/hukum/discussions/new?category=q-a + about: Ask the community for help + - name: Request a feature + url: https://github.com/talemul/hukum/discussions/new?category=ideas + about: Share ideas for new features + - name: Report a security issue + url: https://github.com/talemul/hukum/security/policy + about: Learn how to notify us for sensitive bugs diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 00000000..39b15807 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,19 @@ +# Please see the documentation for all configuration options: +# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates + +version: 2 +updates: + + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "weekly" + labels: + - "dependencies" + + - package-ecosystem: "composer" + directory: "/" + schedule: + interval: "weekly" + labels: + - "dependencies" diff --git a/.github/workflows/dependabot-auto-merge.yml b/.github/workflows/dependabot-auto-merge.yml new file mode 100644 index 00000000..cc8c94cf --- /dev/null +++ b/.github/workflows/dependabot-auto-merge.yml @@ -0,0 +1,33 @@ +name: dependabot-auto-merge +on: pull_request_target + +permissions: + pull-requests: write + contents: write + +jobs: + dependabot: + runs-on: ubuntu-latest + timeout-minutes: 5 + if: ${{ github.actor == 'dependabot[bot]' }} + steps: + + - name: Dependabot metadata + id: metadata + uses: dependabot/fetch-metadata@v2.4.0 + with: + github-token: "${{ secrets.GITHUB_TOKEN }}" + + - name: Auto-merge Dependabot PRs for semver-minor updates + if: ${{steps.metadata.outputs.update-type == 'version-update:semver-minor'}} + run: gh pr merge --auto --merge "$PR_URL" + env: + PR_URL: ${{github.event.pull_request.html_url}} + GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} + + - name: Auto-merge Dependabot PRs for semver-patch updates + if: ${{steps.metadata.outputs.update-type == 'version-update:semver-patch'}} + run: gh pr merge --auto --merge "$PR_URL" + env: + PR_URL: ${{github.event.pull_request.html_url}} + GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} diff --git a/.github/workflows/fix-php-code-style-issues.yml b/.github/workflows/fix-php-code-style-issues.yml new file mode 100644 index 00000000..1ec8dbf4 --- /dev/null +++ b/.github/workflows/fix-php-code-style-issues.yml @@ -0,0 +1,28 @@ +name: Fix PHP code style issues + +on: + push: + paths: + - '**.php' + +permissions: + contents: write + +jobs: + php-code-styling: + runs-on: ubuntu-latest + timeout-minutes: 5 + + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + ref: ${{ github.head_ref }} + + - name: Fix PHP code style issues + uses: aglipanci/laravel-pint-action@2.5 + + - name: Commit changes + uses: stefanzweifel/git-auto-commit-action@v5 + with: + commit_message: Fix styling diff --git a/.github/workflows/phpstan.yml b/.github/workflows/phpstan.yml new file mode 100644 index 00000000..43a82b4e --- /dev/null +++ b/.github/workflows/phpstan.yml @@ -0,0 +1,28 @@ +name: PHPStan + +on: + push: + paths: + - '**.php' + - 'phpstan.neon.dist' + - '.github/workflows/phpstan.yml' + +jobs: + phpstan: + name: phpstan + runs-on: ubuntu-latest + timeout-minutes: 5 + steps: + - uses: actions/checkout@v4 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: '8.4' + coverage: none + + - name: Install composer dependencies + uses: ramsey/composer-install@v3 + + - name: Run PHPStan + run: ./vendor/bin/phpstan --error-format=github diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml new file mode 100644 index 00000000..adbcbe33 --- /dev/null +++ b/.github/workflows/run-tests.yml @@ -0,0 +1,63 @@ +name: run-tests + +on: + push: + paths: + - '**.php' + - '.github/workflows/run-tests.yml' + - 'phpunit.xml.dist' + - 'composer.json' + - 'composer.lock' + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + test: + runs-on: ${{ matrix.os }} + timeout-minutes: 5 + strategy: + fail-fast: true + matrix: + os: [ubuntu-latest, windows-latest] + php: [8.4, 8.3] + laravel: [12.*, 11.*, 10.*] + stability: [prefer-lowest, prefer-stable] + include: + - laravel: 12.* + testbench: 10.* + - laravel: 11.* + testbench: 9.* + - laravel: 10.* + testbench: 8.* + + + name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }} + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo + coverage: none + + - name: Setup problem matchers + run: | + echo "::add-matcher::${{ runner.tool_cache }}/php.json" + echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json" + + - name: Install dependencies + run: | + composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update + composer update --${{ matrix.stability }} --prefer-dist --no-interaction + + - name: List Installed Dependencies + run: composer show -D + + - name: Execute tests + run: vendor/bin/pest --ci diff --git a/.github/workflows/update-changelog.yml b/.github/workflows/update-changelog.yml new file mode 100644 index 00000000..39de30d6 --- /dev/null +++ b/.github/workflows/update-changelog.yml @@ -0,0 +1,32 @@ +name: "Update Changelog" + +on: + release: + types: [released] + +permissions: + contents: write + +jobs: + update: + runs-on: ubuntu-latest + timeout-minutes: 5 + + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + ref: main + + - name: Update Changelog + uses: stefanzweifel/changelog-updater-action@v1 + with: + latest-version: ${{ github.event.release.name }} + release-notes: ${{ github.event.release.body }} + + - name: Commit updated CHANGELOG + uses: stefanzweifel/git-auto-commit-action@v5 + with: + branch: main + commit_message: Update CHANGELOG + file_pattern: CHANGELOG.md diff --git a/.gitignore b/.gitignore index 4e530b36..4ded68c0 100644 --- a/.gitignore +++ b/.gitignore @@ -8,5 +8,5 @@ composer.lock .php_cs.cache .vscode/ resources/assets/minify-manifest.json -resources/assets/open-admin.min.css -resources/assets/open-admin.min.js +resources/assets/super-admin.min.css +resources/assets/super-admin.min.js diff --git a/.phpunit.result.cache b/.phpunit.result.cache index 5002870c..debb3433 100644 --- a/.phpunit.result.cache +++ b/.phpunit.result.cache @@ -1 +1 @@ -{"version":1,"defects":{"AuthTest::testLoginPage":3,"\/var\/www\/tests\/Feature\/DummyTest.php::it":4,"C:\\Users\\LAPTOP GADGET\\Downloads\\laravel plugin\\laravel_plugin_with_coverage_and_ci_final\\tests\\Feature\\DummyTest.php::it dummy test runs":4},"times":{"AuthTest::testLoginPage":2.052,"\/var\/www\/tests\/Feature\/DummyTest.php::it":24.811,"C:\\Users\\LAPTOP GADGET\\Downloads\\laravel plugin\\laravel_plugin_with_coverage_and_ci_final\\tests\\Unit\\DummyUnitTest.php::it dummy unit test runs":0.01,"C:\\Users\\LAPTOP GADGET\\Downloads\\laravel plugin\\laravel_plugin_with_coverage_and_ci_final\\tests\\Feature\\DummyTest.php::it dummy test runs":16.784}} \ No newline at end of file +{"version":1,"defects":{"AuthTest::testLoginPage":3,"\/var\/www\/tests\/Feature\/DummyTest.php::it":4,"C:\\Users\\LAPTOP GADGET\\Downloads\\laravel plugin\\laravel_plugin_with_coverage_and_ci_final\\tests\\Feature\\DummyTest.php::it dummy test runs":4,"MenuTest::testMenuIndex":4,"LaravelTest::testLaravel":4,"IndexTest::testIndex":4,"Warning":6,"UserFormTest::testCreatePage":4},"times":{"AuthTest::testLoginPage":2.052,"\/var\/www\/tests\/Feature\/DummyTest.php::it":24.811,"C:\\Users\\LAPTOP GADGET\\Downloads\\laravel plugin\\laravel_plugin_with_coverage_and_ci_final\\tests\\Unit\\DummyUnitTest.php::it dummy unit test runs":0.01,"C:\\Users\\LAPTOP GADGET\\Downloads\\laravel plugin\\laravel_plugin_with_coverage_and_ci_final\\tests\\Feature\\DummyTest.php::it dummy test runs":16.784,"MenuTest::testMenuIndex":24.425,"LaravelTest::testLaravel":1.249,"IndexTest::testIndex":1.209,"Warning":0.004,"UserFormTest::testCreatePage":1.497}} \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index af3d8af0..627b2f36 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,2 +1,2 @@ # Changelog -See https://open-admin.org/docs/ +See https://super-admin.org/docs/ diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index fd6bc49b..fad4aa82 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -2,7 +2,7 @@ ## Introduction -First, thank you for considering contributing to open-admin! It's people like you that make the open source community such a great community! 😊 +First, thank you for considering contributing to super-admin! It's people like you that make the open source community such a great community! 😊 We welcome any type of contribution, not only code. You can help with - **QA**: file bug reports, the more details you can give the better (e.g. screenshots with the console open) @@ -33,7 +33,7 @@ We also welcome financial contributions in full transparency please drop us a li ## Questions If you have any questions, create an [issue](issue) (protip: do a quick search first to see if someone else didn't ask the same question before!). -You can also reach us at hello@open-admin.opencollective.com. +You can also reach us at hello@super-admin.opencollective.com. \ No newline at end of file diff --git a/README.md b/README.md index 5435509e..48ba53c7 100644 --- a/README.md +++ b/README.md @@ -1,34 +1,34 @@

- -open-admin + +super-admin

-

open-admin is administrative interface builder for laravel which can help you build CRUD backends just with few lines of code.

+

super-admin is administrative interface builder for laravel which can help you build CRUD backends just with few lines of code.

-Homepage | -Documentation | -Download | -Extensions +Homepage | +Documentation | +Download | +Extensions

StyleCI - - Packagist + + Packagist - - Total Downloads + + Total Downloads - + Awesome Laravel ## Contribute? @@ -125,7 +125,7 @@ More coming soon Other ------------ -`open-admin` based on the following plugins or services: +`super-admin` based on the following plugins or services: + [Laravel](https://laravel.com/) + [Axios](https://github.com/axios/axios) @@ -145,4 +145,4 @@ Other License ------------ -`open-admin` is licensed under [The MIT License (MIT)](LICENSE). +`super-admin` is licensed under [The MIT License (MIT)](LICENSE). diff --git a/composer.json b/composer.json index 3d9db226..546251c8 100644 --- a/composer.json +++ b/composer.json @@ -1,14 +1,14 @@ { - "name": "open-admin-org/open-admin", - "description": "open-admin. Open-source Laravel Admin panel. No pro or paid package, free & open. Based on laravel-admin, with special thanks to z-song", + "name": "talemul/super-admin", + "description": "super-admin. Open-source Laravel Admin panel. No pro or paid package, free & open. Based on laravel-admin, with special thanks to z-song", "type": "library", - "keywords": ["laravel", "admin", "grid", "form", "open-admin","open","free"], - "homepage": "https://github.com/open-admin-org/open-admin", + "keywords": ["laravel", "admin", "grid", "form", "super-admin","super","free"], + "homepage": "https://github.com/talemul/super-admin", "license": "MIT", "authors": [ { - "name": "Sjors Broersen | Open-Admin.org", - "email": "info@open-admin.org" + "name": "Super Admin", + "email": "talemulislam@gmail.com" } ], "require": { @@ -26,7 +26,7 @@ }, "autoload": { "psr-4": { - "OpenAdmin\\Admin\\": "src/" + "SuperAdmin\\Admin\\": "src/" }, "files": [ "src/helpers.php" @@ -42,7 +42,7 @@ ] }, "scripts": { - "sass": "sass --watch resources/assets/open-admin/scss/styles.scss:resources/assets/open-admin/css/styles.css resources/assets/open-admin/scss/pages:resources/assets/open-admin/css/pages --style compressed", + "sass": "sass --watch resources/assets/super-admin/scss/styles.scss:resources/assets/super-admin/css/styles.css resources/assets/super-admin/scss/pages:resources/assets/super-admin/css/pages --style compressed", "test": "./vendor/bin/phpunit" }, "suggest": { @@ -52,10 +52,10 @@ "extra": { "laravel": { "providers": [ - "OpenAdmin\\Admin\\AdminServiceProvider" + "SuperAdmin\\Admin\\AdminServiceProvider" ], "aliases": { - "Admin": "OpenAdmin\\Admin\\Facades\\Admin" + "Admin": "SuperAdmin\\Admin\\Facades\\Admin" } } }, diff --git a/composer.json_bk b/composer.json_bk index d2560441..8d84877a 100644 --- a/composer.json_bk +++ b/composer.json_bk @@ -1,14 +1,14 @@ { - "name": "open-admin-org/open-admin", - "description": "open-admin. Open-source Laravel Admin panel. No pro or paid package, free & open. Based on laravel-admin, with special thanks to z-song", + "name": "super-admin-org/super-admin", + "description": "super-admin. Open-source Laravel Admin panel. No pro or paid package, free & open. Based on laravel-admin, with special thanks to z-song", "type": "library", - "keywords": ["laravel", "admin", "grid", "form", "open-admin","open","free"], - "homepage": "https://github.com/open-admin-org/open-admin", + "keywords": ["laravel", "admin", "grid", "form", "super-admin","open","free"], + "homepage": "https://github.com/super-admin-org/super-admin", "license": "MIT", "authors": [ { "name": "Sjors Broersen | Open-Admin.org", - "email": "info@open-admin.org" + "email": "info@super-admin.org" } ], "require": { @@ -30,7 +30,7 @@ }, "autoload": { "psr-4": { - "OpenAdmin\\Admin\\": "src/" + "SuperAdmin\\Admin\\": "src/" }, "files": [ "src/helpers.php" @@ -46,7 +46,7 @@ ] }, "scripts": { - "sass": "sass --watch resources/assets/open-admin/scss/styles.scss:resources/assets/open-admin/css/styles.css resources/assets/open-admin/scss/pages:resources/assets/open-admin/css/pages --style compressed", + "sass": "sass --watch resources/assets/super-admin/scss/styles.scss:resources/assets/super-admin/css/styles.css resources/assets/super-admin/scss/pages:resources/assets/super-admin/css/pages --style compressed", "test": "./vendor/bin/phpunit" }, "suggest": { @@ -56,10 +56,10 @@ "extra": { "laravel": { "providers": [ - "OpenAdmin\\Admin\\AdminServiceProvider" + "SuperAdmin\\Admin\\AdminServiceProvider" ], "aliases": { - "Admin": "OpenAdmin\\Admin\\Facades\\Admin" + "Admin": "SuperAdmin\\Admin\\Facades\\Admin" } } }, diff --git a/config/admin.php b/config/admin.php index 19004f0b..4634f906 100644 --- a/config/admin.php +++ b/config/admin.php @@ -4,18 +4,18 @@ /* |-------------------------------------------------------------------------- - | Open-admin name + | super-admin name |-------------------------------------------------------------------------- | - | This value is the name of Open-admin, This setting is displayed on the + | This value is the name of super-admin, This setting is displayed on the | login page. | */ - 'name' => 'Open Admin', + 'name' => 'Super Admin', /* |-------------------------------------------------------------------------- - | Open-admin logo + | super-admin logo |-------------------------------------------------------------------------- | | The logo of all admin pages. You can also set it as an image by using a @@ -26,7 +26,7 @@ /* |-------------------------------------------------------------------------- - | Open-admin mini logo + | super-admin mini logo |-------------------------------------------------------------------------- | | The logo of all admin pages when the sidebar menu is collapsed. You can @@ -38,17 +38,17 @@ /* |-------------------------------------------------------------------------- - | Open-admin bootstrap setting + | super-admin bootstrap setting |-------------------------------------------------------------------------- | - | This value is the path of open-admin bootstrap file. + | This value is the path of super-admin bootstrap file. | */ 'bootstrap' => app_path('Admin/bootstrap.php'), /* |-------------------------------------------------------------------------- - | Open-admin route settings + | super-admin route settings |-------------------------------------------------------------------------- | | The routing configuration of the admin page, including the path prefix, @@ -67,7 +67,7 @@ /* |-------------------------------------------------------------------------- - | Open-admin install directory + | super-admin install directory |-------------------------------------------------------------------------- | | The installation directory of the controller and routing configuration @@ -79,7 +79,7 @@ /* |-------------------------------------------------------------------------- - | Open-admin html title + | super-admin html title |-------------------------------------------------------------------------- | | Html title for all pages. @@ -99,7 +99,7 @@ /* |-------------------------------------------------------------------------- - | Open-admin auth setting + | super-admin auth setting |-------------------------------------------------------------------------- | | Authentication settings for all admin pages. Include an authentication @@ -124,7 +124,7 @@ 'providers' => [ 'admin' => [ 'driver' => 'eloquent', - 'model' => OpenAdmin\Admin\Auth\Database\Administrator::class, + 'model' => SuperAdmin\Admin\Auth\Database\Administrator::class, ], ], @@ -148,7 +148,7 @@ /* |-------------------------------------------------------------------------- - | Open-admin upload setting + | super-admin upload setting |-------------------------------------------------------------------------- | | File system configuration for form upload files and images, including @@ -169,10 +169,10 @@ /* |-------------------------------------------------------------------------- - | Open-admin database settings + | super-admin database settings |-------------------------------------------------------------------------- | - | Here are database settings for open-admin builtin model & tables. + | Here are database settings for super-admin builtin model & tables. | */ 'database' => [ @@ -182,19 +182,19 @@ // User tables and model. 'users_table' => 'admin_users', - 'users_model' => OpenAdmin\Admin\Auth\Database\Administrator::class, + 'users_model' => SuperAdmin\Admin\Auth\Database\Administrator::class, // Role table and model. 'roles_table' => 'admin_roles', - 'roles_model' => OpenAdmin\Admin\Auth\Database\Role::class, + 'roles_model' => SuperAdmin\Admin\Auth\Database\Role::class, // Permission table and model. 'permissions_table' => 'admin_permissions', - 'permissions_model' => OpenAdmin\Admin\Auth\Database\Permission::class, + 'permissions_model' => SuperAdmin\Admin\Auth\Database\Permission::class, // Menu table and model. 'menu_table' => 'admin_menu', - 'menu_model' => OpenAdmin\Admin\Auth\Database\Menu::class, + 'menu_model' => SuperAdmin\Admin\Auth\Database\Menu::class, // Pivot table for table above. 'operation_log_table' => 'admin_operation_log', @@ -209,7 +209,7 @@ | User operation log setting |-------------------------------------------------------------------------- | - | By setting this option to open or close operation log in open-admin. + | By setting this option to open or close operation log in super-admin. | */ 'operation_log' => [ @@ -263,7 +263,7 @@ | Set a default avatar for newly created users. | */ - 'default_avatar' => '/vendor/open-admin/open-admin/gfx/user.svg', + 'default_avatar' => '/vendor/super-admin/super-admin/gfx/user.svg', /* |-------------------------------------------------------------------------- @@ -314,7 +314,7 @@ | Show version at footer |-------------------------------------------------------------------------- | - | Whether to display the version number of open-admin at the footer of + | Whether to display the version number of super-admin at the footer of | each page | */ @@ -388,7 +388,7 @@ | The global Grid action display class. (Actions::class, DropdownActions:class or ContextMenuActions::class) |-------------------------------------------------------------------------- */ - 'grid_action_class' => \OpenAdmin\Admin\Grid\Displayers\Actions\Actions::class, + 'grid_action_class' => \SuperAdmin\Admin\Grid\Displayers\Actions\Actions::class, /* |-------------------------------------------------------------------------- @@ -406,7 +406,7 @@ |-------------------------------------------------------------------------- | | You can find all available extensions here - | https://github.com/open-admin-extensions. + | https://github.com/super-admin-extensions. | */ 'extensions' => [ diff --git a/resources/assets/open-admin/scss/styles.scss b/resources/assets/open-admin/scss/styles.scss index b2ed8670..b21998fe 100644 --- a/resources/assets/open-admin/scss/styles.scss +++ b/resources/assets/open-admin/scss/styles.scss @@ -1,4 +1,4 @@ -/* styles can be rendered from: vendor/open-admin-org/open-admin by using: composer sass */ +/* styles can be rendered from: vendor/super-admin-org/super-admin by using: composer sass */ /* this will create a watcher looking for changes inside the files below */ /* default contain bootstrap overwrites */ diff --git a/resources/views/dashboard/extensions.blade.php b/resources/views/dashboard/extensions.blade.php index 2a79d731..fee1c0c9 100644 --- a/resources/views/dashboard/extensions.blade.php +++ b/resources/views/dashboard/extensions.blade.php @@ -43,7 +43,7 @@

\ No newline at end of file diff --git a/resources/views/dashboard/title.blade.php b/resources/views/dashboard/title.blade.php index 5a7988f0..824777d6 100644 --- a/resources/views/dashboard/title.blade.php +++ b/resources/views/dashboard/title.blade.php @@ -2,7 +2,7 @@ Resources \ No newline at end of file diff --git a/resources/views/form/hasmanytab.blade.php b/resources/views/form/hasmanytab.blade.php index b4426068..e3d8b84c 100644 --- a/resources/views/form/hasmanytab.blade.php +++ b/resources/views/form/hasmanytab.blade.php @@ -40,14 +40,14 @@