Initial commit,修正

This commit is contained in:
2025-07-13 19:37:38 +08:00
parent 38ce288e27
commit 65bbd06981
12384 changed files with 3985464 additions and 8 deletions
+4
View File
@@ -0,0 +1,4 @@
# these files are auto generated by codeception build
/unit/UnitTester.php
/functional/FunctionalTester.php
/acceptance/AcceptanceTester.php
+16
View File
@@ -0,0 +1,16 @@
<?php
defined('YII_DEBUG') or define('YII_DEBUG', true);
defined('YII_ENV') or define('YII_ENV', 'test');
defined('YII_TEST_ENTRY_URL') or define('YII_TEST_ENTRY_URL', parse_url(\Codeception\Configuration::config()['config']['test_entry_url'], PHP_URL_PATH));
defined('YII_TEST_ENTRY_FILE') or define('YII_TEST_ENTRY_FILE', __DIR__ . '/../web/index-test.php');
require_once(__DIR__ . '/../../vendor/autoload.php');
require_once(__DIR__ . '/../../vendor/yiisoft/yii2/Yii.php');
$_SERVER['SCRIPT_FILENAME'] = YII_TEST_ENTRY_FILE;
$_SERVER['SCRIPT_NAME'] = YII_TEST_ENTRY_URL;
$_SERVER['SERVER_NAME'] = parse_url(\Codeception\Configuration::config()['config']['test_entry_url'], PHP_URL_HOST);
$_SERVER['SERVER_PORT'] = parse_url(\Codeception\Configuration::config()['config']['test_entry_url'], PHP_URL_PORT) ?: '80';
Yii::setAlias('@tests', dirname(__DIR__));
@@ -0,0 +1,2 @@
*
!.gitignore
+32
View File
@@ -0,0 +1,32 @@
<?php
namespace tests\codeception\_pages;
use yii\codeception\BasePage;
/**
* Represents create role or permission
* @property \AcceptanceTester|\FunctionalTester $actor
*/
class CreateItemPage extends BasePage
{
public $route = 'admin/role/create';
/**
* @param array $roleData
*/
public function submit(array $roleData)
{
$inputTypes = [
'name' => 'input',
'description' => 'textarea',
'ruleName' => 'select',
'data' => 'textarea',
];
foreach ($roleData as $field => $value) {
$inputType = isset($inputTypes[$field]) ? $inputTypes[$field] : 'input';
$this->actor->fillField($inputType . '[name="AuthItem[' . $field . ']"]', $value);
}
$this->actor->click('submit-button');
}
}
+23
View File
@@ -0,0 +1,23 @@
<?php
namespace tests\codeception\_pages;
use yii\codeception\BasePage;
/**
* Represents about page
* @property \AcceptanceTester|\FunctionalTester $actor
*/
class RoutePage extends BasePage
{
public $route = 'admin/route/index';
/**
* @param array $route
*/
public function addRoute($route)
{
$this->actor->fillField('#inp-route', $route);
$this->actor->click('add-route');
}
}
+69
View File
@@ -0,0 +1,69 @@
<?php
namespace tests\codeception\_support;
use Codeception\Module;
use yii\test\FixtureTrait;
use tests\codeception\fixtures\AdminFixture;
/**
* This helper is used to populate the database with needed fixtures before any tests are run.
* In this example, the database is populated with the demo login user, which is used in acceptance
* and functional tests. All fixtures will be loaded before the suite is started and unloaded after it
* completes.
*/
class FixtureHelper extends Module
{
/**
* Redeclare visibility because codeception includes all public methods that do not start with "_"
* and are not excluded by module settings, in actor class.
*/
use FixtureTrait {
loadFixtures as public;
fixtures as public;
globalFixtures as public;
createFixtures as public;
unloadFixtures as protected;
getFixtures as protected;
getFixture as protected;
}
/**
* Method called before any suite tests run. Loads User fixture login user
* to use in acceptance and functional tests.
* @param array $settings
*/
public function _beforeSuite($settings = [])
{
$this->loadFixtures();
}
/**
* Method is called after all suite tests run
*/
public function _afterSuite()
{
$this->unloadFixtures();
}
/**
* @inheritdoc
*/
public function globalFixtures()
{
return [
AdminFixture::className(),
];
}
/**
* @inheritdoc
*/
public function fixtures()
{
return [
];
}
}
+28
View File
@@ -0,0 +1,28 @@
# Codeception Test Suite Configuration
# suite for acceptance tests.
# perform tests in browser using the Selenium-like tools.
# powered by Mink (http://mink.behat.org).
# (tip: that's what your customer will see).
# (tip: test your ajax and javascript by one of Mink drivers).
# RUN `build` COMMAND AFTER ADDING/REMOVING MODULES.
class_name: AcceptanceTester
modules:
enabled:
- PhpBrowser
- tests\codeception\_support\FixtureHelper
# you can use WebDriver instead of PhpBrowser to test javascript and ajax.
# This will require you to install selenium. See http://codeception.com/docs/04-AcceptanceTests#Selenium
# "restart" option is used by the WebDriver to start each time per test-file new session and cookies,
# it is useful if you want to login in your app in each test.
# - WebDriver
config:
PhpBrowser:
# PLEASE ADJUST IT TO THE ACTUAL ENTRY POINT WITHOUT PATH INFO
url: http://localhost:8080
# WebDriver:
# url: http://localhost:8080
# browser: firefox
# restart: true
@@ -0,0 +1,31 @@
<?php
use tests\codeception\_pages\CreateItemPage;
/* @var $scenario Codeception\Scenario */
$I = new AcceptanceTester($scenario);
$I->wantTo('ensure that create role item work');
$createItemPage = CreateItemPage::openBy($I);
$I->see('Create Role', 'h1');
$I->amGoingTo('submit role form with no data');
$createItemPage->submit([]);
if (method_exists($I, 'wait')) {
$I->wait(3); // only for selenium
}
$I->expectTo('see validations errors');
$I->see('Create Role', 'h1');
$I->see('Name cannot be blank');
$I->amGoingTo('submit role form with correct data');
$createItemPage->submit([
'name' => 'roleTesterAcp',
'description' => 'Role created for test',
]);
if (method_exists($I, 'wait')) {
$I->wait(3); // only for selenium
}
$I->dontSeeElement('#item-form');
+10
View File
@@ -0,0 +1,10 @@
<?php
use tests\codeception\_pages\RoutePage;
/* @var $scenario Codeception\Scenario */
$I = new AcceptanceTester($scenario);
$I->wantTo('ensure that create route work');
RoutePage::openBy($I);
$I->see('Routes', 'h1');
+2
View File
@@ -0,0 +1,2 @@
<?php
new yii\web\Application(require(dirname(__DIR__) . '/config/acceptance.php'));
+10
View File
@@ -0,0 +1,10 @@
<?php
defined('YII_DEBUG') or define('YII_DEBUG', true);
defined('YII_ENV') or define('YII_ENV', 'test');
defined('MDM_ADMIN_BASE_PATH') or define('MDM_ADMIN_BASE_PATH', dirname(dirname(dirname(__DIR__))));
require(MDM_ADMIN_BASE_PATH . '/vendor/autoload.php');
require(MDM_ADMIN_BASE_PATH . '/vendor/yiisoft/yii2/Yii.php');
Yii::setAlias('@tests', dirname(dirname(__DIR__)));
+20
View File
@@ -0,0 +1,20 @@
#!/usr/bin/env php
<?php
/**
* Yii console bootstrap file.
*
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
require_once __DIR__ . '/_bootstrap.php';
$config = yii\helpers\ArrayHelper::merge(
require(__DIR__ . '/../config/config.php'),
require(__DIR__ . '/../config/console.php')
);
$application = new yii\console\Application($config);
$exitCode = $application->run();
exit($exitCode);
+20
View File
@@ -0,0 +1,20 @@
@echo off
rem -------------------------------------------------------------
rem Yii command line bootstrap script for Windows.
rem
rem @author Qiang Xue <qiang.xue@gmail.com>
rem @link http://www.yiiframework.com/
rem @copyright Copyright (c) 2008 Yii Software LLC
rem @license http://www.yiiframework.com/license/
rem -------------------------------------------------------------
@setlocal
set YII_PATH=%~dp0
if "%PHP_COMMAND%" == "" set PHP_COMMAND=php.exe
"%PHP_COMMAND%" "%YII_PATH%yii" %*
@endlocal
@@ -0,0 +1,2 @@
# these files are auto generated by codeception build
/db-local.php
+11
View File
@@ -0,0 +1,11 @@
<?php
/**
* Application configuration for acceptance tests
*/
return yii\helpers\ArrayHelper::merge(
require(__DIR__ . '/config.php'),
require(__DIR__ . '/web.php'),
[
]
);
+48
View File
@@ -0,0 +1,48 @@
<?php
/**
* Application configuration shared by all test types
*/
return [
'id' => 'mdm-admin-test',
'basePath' => dirname(dirname(__DIR__)), // @tests
'vendorPath' => dirname(dirname(dirname(__DIR__))) . '/vendor',
'language' => 'en-US',
'aliases' => [
'@mdm/admin' => dirname(dirname(dirname(__DIR__))),
],
'modules' => [
'admin' => [
'class' => 'mdm\admin\Module',
]
],
'controllerMap' => [
'fixture' => [
'class' => 'yii\console\controllers\FixtureController',
'namespace' => 'tests\codeception\fixtures',
],
],
'components' => [
'db' => require(__DIR__ . '/db.php'),
'mailer' => [
'useFileTransport' => true,
],
'urlManager' => [
'showScriptName' => true,
],
'authManager' => [
'class' => 'yii\rbac\DbManager'
],
'cache' => [
'class' => 'yii\caching\DummyCache',
],
'i18n' => [
'translations' => [
'rbac-admin' => [
'class' => 'yii\i18n\PhpMessageSource',
'sourceLanguage' => 'en',
'basePath' => '@mdm/admin/messages'
]
]
]
],
];
+5
View File
@@ -0,0 +1,5 @@
<?php
return[
'components' => [
]
];
+36
View File
@@ -0,0 +1,36 @@
<?php
/**
* This is the configuration file for the yii2-admin unit tests.
* You can override configuration values by creating a `db-local.php` file
* and manipulate the `$databases` variable.
* For example to change MySQL username and password your `db-local.php` should
* contain the following:
*
<?php
$driver = 'pgsql';
$databases[$driver]['username'] = 'myname';
$databases[$driver]['password'] = 'changeme';
*/
$databases = [
'mysql' => [
'dsn' => 'mysql:host=127.0.0.1;dbname=mdm_admin_test',
'username' => 'travis',
'password' => '',
],
'sqlite' => [
//'dsn' => 'sqlite::memory:',
'dsn' => 'sqlite:@runtime/mdm_admin_test.sqlite',
],
'pgsql' => [
'dsn' => 'pgsql:host=localhost;dbname=mdm_admin_test;port=5432;',
'username' => 'postgres',
'password' => 'postgres',
],
];
$driver = 'mysql';
if (is_file(__DIR__ . '/db-local.php')) {
include __DIR__ . '/db-local.php';
}
return array_merge(['class' => 'yii\db\Connection'], $databases[$driver]);
+25
View File
@@ -0,0 +1,25 @@
<?php
$_SERVER['SCRIPT_FILENAME'] = YII_TEST_ENTRY_FILE;
$_SERVER['SCRIPT_NAME'] = YII_TEST_ENTRY_URL;
/**
* Application configuration for functional tests
*/
return yii\helpers\ArrayHelper::merge(
require(__DIR__ . '/config.php'),
require(__DIR__ . '/web.php'),
[
'components' => [
'request' => [
// it's not recommended to run functional tests with CSRF validation enabled
'enableCsrfValidation' => false,
// but if you absolutely need it set cookie domain to localhost
/*
'csrfCookie' => [
'domain' => 'localhost',
],
*/
],
],
]
);
+11
View File
@@ -0,0 +1,11 @@
<?php
/**
* Application configuration for unit tests
*/
return yii\helpers\ArrayHelper::merge(
require(__DIR__ . '/config.php'),
require(__DIR__ . '/web.php'),
[
]
);
+8
View File
@@ -0,0 +1,8 @@
<?php
return[
'components' => [
'request' => [
'cookieValidationKey' => 'testme',
],
]
];
View File
+24
View File
@@ -0,0 +1,24 @@
<?php
namespace tests\codeception\fixtures;
use Yii;
use yii\test\DbFixture;
/**
* Description of AdminFixture
*
* @author Misbahul D Munir <misbahuldmunir@gmail.com>
* @since 2.5
*/
class AdminFixture extends DbFixture
{
public function load()
{
ob_start();
ob_implicit_flush(false);
include __DIR__ . '/data/admin.php';
ob_get_clean();
}
}
+58
View File
@@ -0,0 +1,58 @@
<?php
use mdm\admin\components\Configs;
/* @var $this tests\codeception\fixtures\AdminFixture */
$migrations = [
'm140506_102106_rbac_init' => '@yii/rbac/migrations',
'm140602_111327_create_menu_table' => '@mdm/admin/migrations',
'm160312_050000_create_user' => '@mdm/admin/migrations',
];
$command = $this->db->createCommand();
$schema = $this->db->schema;
// rbac
$authManager = Yii::$app->getAuthManager();
if ($this->db->driverName === 'mssql' || $this->db->driverName === 'sqlsrv' || $this->db->driverName === 'dblib') {
$sql = <<<SQL
IF EXISTS (
SELECT *
FROM sys.objects
WHERE [type] = 'TR' AND [name] = 'blablabla'
)
DROP dbo.trigger_auth_item_child;
GO
SQL;
$command->setSql($sql)->execute();
}
if ($schema->getTableSchema($authManager->assignmentTable)) {
$command->dropTable($authManager->assignmentTable)->execute();
}
if ($schema->getTableSchema($authManager->itemChildTable)) {
$command->dropTable($authManager->itemChildTable)->execute();
}
if ($schema->getTableSchema($authManager->itemTable)) {
$command->dropTable($authManager->itemTable)->execute();
}
if ($schema->getTableSchema($authManager->ruleTable)) {
$command->dropTable($authManager->ruleTable)->execute();
}
// mdm/admin
if ($schema->getTableSchema(Configs::menuTable())) {
$command->dropTable(Configs::menuTable())->execute();
}
if ($schema->getTableSchema(Configs::userTable())) {
$command->dropTable(Configs::userTable())->execute();
}
foreach ($migrations as $migration => $path) {
$file = Yii::getAlias($path . '/' . $migration . '.php');
include_once $file;
$migration = new $migration();
$migration->up();
}
+17
View File
@@ -0,0 +1,17 @@
# Codeception Test Suite Configuration
# suite for functional (integration) tests.
# emulate web requests and make application process them.
# (tip: better to use with frameworks).
# RUN `build` COMMAND AFTER ADDING/REMOVING MODULES.
#basic/web/index.php
class_name: FunctionalTester
modules:
enabled:
- Filesystem
- Yii2
- tests\codeception\_support\FixtureHelper
config:
Yii2:
configFile: 'codeception/config/functional.php'
@@ -0,0 +1,31 @@
<?php
use tests\codeception\_pages\CreateItemPage;
/* @var $scenario Codeception\Scenario */
$I = new FunctionalTester($scenario);
$I->wantTo('ensure that create item work');
$createItemPage = CreateItemPage::openBy($I);
$I->see('Create Role', 'h1');
$I->amGoingTo('submit contact form with no data');
$createItemPage->submit([]);
if (method_exists($I, 'wait')) {
$I->wait(3); // only for selenium
}
$I->expectTo('see validations errors');
$I->see('Create Role', 'h1');
$I->see('Name cannot be blank');
$I->amGoingTo('submit contact form with correct data');
$createItemPage->submit([
'name' => 'roleTester',
'description' => 'Role created for test',
]);
if (method_exists($I, 'wait')) {
$I->wait(3); // only for selenium
}
$I->dontSeeElement('#item-form');
+10
View File
@@ -0,0 +1,10 @@
<?php
use tests\codeception\_pages\RoutePage;
/* @var $scenario Codeception\Scenario */
$I = new FunctionalTester($scenario);
$I->wantTo('ensure that create route work');
RoutePage::openBy($I);
$I->see('Routes', 'h1');
+2
View File
@@ -0,0 +1,2 @@
<?php
new yii\web\Application(require(dirname(__DIR__) . '/config/functional.php'));
@@ -0,0 +1,2 @@
*
!.gitignore
+6
View File
@@ -0,0 +1,6 @@
# Codeception Test Suite Configuration
# suite for unit (internal) tests.
# RUN `build` COMMAND AFTER ADDING/REMOVING MODULES.
class_name: UnitTester
+29
View File
@@ -0,0 +1,29 @@
<?php
namespace tests\codeception\unit;
use tests\codeception\fixtures\AdminFixture;
/**
* Description of TestCase
*
* @author Misbahul D Munir <misbahuldmunir@gmail.com>
* @since 1.0
*/
class TestCase extends \yii\codeception\TestCase
{
public $appConfig = '@tests/codeception/config/unit.php';
protected function setUp()
{
parent::setUp();
$this->loadFixtures();
}
public function fixtures()
{
return[
AdminFixture::className(),
];
}
}
+3
View File
@@ -0,0 +1,3 @@
<?php
// add unit testing specific bootstrap code here
@@ -0,0 +1,17 @@
<?php
namespace tests\codeception\unit\components;
/**
* Description of HelperTest
*
* @author Misbahul D Munir <misbahuldmunir@gmail.com>
* @since 1.0
*/
class HelperTest extends \tests\codeception\unit\TestCase
{
public function testFilter()
{
$this->assertTrue(true);
}
}
+42
View File
@@ -0,0 +1,42 @@
<?php
namespace tests\codeception\unit\models;
use Yii;
use tests\codeception\unit\TestCase;
use Codeception\Specify;
use mdm\admin\models\AuthItem;
class ItemTest extends TestCase
{
use Specify;
public function testAddNew()
{
$model = new AuthItem();
$model->attributes = [
'type' => 1,
];
// required
$this->assertFalse($model->validate());
$model = new AuthItem();
$model->attributes = [
'name' => 'Tester',
'type' => 1,
];
$this->assertTrue($model->validate());
$model->save();
$model = new AuthItem();
$model->attributes = [
'name' => 'Tester',
'type' => 1,
];
// not unique
$this->assertFalse($model->validate());
}
}
+19
View File
@@ -0,0 +1,19 @@
<?php
namespace tests\codeception\unit\models;
use tests\codeception\unit\TestCase;
/**
* Description of RouteTest
*
* @author Misbahul D Munir <misbahuldmunir@gmail.com>
* @since 2.5
*/
class RouteTest extends TestCase
{
public function testGetRouteList()
{
$this->assertTrue(true);
}
}