From 960876a1bff6d1024109cb18789c2e87b5562175 Mon Sep 17 00:00:00 2001
From: Error202
Date: Sun, 11 Jun 2023 09:28:12 +0300
Subject: [PATCH] init
---
.bowerrc | 3 +
.gitignore | 39 ++
LICENSE.md | 29 ++
Makefile | 14 +
README.md | 233 ++++++++++
assets/AppAsset.php | 31 ++
codeception.yml | 27 ++
commands/HelloController.php | 34 ++
composer.json | 75 ++++
config/__autocomplete.php | 33 ++
config/console.php | 56 +++
config/db.php | 14 +
config/params.php | 7 +
config/test.php | 46 ++
config/test_db.php | 6 +
config/web.php | 72 +++
controllers/SiteController.php | 128 ++++++
controllers/api/TestController.php | 15 +
docker-compose.yml | 29 ++
mail/layouts/html.php | 22 +
mail/layouts/text.php | 13 +
models/ContactForm.php | 65 +++
models/LoginForm.php | 81 ++++
models/User.php | 104 +++++
requirements.php | 162 +++++++
runtime/.gitignore | 2 +
tests/_bootstrap.php | 6 +
tests/_data/.gitkeep | 1 +
tests/_output/.gitignore | 2 +
tests/_support/AcceptanceTester.php | 26 ++
tests/_support/FunctionalTester.php | 23 +
tests/_support/UnitTester.php | 26 ++
tests/acceptance.suite.yml.example | 10 +
tests/acceptance/AboutCest.php | 12 +
tests/acceptance/ContactCest.php | 34 ++
tests/acceptance/HomeCest.php | 18 +
tests/acceptance/LoginCest.php | 21 +
tests/acceptance/_bootstrap.php | 1 +
tests/bin/yii | 29 ++
tests/bin/yii.bat | 20 +
tests/functional.suite.yml | 14 +
tests/functional/ContactFormCest.php | 57 +++
tests/functional/LoginFormCest.php | 59 +++
tests/functional/_bootstrap.php | 1 +
tests/unit.suite.yml | 11 +
tests/unit/_bootstrap.php | 3 +
tests/unit/models/ContactFormTest.php | 41 ++
tests/unit/models/LoginFormTest.php | 51 +++
tests/unit/models/UserTest.php | 44 ++
tests/unit/widgets/AlertTest.php | 261 +++++++++++
views/layouts/main.php | 6 +
views/site/about.php | 18 +
views/site/contact.php | 68 +++
views/site/error.php | 27 ++
views/site/index.php | 53 +++
views/site/login.php | 55 +++
vue3/.gitignore | 24 +
vue3/.vscode/extensions.json | 3 +
vue3/README.md | 7 +
vue3/index.html | 13 +
vue3/package-lock.json | 798 ++++++++++++++++++++++++++++++++++
vue3/package.json | 19 +
vue3/public/vite.svg | 1 +
vue3/src/App.vue | 41 ++
vue3/src/assets/vue.svg | 1 +
vue3/src/main.js | 7 +
vue3/src/services/http.client.js | 9 +
vue3/src/services/test.service.js | 9 +
vue3/src/style.css | 89 ++++
vue3/vite.config.js | 20 +
web/.htaccess | 4 +
web/assets/index-c05be89e.css | 1 +
web/assets/index-c9f5c948.css | 1 +
web/assets/index-d563b5ec.js | 3 +
web/assets/index-e54ab67f.js | 3 +
web/assets/vue-5532db34.svg | 1 +
web/favicon.ico | Bin 0 -> 318 bytes
web/index-test.php | 16 +
web/index.html | 15 +
web/index.php | 12 +
web/robots.txt | 2 +
web/vite.svg | 1 +
widgets/Alert.php | 73 ++++
yii | 21 +
yii.bat | 20 +
85 files changed, 3552 insertions(+)
create mode 100644 .bowerrc
create mode 100644 .gitignore
create mode 100644 LICENSE.md
create mode 100644 Makefile
create mode 100644 README.md
create mode 100644 assets/AppAsset.php
create mode 100644 codeception.yml
create mode 100644 commands/HelloController.php
create mode 100644 composer.json
create mode 100644 config/__autocomplete.php
create mode 100644 config/console.php
create mode 100644 config/db.php
create mode 100644 config/params.php
create mode 100644 config/test.php
create mode 100644 config/test_db.php
create mode 100644 config/web.php
create mode 100644 controllers/SiteController.php
create mode 100644 controllers/api/TestController.php
create mode 100644 docker-compose.yml
create mode 100644 mail/layouts/html.php
create mode 100644 mail/layouts/text.php
create mode 100644 models/ContactForm.php
create mode 100644 models/LoginForm.php
create mode 100644 models/User.php
create mode 100644 requirements.php
create mode 100644 runtime/.gitignore
create mode 100644 tests/_bootstrap.php
create mode 100644 tests/_data/.gitkeep
create mode 100644 tests/_output/.gitignore
create mode 100644 tests/_support/AcceptanceTester.php
create mode 100644 tests/_support/FunctionalTester.php
create mode 100644 tests/_support/UnitTester.php
create mode 100644 tests/acceptance.suite.yml.example
create mode 100644 tests/acceptance/AboutCest.php
create mode 100644 tests/acceptance/ContactCest.php
create mode 100644 tests/acceptance/HomeCest.php
create mode 100644 tests/acceptance/LoginCest.php
create mode 100644 tests/acceptance/_bootstrap.php
create mode 100644 tests/bin/yii
create mode 100644 tests/bin/yii.bat
create mode 100644 tests/functional.suite.yml
create mode 100644 tests/functional/ContactFormCest.php
create mode 100644 tests/functional/LoginFormCest.php
create mode 100644 tests/functional/_bootstrap.php
create mode 100644 tests/unit.suite.yml
create mode 100644 tests/unit/_bootstrap.php
create mode 100644 tests/unit/models/ContactFormTest.php
create mode 100644 tests/unit/models/LoginFormTest.php
create mode 100644 tests/unit/models/UserTest.php
create mode 100644 tests/unit/widgets/AlertTest.php
create mode 100644 views/layouts/main.php
create mode 100644 views/site/about.php
create mode 100644 views/site/contact.php
create mode 100644 views/site/error.php
create mode 100644 views/site/index.php
create mode 100644 views/site/login.php
create mode 100644 vue3/.gitignore
create mode 100644 vue3/.vscode/extensions.json
create mode 100644 vue3/README.md
create mode 100644 vue3/index.html
create mode 100644 vue3/package-lock.json
create mode 100644 vue3/package.json
create mode 100644 vue3/public/vite.svg
create mode 100644 vue3/src/App.vue
create mode 100644 vue3/src/assets/vue.svg
create mode 100644 vue3/src/main.js
create mode 100644 vue3/src/services/http.client.js
create mode 100644 vue3/src/services/test.service.js
create mode 100644 vue3/src/style.css
create mode 100644 vue3/vite.config.js
create mode 100644 web/.htaccess
create mode 100644 web/assets/index-c05be89e.css
create mode 100644 web/assets/index-c9f5c948.css
create mode 100644 web/assets/index-d563b5ec.js
create mode 100644 web/assets/index-e54ab67f.js
create mode 100644 web/assets/vue-5532db34.svg
create mode 100644 web/favicon.ico
create mode 100644 web/index-test.php
create mode 100644 web/index.html
create mode 100644 web/index.php
create mode 100644 web/robots.txt
create mode 100644 web/vite.svg
create mode 100644 widgets/Alert.php
create mode 100644 yii
create mode 100644 yii.bat
diff --git a/.bowerrc b/.bowerrc
new file mode 100644
index 0000000..a39b5b0
--- /dev/null
+++ b/.bowerrc
@@ -0,0 +1,3 @@
+{
+ "directory" : "vendor/bower-asset"
+}
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..460198d
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,39 @@
+# phpstorm project files
+.idea
+
+# netbeans project files
+nbproject
+
+# zend studio for eclipse project files
+.buildpath
+.project
+.settings
+
+# windows thumbnail cache
+Thumbs.db
+
+# composer vendor dir
+/vendor
+
+# composer itself is not needed
+composer.phar
+
+# composer lock
+composer.lock
+
+# Mac DS_Store Files
+.DS_Store
+
+# phpunit itself is not needed
+phpunit.phar
+# local phpunit config
+/phpunit.xml
+
+tests/_output/*
+tests/_support/_generated
+
+#vagrant folder
+/.vagrant
+
+# PostgreSQL database files
+/pgdata
diff --git a/LICENSE.md b/LICENSE.md
new file mode 100644
index 0000000..ee872b9
--- /dev/null
+++ b/LICENSE.md
@@ -0,0 +1,29 @@
+Copyright © 2008 by Yii Software LLC (http://www.yiisoft.com)
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions
+are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+ * Neither the name of Yii Software LLC nor the names of its
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGE.
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..37fc76d
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,14 @@
+init: docker-down-clear docker-up
+up: docker-up
+down: docker-down
+restart: down up
+
+docker-up:
+ docker-compose up -d
+
+docker-down:
+ docker-compose down --remove-orphans
+
+docker-down-clear:
+ docker-compose down -v --remove-orphans
+
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..981a7f9
--- /dev/null
+++ b/README.md
@@ -0,0 +1,233 @@
+
+
+
+
+
Yii 2 Basic Project Template
+
+
+
+Yii 2 Basic Project Template is a skeleton [Yii 2](https://www.yiiframework.com/) application best for
+rapidly creating small projects.
+
+The template contains the basic features including user login/logout and a contact page.
+It includes all commonly used configurations that would allow you to focus on adding new
+features to your application.
+
+[![Latest Stable Version](https://img.shields.io/packagist/v/yiisoft/yii2-app-basic.svg)](https://packagist.org/packages/yiisoft/yii2-app-basic)
+[![Total Downloads](https://img.shields.io/packagist/dt/yiisoft/yii2-app-basic.svg)](https://packagist.org/packages/yiisoft/yii2-app-basic)
+[![build](https://github.com/yiisoft/yii2-app-basic/workflows/build/badge.svg)](https://github.com/yiisoft/yii2-app-basic/actions?query=workflow%3Abuild)
+
+DIRECTORY STRUCTURE
+-------------------
+
+ assets/ contains assets definition
+ commands/ contains console commands (controllers)
+ config/ contains application configurations
+ controllers/ contains Web controller classes
+ mail/ contains view files for e-mails
+ models/ contains model classes
+ runtime/ contains files generated during runtime
+ tests/ contains various tests for the basic application
+ vendor/ contains dependent 3rd-party packages
+ views/ contains view files for the Web application
+ web/ contains the entry script and Web resources
+
+
+
+REQUIREMENTS
+------------
+
+The minimum requirement by this project template that your Web server supports PHP 7.4.
+
+
+INSTALLATION
+------------
+
+### Install via Composer
+
+If you do not have [Composer](https://getcomposer.org/), you may install it by following the instructions
+at [getcomposer.org](https://getcomposer.org/doc/00-intro.md#installation-nix).
+
+You can then install this project template using the following command:
+
+~~~
+composer create-project --prefer-dist yiisoft/yii2-app-basic basic
+~~~
+
+Now you should be able to access the application through the following URL, assuming `basic` is the directory
+directly under the Web root.
+
+~~~
+http://localhost/basic/web/
+~~~
+
+### Install from an Archive File
+
+Extract the archive file downloaded from [yiiframework.com](https://www.yiiframework.com/download/) to
+a directory named `basic` that is directly under the Web root.
+
+Set cookie validation key in `config/web.php` file to some random secret string:
+
+```php
+'request' => [
+ // !!! insert a secret key in the following (if it is empty) - this is required by cookie validation
+ 'cookieValidationKey' => '',
+],
+```
+
+You can then access the application through the following URL:
+
+~~~
+http://localhost/basic/web/
+~~~
+
+
+### Install with Docker
+
+Update your vendor packages
+
+ docker-compose run --rm php composer update --prefer-dist
+
+Run the installation triggers (creating cookie validation code)
+
+ docker-compose run --rm php composer install
+
+Start the container
+
+ docker-compose up -d
+
+You can then access the application through the following URL:
+
+ http://127.0.0.1:8000
+
+**NOTES:**
+- Minimum required Docker engine version `17.04` for development (see [Performance tuning for volume mounts](https://docs.docker.com/docker-for-mac/osxfs-caching/))
+- The default configuration uses a host-volume in your home directory `.docker-composer` for composer caches
+
+
+CONFIGURATION
+-------------
+
+### Database
+
+Edit the file `config/db.php` with real data, for example:
+
+```php
+return [
+ 'class' => 'yii\db\Connection',
+ 'dsn' => 'mysql:host=localhost;dbname=yii2basic',
+ 'username' => 'root',
+ 'password' => '1234',
+ 'charset' => 'utf8',
+];
+```
+
+**NOTES:**
+- Yii won't create the database for you, this has to be done manually before you can access it.
+- Check and edit the other files in the `config/` directory to customize your application as required.
+- Refer to the README in the `tests` directory for information specific to basic application tests.
+
+
+TESTING
+-------
+
+Tests are located in `tests` directory. They are developed with [Codeception PHP Testing Framework](https://codeception.com/).
+By default, there are 3 test suites:
+
+- `unit`
+- `functional`
+- `acceptance`
+
+Tests can be executed by running
+
+```
+vendor/bin/codecept run
+```
+
+The command above will execute unit and functional tests. Unit tests are testing the system components, while functional
+tests are for testing user interaction. Acceptance tests are disabled by default as they require additional setup since
+they perform testing in real browser.
+
+
+### Running acceptance tests
+
+To execute acceptance tests do the following:
+
+1. Rename `tests/acceptance.suite.yml.example` to `tests/acceptance.suite.yml` to enable suite configuration
+
+2. Replace `codeception/base` package in `composer.json` with `codeception/codeception` to install full-featured
+ version of Codeception
+
+3. Update dependencies with Composer
+
+ ```
+ composer update
+ ```
+
+4. Download [Selenium Server](https://www.seleniumhq.org/download/) and launch it:
+
+ ```
+ java -jar ~/selenium-server-standalone-x.xx.x.jar
+ ```
+
+ In case of using Selenium Server 3.0 with Firefox browser since v48 or Google Chrome since v53 you must download [GeckoDriver](https://github.com/mozilla/geckodriver/releases) or [ChromeDriver](https://sites.google.com/a/chromium.org/chromedriver/downloads) and launch Selenium with it:
+
+ ```
+ # for Firefox
+ java -jar -Dwebdriver.gecko.driver=~/geckodriver ~/selenium-server-standalone-3.xx.x.jar
+
+ # for Google Chrome
+ java -jar -Dwebdriver.chrome.driver=~/chromedriver ~/selenium-server-standalone-3.xx.x.jar
+ ```
+
+ As an alternative way you can use already configured Docker container with older versions of Selenium and Firefox:
+
+ ```
+ docker run --net=host selenium/standalone-firefox:2.53.0
+ ```
+
+5. (Optional) Create `yii2basic_test` database and update it by applying migrations if you have them.
+
+ ```
+ tests/bin/yii migrate
+ ```
+
+ The database configuration can be found at `config/test_db.php`.
+
+
+6. Start web server:
+
+ ```
+ tests/bin/yii serve
+ ```
+
+7. Now you can run all available tests
+
+ ```
+ # run all available tests
+ vendor/bin/codecept run
+
+ # run acceptance tests
+ vendor/bin/codecept run acceptance
+
+ # run only unit and functional tests
+ vendor/bin/codecept run unit,functional
+ ```
+
+### Code coverage support
+
+By default, code coverage is disabled in `codeception.yml` configuration file, you should uncomment needed rows to be able
+to collect code coverage. You can run your tests and collect coverage with the following command:
+
+```
+#collect coverage for all tests
+vendor/bin/codecept run --coverage --coverage-html --coverage-xml
+
+#collect coverage only for unit tests
+vendor/bin/codecept run unit --coverage --coverage-html --coverage-xml
+
+#collect coverage for unit and functional tests
+vendor/bin/codecept run functional,unit --coverage --coverage-html --coverage-xml
+```
+
+You can see code coverage output under the `tests/_output` directory.
diff --git a/assets/AppAsset.php b/assets/AppAsset.php
new file mode 100644
index 0000000..3d40487
--- /dev/null
+++ b/assets/AppAsset.php
@@ -0,0 +1,31 @@
+
+ * @since 2.0
+ */
+class AppAsset extends AssetBundle
+{
+ public $basePath = '@webroot';
+ public $baseUrl = '@web';
+ public $css = [
+ 'css/site.css',
+ ];
+ public $js = [
+ ];
+ public $depends = [
+ 'yii\web\YiiAsset',
+ 'yii\bootstrap5\BootstrapAsset'
+ ];
+}
diff --git a/codeception.yml b/codeception.yml
new file mode 100644
index 0000000..dd8febc
--- /dev/null
+++ b/codeception.yml
@@ -0,0 +1,27 @@
+actor: Tester
+bootstrap: _bootstrap.php
+paths:
+ tests: tests
+ output: tests/_output
+ data: tests/_data
+ helpers: tests/_support
+settings:
+ memory_limit: 1024M
+ colors: true
+modules:
+ config:
+ Yii2:
+ configFile: 'config/test.php'
+
+# To enable code coverage:
+#coverage:
+# #c3_url: http://localhost:8080/index-test.php/
+# enabled: true
+# #remote: true
+# #remote_config: '../codeception.yml'
+# whitelist:
+# include:
+# - models/*
+# - controllers/*
+# - commands/*
+# - mail/*
diff --git a/commands/HelloController.php b/commands/HelloController.php
new file mode 100644
index 0000000..9ec914d
--- /dev/null
+++ b/commands/HelloController.php
@@ -0,0 +1,34 @@
+
+ * @since 2.0
+ */
+class HelloController extends Controller
+{
+ /**
+ * This command echoes what you have entered as the message.
+ * @param string $message the message to be echoed.
+ * @return int Exit code
+ */
+ public function actionIndex($message = 'hello world')
+ {
+ echo $message . "\n";
+
+ return ExitCode::OK;
+ }
+}
diff --git a/composer.json b/composer.json
new file mode 100644
index 0000000..59b9380
--- /dev/null
+++ b/composer.json
@@ -0,0 +1,75 @@
+{
+ "name": "yiisoft/yii2-app-basic",
+ "description": "Yii 2 Basic Project Template",
+ "keywords": ["yii2", "framework", "basic", "project template"],
+ "homepage": "https://www.yiiframework.com/",
+ "type": "project",
+ "license": "BSD-3-Clause",
+ "support": {
+ "issues": "https://github.com/yiisoft/yii2/issues?state=open",
+ "forum": "https://www.yiiframework.com/forum/",
+ "wiki": "https://www.yiiframework.com/wiki/",
+ "irc": "irc://irc.freenode.net/yii",
+ "source": "https://github.com/yiisoft/yii2"
+ },
+ "minimum-stability": "stable",
+ "require": {
+ "php": ">=7.4.0",
+ "yiisoft/yii2": "~2.0.45",
+ "yiisoft/yii2-bootstrap5": "~2.0.2",
+ "yiisoft/yii2-symfonymailer": "~2.0.3"
+ },
+ "require-dev": {
+ "yiisoft/yii2-debug": "~2.1.0",
+ "yiisoft/yii2-gii": "~2.2.0",
+ "yiisoft/yii2-faker": "~2.0.0",
+ "phpunit/phpunit": "~9.5.0",
+ "codeception/codeception": "^5.0.0 || ^4.0",
+ "codeception/lib-innerbrowser": "^4.0 || ^3.0 || ^1.1",
+ "codeception/module-asserts": "^3.0 || ^1.1",
+ "codeception/module-yii2": "^1.1",
+ "codeception/module-filesystem": "^3.0 || ^2.0 || ^1.1",
+ "codeception/verify": "^3.0 || ^2.2",
+ "symfony/browser-kit": "^6.0 || >=2.7 <=4.2.4"
+ },
+ "config": {
+ "allow-plugins": {
+ "yiisoft/yii2-composer" : true
+ },
+ "process-timeout": 1800,
+ "fxp-asset": {
+ "enabled": false
+ }
+ },
+ "scripts": {
+ "post-install-cmd": [
+ "yii\\composer\\Installer::postInstall"
+ ],
+ "post-create-project-cmd": [
+ "yii\\composer\\Installer::postCreateProject",
+ "yii\\composer\\Installer::postInstall"
+ ]
+ },
+ "extra": {
+ "yii\\composer\\Installer::postCreateProject": {
+ "setPermission": [
+ {
+ "runtime": "0777",
+ "web/assets": "0777",
+ "yii": "0755"
+ }
+ ]
+ },
+ "yii\\composer\\Installer::postInstall": {
+ "generateCookieValidationKey": [
+ "config/web.php"
+ ]
+ }
+ },
+ "repositories": [
+ {
+ "type": "composer",
+ "url": "https://asset-packagist.org"
+ }
+ ]
+}
diff --git a/config/__autocomplete.php b/config/__autocomplete.php
new file mode 100644
index 0000000..d99dea5
--- /dev/null
+++ b/config/__autocomplete.php
@@ -0,0 +1,33 @@
+ 'basic-console',
+ 'basePath' => dirname(__DIR__),
+ 'bootstrap' => ['log'],
+ 'controllerNamespace' => 'app\commands',
+ 'aliases' => [
+ '@bower' => '@vendor/bower-asset',
+ '@npm' => '@vendor/npm-asset',
+ '@tests' => '@app/tests',
+ ],
+ 'components' => [
+ 'cache' => [
+ 'class' => 'yii\caching\FileCache',
+ ],
+ 'log' => [
+ 'targets' => [
+ [
+ 'class' => 'yii\log\FileTarget',
+ 'levels' => ['error', 'warning'],
+ ],
+ ],
+ ],
+ 'db' => $db,
+ ],
+ 'params' => $params,
+ /*
+ 'controllerMap' => [
+ 'fixture' => [ // Fixture generation command line.
+ 'class' => 'yii\faker\FixtureController',
+ ],
+ ],
+ */
+];
+
+if (YII_ENV_DEV) {
+ // configuration adjustments for 'dev' environment
+ $config['bootstrap'][] = 'gii';
+ $config['modules']['gii'] = [
+ 'class' => 'yii\gii\Module',
+ ];
+ // configuration adjustments for 'dev' environment
+ // requires version `2.1.21` of yii2-debug module
+ $config['bootstrap'][] = 'debug';
+ $config['modules']['debug'] = [
+ 'class' => 'yii\debug\Module',
+ // uncomment the following to add your IP if you are not connecting from localhost.
+ //'allowedIPs' => ['127.0.0.1', '::1'],
+ ];
+}
+
+return $config;
diff --git a/config/db.php b/config/db.php
new file mode 100644
index 0000000..bc75e61
--- /dev/null
+++ b/config/db.php
@@ -0,0 +1,14 @@
+ 'yii\db\Connection',
+ 'dsn' => 'mysql:host=localhost;dbname=yii2basic',
+ 'username' => 'root',
+ 'password' => '',
+ 'charset' => 'utf8',
+
+ // Schema cache options (for production environment)
+ //'enableSchemaCache' => true,
+ //'schemaCacheDuration' => 60,
+ //'schemaCache' => 'cache',
+];
diff --git a/config/params.php b/config/params.php
new file mode 100644
index 0000000..981c621
--- /dev/null
+++ b/config/params.php
@@ -0,0 +1,7 @@
+ 'admin@example.com',
+ 'senderEmail' => 'noreply@example.com',
+ 'senderName' => 'Example.com mailer',
+];
diff --git a/config/test.php b/config/test.php
new file mode 100644
index 0000000..317bc1c
--- /dev/null
+++ b/config/test.php
@@ -0,0 +1,46 @@
+ 'basic-tests',
+ 'basePath' => dirname(__DIR__),
+ 'aliases' => [
+ '@bower' => '@vendor/bower-asset',
+ '@npm' => '@vendor/npm-asset',
+ ],
+ 'language' => 'en-US',
+ 'components' => [
+ 'db' => $db,
+ 'mailer' => [
+ 'class' => \yii\symfonymailer\Mailer::class,
+ 'viewPath' => '@app/mail',
+ // send all mails to a file by default.
+ 'useFileTransport' => true,
+ 'messageClass' => 'yii\symfonymailer\Message'
+ ],
+ 'assetManager' => [
+ 'basePath' => __DIR__ . '/../web/assets',
+ ],
+ 'urlManager' => [
+ 'showScriptName' => true,
+ ],
+ 'user' => [
+ 'identityClass' => 'app\models\User',
+ ],
+ 'request' => [
+ 'cookieValidationKey' => 'test',
+ 'enableCsrfValidation' => false,
+ // but if you absolutely need it set cookie domain to localhost
+ /*
+ 'csrfCookie' => [
+ 'domain' => 'localhost',
+ ],
+ */
+ ],
+ ],
+ 'params' => $params,
+];
diff --git a/config/test_db.php b/config/test_db.php
new file mode 100644
index 0000000..f4290e0
--- /dev/null
+++ b/config/test_db.php
@@ -0,0 +1,6 @@
+ 'basic',
+ 'basePath' => dirname(__DIR__),
+ 'bootstrap' => ['log'],
+ 'aliases' => [
+ '@bower' => '@vendor/bower-asset',
+ '@npm' => '@vendor/npm-asset',
+ ],
+ 'components' => [
+ 'request' => [
+ // !!! insert a secret key in the following (if it is empty) - this is required by cookie validation
+ 'cookieValidationKey' => 'kxzoL3hScKXhQzb-QNrA75YJw7mrG_Su',
+ ],
+ 'cache' => [
+ 'class' => 'yii\caching\FileCache',
+ ],
+ 'user' => [
+ 'identityClass' => 'app\models\User',
+ 'enableAutoLogin' => true,
+ ],
+ 'errorHandler' => [
+ 'errorAction' => 'site/error',
+ ],
+ 'mailer' => [
+ 'class' => \yii\symfonymailer\Mailer::class,
+ 'viewPath' => '@app/mail',
+ // send all mails to a file by default.
+ 'useFileTransport' => true,
+ ],
+ 'log' => [
+ 'traceLevel' => YII_DEBUG ? 3 : 0,
+ 'targets' => [
+ [
+ 'class' => 'yii\log\FileTarget',
+ 'levels' => ['error', 'warning'],
+ ],
+ ],
+ ],
+ 'db' => $db,
+ 'urlManager' => [
+ 'enablePrettyUrl' => true,
+ 'showScriptName' => false,
+ 'rules' => [
+ ],
+ ],
+ ],
+ 'params' => $params,
+];
+
+if (YII_ENV_DEV) {
+ // configuration adjustments for 'dev' environment
+ $config['bootstrap'][] = 'debug';
+ $config['modules']['debug'] = [
+ 'class' => 'yii\debug\Module',
+ // uncomment the following to add your IP if you are not connecting from localhost.
+ //'allowedIPs' => ['127.0.0.1', '::1'],
+ ];
+
+ $config['bootstrap'][] = 'gii';
+ $config['modules']['gii'] = [
+ 'class' => 'yii\gii\Module',
+ // uncomment the following to add your IP if you are not connecting from localhost.
+ //'allowedIPs' => ['127.0.0.1', '::1'],
+ ];
+}
+
+return $config;
diff --git a/controllers/SiteController.php b/controllers/SiteController.php
new file mode 100644
index 0000000..67c3f50
--- /dev/null
+++ b/controllers/SiteController.php
@@ -0,0 +1,128 @@
+ [
+ 'class' => AccessControl::class,
+ 'only' => ['logout'],
+ 'rules' => [
+ [
+ 'actions' => ['logout'],
+ 'allow' => true,
+ 'roles' => ['@'],
+ ],
+ ],
+ ],
+ 'verbs' => [
+ 'class' => VerbFilter::class,
+ 'actions' => [
+ 'logout' => ['post'],
+ ],
+ ],
+ ];
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function actions()
+ {
+ return [
+ 'error' => [
+ 'class' => 'yii\web\ErrorAction',
+ ],
+ 'captcha' => [
+ 'class' => 'yii\captcha\CaptchaAction',
+ 'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null,
+ ],
+ ];
+ }
+
+ /**
+ * Displays homepage.
+ *
+ * @return string
+ */
+ public function actionIndex()
+ {
+ return $this->render('index');
+ }
+
+ /**
+ * Login action.
+ *
+ * @return Response|string
+ */
+ public function actionLogin()
+ {
+ if (!Yii::$app->user->isGuest) {
+ return $this->goHome();
+ }
+
+ $model = new LoginForm();
+ if ($model->load(Yii::$app->request->post()) && $model->login()) {
+ return $this->goBack();
+ }
+
+ $model->password = '';
+ return $this->render('login', [
+ 'model' => $model,
+ ]);
+ }
+
+ /**
+ * Logout action.
+ *
+ * @return Response
+ */
+ public function actionLogout()
+ {
+ Yii::$app->user->logout();
+
+ return $this->goHome();
+ }
+
+ /**
+ * Displays contact page.
+ *
+ * @return Response|string
+ */
+ public function actionContact()
+ {
+ $model = new ContactForm();
+ if ($model->load(Yii::$app->request->post()) && $model->contact(Yii::$app->params['adminEmail'])) {
+ Yii::$app->session->setFlash('contactFormSubmitted');
+
+ return $this->refresh();
+ }
+ return $this->render('contact', [
+ 'model' => $model,
+ ]);
+ }
+
+ /**
+ * Displays about page.
+ *
+ * @return string
+ */
+ public function actionAbout()
+ {
+ return $this->render('about');
+ }
+}
diff --git a/controllers/api/TestController.php b/controllers/api/TestController.php
new file mode 100644
index 0000000..bc6f6dc
--- /dev/null
+++ b/controllers/api/TestController.php
@@ -0,0 +1,15 @@
+
+beginPage() ?>
+
+
+
+
+ = Html::encode($this->title) ?>
+ head() ?>
+
+
+ beginBody() ?>
+ = $content ?>
+ endBody() ?>
+
+
+endPage() ?>
diff --git a/mail/layouts/text.php b/mail/layouts/text.php
new file mode 100644
index 0000000..c376864
--- /dev/null
+++ b/mail/layouts/text.php
@@ -0,0 +1,13 @@
+beginPage();
+$this->beginBody();
+echo $content;
+$this->endBody();
+$this->endPage();
diff --git a/models/ContactForm.php b/models/ContactForm.php
new file mode 100644
index 0000000..f001d21
--- /dev/null
+++ b/models/ContactForm.php
@@ -0,0 +1,65 @@
+ 'Verification Code',
+ ];
+ }
+
+ /**
+ * Sends an email to the specified email address using the information collected by this model.
+ * @param string $email the target email address
+ * @return bool whether the model passes validation
+ */
+ public function contact($email)
+ {
+ if ($this->validate()) {
+ Yii::$app->mailer->compose()
+ ->setTo($email)
+ ->setFrom([Yii::$app->params['senderEmail'] => Yii::$app->params['senderName']])
+ ->setReplyTo([$this->email => $this->name])
+ ->setSubject($this->subject)
+ ->setTextBody($this->body)
+ ->send();
+
+ return true;
+ }
+ return false;
+ }
+}
diff --git a/models/LoginForm.php b/models/LoginForm.php
new file mode 100644
index 0000000..dce15cc
--- /dev/null
+++ b/models/LoginForm.php
@@ -0,0 +1,81 @@
+hasErrors()) {
+ $user = $this->getUser();
+
+ if (!$user || !$user->validatePassword($this->password)) {
+ $this->addError($attribute, 'Incorrect username or password.');
+ }
+ }
+ }
+
+ /**
+ * Logs in a user using the provided username and password.
+ * @return bool whether the user is logged in successfully
+ */
+ public function login()
+ {
+ if ($this->validate()) {
+ return Yii::$app->user->login($this->getUser(), $this->rememberMe ? 3600*24*30 : 0);
+ }
+ return false;
+ }
+
+ /**
+ * Finds user by [[username]]
+ *
+ * @return User|null
+ */
+ public function getUser()
+ {
+ if ($this->_user === false) {
+ $this->_user = User::findByUsername($this->username);
+ }
+
+ return $this->_user;
+ }
+}
diff --git a/models/User.php b/models/User.php
new file mode 100644
index 0000000..2e3fb25
--- /dev/null
+++ b/models/User.php
@@ -0,0 +1,104 @@
+ [
+ 'id' => '100',
+ 'username' => 'admin',
+ 'password' => 'admin',
+ 'authKey' => 'test100key',
+ 'accessToken' => '100-token',
+ ],
+ '101' => [
+ 'id' => '101',
+ 'username' => 'demo',
+ 'password' => 'demo',
+ 'authKey' => 'test101key',
+ 'accessToken' => '101-token',
+ ],
+ ];
+
+
+ /**
+ * {@inheritdoc}
+ */
+ public static function findIdentity($id)
+ {
+ return isset(self::$users[$id]) ? new static(self::$users[$id]) : null;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public static function findIdentityByAccessToken($token, $type = null)
+ {
+ foreach (self::$users as $user) {
+ if ($user['accessToken'] === $token) {
+ return new static($user);
+ }
+ }
+
+ return null;
+ }
+
+ /**
+ * Finds user by username
+ *
+ * @param string $username
+ * @return static|null
+ */
+ public static function findByUsername($username)
+ {
+ foreach (self::$users as $user) {
+ if (strcasecmp($user['username'], $username) === 0) {
+ return new static($user);
+ }
+ }
+
+ return null;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getId()
+ {
+ return $this->id;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getAuthKey()
+ {
+ return $this->authKey;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function validateAuthKey($authKey)
+ {
+ return $this->authKey === $authKey;
+ }
+
+ /**
+ * Validates password
+ *
+ * @param string $password password to validate
+ * @return bool if password provided is valid for current user
+ */
+ public function validatePassword($password)
+ {
+ return $this->password === $password;
+ }
+}
diff --git a/requirements.php b/requirements.php
new file mode 100644
index 0000000..c1a6bf6
--- /dev/null
+++ b/requirements.php
@@ -0,0 +1,162 @@
+Error\n\n"
+ . "The path to yii framework seems to be incorrect.
\n"
+ . 'You need to install Yii framework via composer or adjust the framework path in file ' . basename(__FILE__) . ".
\n"
+ . 'Please refer to the README on how to install Yii.
\n";
+
+ if (!empty($_SERVER['argv'])) {
+ // do not print HTML when used in console mode
+ echo strip_tags($message);
+ } else {
+ echo $message;
+ }
+ exit(1);
+}
+
+require_once($frameworkPath . '/requirements/YiiRequirementChecker.php');
+$requirementsChecker = new YiiRequirementChecker();
+
+$gdMemo = $imagickMemo = 'Either GD PHP extension with FreeType support or ImageMagick PHP extension with PNG support is required for image CAPTCHA.';
+$gdOK = $imagickOK = false;
+
+if (extension_loaded('imagick')) {
+ $imagick = new Imagick();
+ $imagickFormats = $imagick->queryFormats('PNG');
+ if (in_array('PNG', $imagickFormats)) {
+ $imagickOK = true;
+ } else {
+ $imagickMemo = 'Imagick extension should be installed with PNG support in order to be used for image CAPTCHA.';
+ }
+}
+
+if (extension_loaded('gd')) {
+ $gdInfo = gd_info();
+ if (!empty($gdInfo['FreeType Support'])) {
+ $gdOK = true;
+ } else {
+ $gdMemo = 'GD extension should be installed with FreeType support in order to be used for image CAPTCHA.';
+ }
+}
+
+/**
+ * Adjust requirements according to your application specifics.
+ */
+$requirements = array(
+ // Database :
+ array(
+ 'name' => 'PDO extension',
+ 'mandatory' => true,
+ 'condition' => extension_loaded('pdo'),
+ 'by' => 'All DB-related classes',
+ ),
+ array(
+ 'name' => 'PDO SQLite extension',
+ 'mandatory' => false,
+ 'condition' => extension_loaded('pdo_sqlite'),
+ 'by' => 'All DB-related classes',
+ 'memo' => 'Required for SQLite database.',
+ ),
+ array(
+ 'name' => 'PDO MySQL extension',
+ 'mandatory' => false,
+ 'condition' => extension_loaded('pdo_mysql'),
+ 'by' => 'All DB-related classes',
+ 'memo' => 'Required for MySQL database.',
+ ),
+ array(
+ 'name' => 'PDO PostgreSQL extension',
+ 'mandatory' => false,
+ 'condition' => extension_loaded('pdo_pgsql'),
+ 'by' => 'All DB-related classes',
+ 'memo' => 'Required for PostgreSQL database.',
+ ),
+ // Cache :
+ array(
+ 'name' => 'Memcache extension',
+ 'mandatory' => false,
+ 'condition' => extension_loaded('memcache') || extension_loaded('memcached'),
+ 'by' => 'MemCache',
+ 'memo' => extension_loaded('memcached') ? 'To use memcached set MemCache::useMemcached to true
.' : ''
+ ),
+ // CAPTCHA:
+ array(
+ 'name' => 'GD PHP extension with FreeType support',
+ 'mandatory' => false,
+ 'condition' => $gdOK,
+ 'by' => 'Captcha',
+ 'memo' => $gdMemo,
+ ),
+ array(
+ 'name' => 'ImageMagick PHP extension with PNG support',
+ 'mandatory' => false,
+ 'condition' => $imagickOK,
+ 'by' => 'Captcha',
+ 'memo' => $imagickMemo,
+ ),
+ // PHP ini :
+ 'phpExposePhp' => array(
+ 'name' => 'Expose PHP',
+ 'mandatory' => false,
+ 'condition' => $requirementsChecker->checkPhpIniOff("expose_php"),
+ 'by' => 'Security reasons',
+ 'memo' => '"expose_php" should be disabled at php.ini',
+ ),
+ 'phpAllowUrlInclude' => array(
+ 'name' => 'PHP allow url include',
+ 'mandatory' => false,
+ 'condition' => $requirementsChecker->checkPhpIniOff("allow_url_include"),
+ 'by' => 'Security reasons',
+ 'memo' => '"allow_url_include" should be disabled at php.ini',
+ ),
+ 'phpSmtp' => array(
+ 'name' => 'PHP mail SMTP',
+ 'mandatory' => false,
+ 'condition' => strlen(ini_get('SMTP')) > 0,
+ 'by' => 'Email sending',
+ 'memo' => 'PHP mail SMTP server required',
+ ),
+);
+
+// OPcache check
+if (!version_compare(phpversion(), '5.5', '>=')) {
+ $requirements[] = array(
+ 'name' => 'APC extension',
+ 'mandatory' => false,
+ 'condition' => extension_loaded('apc'),
+ 'by' => 'ApcCache',
+ );
+}
+
+$result = $requirementsChecker->checkYii()->check($requirements)->getResult();
+$requirementsChecker->render();
+exit($result['summary']['errors'] === 0 ? 0 : 1);
diff --git a/runtime/.gitignore b/runtime/.gitignore
new file mode 100644
index 0000000..c96a04f
--- /dev/null
+++ b/runtime/.gitignore
@@ -0,0 +1,2 @@
+*
+!.gitignore
\ No newline at end of file
diff --git a/tests/_bootstrap.php b/tests/_bootstrap.php
new file mode 100644
index 0000000..131da42
--- /dev/null
+++ b/tests/_bootstrap.php
@@ -0,0 +1,6 @@
+amOnPage(Url::toRoute('/site/about'));
+ $I->see('About', 'h1');
+ }
+}
diff --git a/tests/acceptance/ContactCest.php b/tests/acceptance/ContactCest.php
new file mode 100644
index 0000000..90f9848
--- /dev/null
+++ b/tests/acceptance/ContactCest.php
@@ -0,0 +1,34 @@
+amOnPage(Url::toRoute('/site/contact'));
+ }
+
+ public function contactPageWorks(AcceptanceTester $I)
+ {
+ $I->wantTo('ensure that contact page works');
+ $I->see('Contact', 'h1');
+ }
+
+ public function contactFormCanBeSubmitted(AcceptanceTester $I)
+ {
+ $I->amGoingTo('submit contact form with correct data');
+ $I->fillField('#contactform-name', 'tester');
+ $I->fillField('#contactform-email', 'tester@example.com');
+ $I->fillField('#contactform-subject', 'test subject');
+ $I->fillField('#contactform-body', 'test content');
+ $I->fillField('#contactform-verifycode', 'testme');
+
+ $I->click('contact-button');
+
+ $I->wait(2); // wait for button to be clicked
+
+ $I->dontSeeElement('#contact-form');
+ $I->see('Thank you for contacting us. We will respond to you as soon as possible.');
+ }
+}
diff --git a/tests/acceptance/HomeCest.php b/tests/acceptance/HomeCest.php
new file mode 100644
index 0000000..e65df16
--- /dev/null
+++ b/tests/acceptance/HomeCest.php
@@ -0,0 +1,18 @@
+amOnPage(Url::toRoute('/site/index'));
+ $I->see('My Company');
+
+ $I->seeLink('About');
+ $I->click('About');
+ $I->wait(2); // wait for page to be opened
+
+ $I->see('This is the About page.');
+ }
+}
diff --git a/tests/acceptance/LoginCest.php b/tests/acceptance/LoginCest.php
new file mode 100644
index 0000000..6f5cb2f
--- /dev/null
+++ b/tests/acceptance/LoginCest.php
@@ -0,0 +1,21 @@
+amOnPage(Url::toRoute('/site/login'));
+ $I->see('Login', 'h1');
+
+ $I->amGoingTo('try to login with correct credentials');
+ $I->fillField('input[name="LoginForm[username]"]', 'admin');
+ $I->fillField('input[name="LoginForm[password]"]', 'admin');
+ $I->click('login-button');
+ $I->wait(2); // wait for button to be clicked
+
+ $I->expectTo('see user info');
+ $I->see('Logout');
+ }
+}
diff --git a/tests/acceptance/_bootstrap.php b/tests/acceptance/_bootstrap.php
new file mode 100644
index 0000000..b3d9bbc
--- /dev/null
+++ b/tests/acceptance/_bootstrap.php
@@ -0,0 +1 @@
+ [
+ 'db' => require __DIR__ . '/../../config/test_db.php'
+ ]
+ ]
+);
+
+
+$application = new yii\console\Application($config);
+$exitCode = $application->run();
+exit($exitCode);
diff --git a/tests/bin/yii.bat b/tests/bin/yii.bat
new file mode 100644
index 0000000..ce14c92
--- /dev/null
+++ b/tests/bin/yii.bat
@@ -0,0 +1,20 @@
+@echo off
+
+rem -------------------------------------------------------------
+rem Yii command line bootstrap script for Windows.
+rem
+rem @author Qiang Xue
+rem @link https://www.yiiframework.com/
+rem @copyright Copyright (c) 2008 Yii Software LLC
+rem @license https://www.yiiframework.com/license/
+rem -------------------------------------------------------------
+
+@setlocal
+
+set YII_PATH=%~dp0
+
+if "%PHP_COMMAND%" == "" set PHP_COMMAND=php.exe
+
+"%PHP_COMMAND%" "%YII_PATH%yii" %*
+
+@endlocal
diff --git a/tests/functional.suite.yml b/tests/functional.suite.yml
new file mode 100644
index 0000000..9d8cf14
--- /dev/null
+++ b/tests/functional.suite.yml
@@ -0,0 +1,14 @@
+# 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
+actor: FunctionalTester
+modules:
+ enabled:
+ - Filesystem
+ - Yii2
+ - Asserts
diff --git a/tests/functional/ContactFormCest.php b/tests/functional/ContactFormCest.php
new file mode 100644
index 0000000..d17ef52
--- /dev/null
+++ b/tests/functional/ContactFormCest.php
@@ -0,0 +1,57 @@
+amOnRoute('site/contact');
+ }
+
+ public function openContactPage(\FunctionalTester $I)
+ {
+ $I->see('Contact', 'h1');
+ }
+
+ public function submitEmptyForm(\FunctionalTester $I)
+ {
+ $I->submitForm('#contact-form', []);
+ $I->expectTo('see validations errors');
+ $I->see('Contact', 'h1');
+ $I->see('Name cannot be blank');
+ $I->see('Email cannot be blank');
+ $I->see('Subject cannot be blank');
+ $I->see('Body cannot be blank');
+ $I->see('The verification code is incorrect');
+ }
+
+ public function submitFormWithIncorrectEmail(\FunctionalTester $I)
+ {
+ $I->submitForm('#contact-form', [
+ 'ContactForm[name]' => 'tester',
+ 'ContactForm[email]' => 'tester.email',
+ 'ContactForm[subject]' => 'test subject',
+ 'ContactForm[body]' => 'test content',
+ 'ContactForm[verifyCode]' => 'testme',
+ ]);
+ $I->expectTo('see that email address is wrong');
+ $I->dontSee('Name cannot be blank', '.help-inline');
+ $I->see('Email is not a valid email address.');
+ $I->dontSee('Subject cannot be blank', '.help-inline');
+ $I->dontSee('Body cannot be blank', '.help-inline');
+ $I->dontSee('The verification code is incorrect', '.help-inline');
+ }
+
+ public function submitFormSuccessfully(\FunctionalTester $I)
+ {
+ $I->submitForm('#contact-form', [
+ 'ContactForm[name]' => 'tester',
+ 'ContactForm[email]' => 'tester@example.com',
+ 'ContactForm[subject]' => 'test subject',
+ 'ContactForm[body]' => 'test content',
+ 'ContactForm[verifyCode]' => 'testme',
+ ]);
+ $I->seeEmailIsSent();
+ $I->dontSeeElement('#contact-form');
+ $I->see('Thank you for contacting us. We will respond to you as soon as possible.');
+ }
+}
diff --git a/tests/functional/LoginFormCest.php b/tests/functional/LoginFormCest.php
new file mode 100644
index 0000000..7a83a27
--- /dev/null
+++ b/tests/functional/LoginFormCest.php
@@ -0,0 +1,59 @@
+amOnRoute('site/login');
+ }
+
+ public function openLoginPage(\FunctionalTester $I)
+ {
+ $I->see('Login', 'h1');
+
+ }
+
+ // demonstrates `amLoggedInAs` method
+ public function internalLoginById(\FunctionalTester $I)
+ {
+ $I->amLoggedInAs(100);
+ $I->amOnPage('/');
+ $I->see('Logout (admin)');
+ }
+
+ // demonstrates `amLoggedInAs` method
+ public function internalLoginByInstance(\FunctionalTester $I)
+ {
+ $I->amLoggedInAs(\app\models\User::findByUsername('admin'));
+ $I->amOnPage('/');
+ $I->see('Logout (admin)');
+ }
+
+ public function loginWithEmptyCredentials(\FunctionalTester $I)
+ {
+ $I->submitForm('#login-form', []);
+ $I->expectTo('see validations errors');
+ $I->see('Username cannot be blank.');
+ $I->see('Password cannot be blank.');
+ }
+
+ public function loginWithWrongCredentials(\FunctionalTester $I)
+ {
+ $I->submitForm('#login-form', [
+ 'LoginForm[username]' => 'admin',
+ 'LoginForm[password]' => 'wrong',
+ ]);
+ $I->expectTo('see validations errors');
+ $I->see('Incorrect username or password.');
+ }
+
+ public function loginSuccessfully(\FunctionalTester $I)
+ {
+ $I->submitForm('#login-form', [
+ 'LoginForm[username]' => 'admin',
+ 'LoginForm[password]' => 'admin',
+ ]);
+ $I->see('Logout (admin)');
+ $I->dontSeeElement('form#login-form');
+ }
+}
\ No newline at end of file
diff --git a/tests/functional/_bootstrap.php b/tests/functional/_bootstrap.php
new file mode 100644
index 0000000..b3d9bbc
--- /dev/null
+++ b/tests/functional/_bootstrap.php
@@ -0,0 +1 @@
+attributes = [
+ 'name' => 'Tester',
+ 'email' => 'tester@example.com',
+ 'subject' => 'very important letter subject',
+ 'body' => 'body of current message',
+ 'verifyCode' => 'testme',
+ ];
+
+ verify($model->contact('admin@example.com'))->notEmpty();
+
+ // using Yii2 module actions to check email was sent
+ $this->tester->seeEmailIsSent();
+
+ /** @var MessageInterface $emailMessage */
+ $emailMessage = $this->tester->grabLastSentEmail();
+ verify($emailMessage)->instanceOf('yii\mail\MessageInterface');
+ verify($emailMessage->getTo())->arrayHasKey('admin@example.com');
+ verify($emailMessage->getFrom())->arrayHasKey('noreply@example.com');
+ verify($emailMessage->getReplyTo())->arrayHasKey('tester@example.com');
+ verify($emailMessage->getSubject())->equals('very important letter subject');
+ verify($emailMessage->toString())->stringContainsString('body of current message');
+ }
+}
diff --git a/tests/unit/models/LoginFormTest.php b/tests/unit/models/LoginFormTest.php
new file mode 100644
index 0000000..3c1dcdd
--- /dev/null
+++ b/tests/unit/models/LoginFormTest.php
@@ -0,0 +1,51 @@
+user->logout();
+ }
+
+ public function testLoginNoUser()
+ {
+ $this->model = new LoginForm([
+ 'username' => 'not_existing_username',
+ 'password' => 'not_existing_password',
+ ]);
+
+ verify($this->model->login())->false();
+ verify(\Yii::$app->user->isGuest)->true();
+ }
+
+ public function testLoginWrongPassword()
+ {
+ $this->model = new LoginForm([
+ 'username' => 'demo',
+ 'password' => 'wrong_password',
+ ]);
+
+ verify($this->model->login())->false();
+ verify(\Yii::$app->user->isGuest)->true();
+ verify($this->model->errors)->arrayHasKey('password');
+ }
+
+ public function testLoginCorrect()
+ {
+ $this->model = new LoginForm([
+ 'username' => 'demo',
+ 'password' => 'demo',
+ ]);
+
+ verify($this->model->login())->true();
+ verify(\Yii::$app->user->isGuest)->false();
+ verify($this->model->errors)->arrayHasNotKey('password');
+ }
+
+}
diff --git a/tests/unit/models/UserTest.php b/tests/unit/models/UserTest.php
new file mode 100644
index 0000000..28986cb
--- /dev/null
+++ b/tests/unit/models/UserTest.php
@@ -0,0 +1,44 @@
+notEmpty();
+ verify($user->username)->equals('admin');
+
+ verify(User::findIdentity(999))->empty();
+ }
+
+ public function testFindUserByAccessToken()
+ {
+ verify($user = User::findIdentityByAccessToken('100-token'))->notEmpty();
+ verify($user->username)->equals('admin');
+
+ verify(User::findIdentityByAccessToken('non-existing'))->empty();
+ }
+
+ public function testFindUserByUsername()
+ {
+ verify($user = User::findByUsername('admin'))->notEmpty();
+ verify(User::findByUsername('not-admin'))->empty();
+ }
+
+ /**
+ * @depends testFindUserByUsername
+ */
+ public function testValidateUser()
+ {
+ $user = User::findByUsername('admin');
+ verify($user->validateAuthKey('test100key'))->notEmpty();
+ verify($user->validateAuthKey('test102key'))->empty();
+
+ verify($user->validatePassword('admin'))->notEmpty();
+ verify($user->validatePassword('123456'))->empty();
+ }
+
+}
diff --git a/tests/unit/widgets/AlertTest.php b/tests/unit/widgets/AlertTest.php
new file mode 100644
index 0000000..e9857a1
--- /dev/null
+++ b/tests/unit/widgets/AlertTest.php
@@ -0,0 +1,261 @@
+session->setFlash('error', $message);
+
+ $renderingResult = Alert::widget();
+
+ verify($renderingResult)->stringContainsString($message);
+ verify($renderingResult)->stringContainsString('alert-danger');
+
+ verify($renderingResult)->stringNotContainsString('alert-success');
+ verify($renderingResult)->stringNotContainsString('alert-info');
+ verify($renderingResult)->stringNotContainsString('alert-warning');
+ }
+
+ public function testMultipleErrorMessages()
+ {
+ $firstMessage = 'This is the first error message';
+ $secondMessage = 'This is the second error message';
+
+ Yii::$app->session->setFlash('error', [$firstMessage, $secondMessage]);
+
+ $renderingResult = Alert::widget();
+
+ verify($renderingResult)->stringContainsString($firstMessage);
+ verify($renderingResult)->stringContainsString($secondMessage);
+ verify($renderingResult)->stringContainsString('alert-danger');
+
+ verify($renderingResult)->stringNotContainsString('alert-success');
+ verify($renderingResult)->stringNotContainsString('alert-info');
+ verify($renderingResult)->stringNotContainsString('alert-warning');
+ }
+
+ public function testSingleDangerMessage()
+ {
+ $message = 'This is a danger message';
+
+ Yii::$app->session->setFlash('danger', $message);
+
+ $renderingResult = Alert::widget();
+
+ verify($renderingResult)->stringContainsString($message);
+ verify($renderingResult)->stringContainsString('alert-danger');
+
+ verify($renderingResult)->stringNotContainsString('alert-success');
+ verify($renderingResult)->stringNotContainsString('alert-info');
+ verify($renderingResult)->stringNotContainsString('alert-warning');
+ }
+
+ public function testMultipleDangerMessages()
+ {
+ $firstMessage = 'This is the first danger message';
+ $secondMessage = 'This is the second danger message';
+
+ Yii::$app->session->setFlash('danger', [$firstMessage, $secondMessage]);
+
+ $renderingResult = Alert::widget();
+
+ verify($renderingResult)->stringContainsString($firstMessage);
+ verify($renderingResult)->stringContainsString($secondMessage);
+ verify($renderingResult)->stringContainsString('alert-danger');
+
+ verify($renderingResult)->stringNotContainsString('alert-success');
+ verify($renderingResult)->stringNotContainsString('alert-info');
+ verify($renderingResult)->stringNotContainsString('alert-warning');
+ }
+
+ public function testSingleSuccessMessage()
+ {
+ $message = 'This is a success message';
+
+ Yii::$app->session->setFlash('success', $message);
+
+ $renderingResult = Alert::widget();
+
+ verify($renderingResult)->stringContainsString($message);
+ verify($renderingResult)->stringContainsString('alert-success');
+
+ verify($renderingResult)->stringNotContainsString('alert-danger');
+ verify($renderingResult)->stringNotContainsString('alert-info');
+ verify($renderingResult)->stringNotContainsString('alert-warning');
+ }
+
+ public function testMultipleSuccessMessages()
+ {
+ $firstMessage = 'This is the first danger message';
+ $secondMessage = 'This is the second danger message';
+
+ Yii::$app->session->setFlash('success', [$firstMessage, $secondMessage]);
+
+ $renderingResult = Alert::widget();
+
+ verify($renderingResult)->stringContainsString($firstMessage);
+ verify($renderingResult)->stringContainsString($secondMessage);
+ verify($renderingResult)->stringContainsString('alert-success');
+
+ verify($renderingResult)->stringNotContainsString('alert-danger');
+ verify($renderingResult)->stringNotContainsString('alert-info');
+ verify($renderingResult)->stringNotContainsString('alert-warning');
+ }
+
+ public function testSingleInfoMessage()
+ {
+ $message = 'This is an info message';
+
+ Yii::$app->session->setFlash('info', $message);
+
+ $renderingResult = Alert::widget();
+
+ verify($renderingResult)->stringContainsString($message);
+ verify($renderingResult)->stringContainsString('alert-info');
+
+ verify($renderingResult)->stringNotContainsString('alert-danger');
+ verify($renderingResult)->stringNotContainsString('alert-success');
+ verify($renderingResult)->stringNotContainsString('alert-warning');
+ }
+
+ public function testMultipleInfoMessages()
+ {
+ $firstMessage = 'This is the first info message';
+ $secondMessage = 'This is the second info message';
+
+ Yii::$app->session->setFlash('info', [$firstMessage, $secondMessage]);
+
+ $renderingResult = Alert::widget();
+
+ verify($renderingResult)->stringContainsString($firstMessage);
+ verify($renderingResult)->stringContainsString($secondMessage);
+ verify($renderingResult)->stringContainsString('alert-info');
+
+ verify($renderingResult)->stringNotContainsString('alert-danger');
+ verify($renderingResult)->stringNotContainsString('alert-success');
+ verify($renderingResult)->stringNotContainsString('alert-warning');
+ }
+
+ public function testSingleWarningMessage()
+ {
+ $message = 'This is a warning message';
+
+ Yii::$app->session->setFlash('warning', $message);
+
+ $renderingResult = Alert::widget();
+
+ verify($renderingResult)->stringContainsString($message);
+ verify($renderingResult)->stringContainsString('alert-warning');
+
+ verify($renderingResult)->stringNotContainsString('alert-danger');
+ verify($renderingResult)->stringNotContainsString('alert-success');
+ verify($renderingResult)->stringNotContainsString('alert-info');
+ }
+
+ public function testMultipleWarningMessages()
+ {
+ $firstMessage = 'This is the first warning message';
+ $secondMessage = 'This is the second warning message';
+
+ Yii::$app->session->setFlash('warning', [$firstMessage, $secondMessage]);
+
+ $renderingResult = Alert::widget();
+
+ verify($renderingResult)->stringContainsString($firstMessage);
+ verify($renderingResult)->stringContainsString($secondMessage);
+ verify($renderingResult)->stringContainsString('alert-warning');
+
+ verify($renderingResult)->stringNotContainsString('alert-danger');
+ verify($renderingResult)->stringNotContainsString('alert-success');
+ verify($renderingResult)->stringNotContainsString('alert-info');
+ }
+
+ public function testSingleMixedMessages() {
+ $errorMessage = 'This is an error message';
+ $dangerMessage = 'This is a danger message';
+ $successMessage = 'This is a success message';
+ $infoMessage = 'This is a info message';
+ $warningMessage = 'This is a warning message';
+
+ Yii::$app->session->setFlash('error', $errorMessage);
+ Yii::$app->session->setFlash('danger', $dangerMessage);
+ Yii::$app->session->setFlash('success', $successMessage);
+ Yii::$app->session->setFlash('info', $infoMessage);
+ Yii::$app->session->setFlash('warning', $warningMessage);
+
+ $renderingResult = Alert::widget();
+
+ verify($renderingResult)->stringContainsString($errorMessage);
+ verify($renderingResult)->stringContainsString($dangerMessage);
+ verify($renderingResult)->stringContainsString($successMessage);
+ verify($renderingResult)->stringContainsString($infoMessage);
+ verify($renderingResult)->stringContainsString($warningMessage);
+
+ verify($renderingResult)->stringContainsString('alert-danger');
+ verify($renderingResult)->stringContainsString('alert-success');
+ verify($renderingResult)->stringContainsString('alert-info');
+ verify($renderingResult)->stringContainsString('alert-warning');
+ }
+
+ public function testMultipleMixedMessages() {
+ $firstErrorMessage = 'This is the first error message';
+ $secondErrorMessage = 'This is the second error message';
+ $firstDangerMessage = 'This is the first danger message';
+ $secondDangerMessage = 'This is the second';
+ $firstSuccessMessage = 'This is the first success message';
+ $secondSuccessMessage = 'This is the second success message';
+ $firstInfoMessage = 'This is the first info message';
+ $secondInfoMessage = 'This is the second info message';
+ $firstWarningMessage = 'This is the first warning message';
+ $secondWarningMessage = 'This is the second warning message';
+
+ Yii::$app->session->setFlash('error', [$firstErrorMessage, $secondErrorMessage]);
+ Yii::$app->session->setFlash('danger', [$firstDangerMessage, $secondDangerMessage]);
+ Yii::$app->session->setFlash('success', [$firstSuccessMessage, $secondSuccessMessage]);
+ Yii::$app->session->setFlash('info', [$firstInfoMessage, $secondInfoMessage]);
+ Yii::$app->session->setFlash('warning', [$firstWarningMessage, $secondWarningMessage]);
+
+ $renderingResult = Alert::widget();
+
+ verify($renderingResult)->stringContainsString($firstErrorMessage);
+ verify($renderingResult)->stringContainsString($secondErrorMessage);
+ verify($renderingResult)->stringContainsString($firstDangerMessage);
+ verify($renderingResult)->stringContainsString($secondDangerMessage);
+ verify($renderingResult)->stringContainsString($firstSuccessMessage);
+ verify($renderingResult)->stringContainsString($secondSuccessMessage);
+ verify($renderingResult)->stringContainsString($firstInfoMessage);
+ verify($renderingResult)->stringContainsString($secondInfoMessage);
+ verify($renderingResult)->stringContainsString($firstWarningMessage);
+ verify($renderingResult)->stringContainsString($secondWarningMessage);
+
+ verify($renderingResult)->stringContainsString('alert-danger');
+ verify($renderingResult)->stringContainsString('alert-success');
+ verify($renderingResult)->stringContainsString('alert-info');
+ verify($renderingResult)->stringContainsString('alert-warning');
+ }
+
+ public function testFlashIntegrity()
+ {
+ $errorMessage = 'This is an error message';
+ $unrelatedMessage = 'This is a message that is not related to the alert widget';
+
+ Yii::$app->session->setFlash('error', $errorMessage);
+ Yii::$app->session->setFlash('unrelated', $unrelatedMessage);
+
+ Alert::widget();
+
+ // Simulate redirect
+ Yii::$app->session->close();
+ Yii::$app->session->open();
+
+ verify(Yii::$app->session->getFlash('error'))->empty();
+ verify(Yii::$app->session->getFlash('unrelated'))->equals($unrelatedMessage);
+ }
+}
diff --git a/views/layouts/main.php b/views/layouts/main.php
new file mode 100644
index 0000000..d4fcbcb
--- /dev/null
+++ b/views/layouts/main.php
@@ -0,0 +1,6 @@
+
+
+= $html ?>
\ No newline at end of file
diff --git a/views/site/about.php b/views/site/about.php
new file mode 100644
index 0000000..ea006ec
--- /dev/null
+++ b/views/site/about.php
@@ -0,0 +1,18 @@
+title = 'About';
+$this->params['breadcrumbs'][] = $this->title;
+?>
+
+
= Html::encode($this->title) ?>
+
+
+ This is the About page. You may modify the following file to customize its content:
+
+
+
= __FILE__ ?>
+
diff --git a/views/site/contact.php b/views/site/contact.php
new file mode 100644
index 0000000..597fabc
--- /dev/null
+++ b/views/site/contact.php
@@ -0,0 +1,68 @@
+title = 'Contact';
+$this->params['breadcrumbs'][] = $this->title;
+?>
+
diff --git a/views/site/error.php b/views/site/error.php
new file mode 100644
index 0000000..4a37b25
--- /dev/null
+++ b/views/site/error.php
@@ -0,0 +1,27 @@
+title = $name;
+?>
+
+
+
= Html::encode($this->title) ?>
+
+
+ = nl2br(Html::encode($message)) ?>
+
+
+
+ The above error occurred while the Web server was processing your request.
+
+
+ Please contact us if you think this is a server error. Thank you.
+
+
+
diff --git a/views/site/index.php b/views/site/index.php
new file mode 100644
index 0000000..df5df7c
--- /dev/null
+++ b/views/site/index.php
@@ -0,0 +1,53 @@
+title = 'My Yii Application';
+?>
+
+
+
+
Congratulations!
+
+
You have successfully created your Yii-powered application.
+
+
Get started with Yii
+
+
+
+
+
+
+
Heading
+
+
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et
+ dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip
+ ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu
+ fugiat nulla pariatur.
+
+
Yii Documentation »
+
+
+
Heading
+
+
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et
+ dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip
+ ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu
+ fugiat nulla pariatur.
+
+
Yii Forum »
+
+
+
Heading
+
+
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et
+ dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip
+ ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu
+ fugiat nulla pariatur.
+
+
Yii Extensions »
+
+
+
+
+
diff --git a/views/site/login.php b/views/site/login.php
new file mode 100644
index 0000000..db003c0
--- /dev/null
+++ b/views/site/login.php
@@ -0,0 +1,55 @@
+title = 'Login';
+$this->params['breadcrumbs'][] = $this->title;
+?>
+
+
= Html::encode($this->title) ?>
+
+
Please fill out the following fields to login:
+
+
+
+
+ 'login-form',
+ 'fieldConfig' => [
+ 'template' => "{label}\n{input}\n{error}",
+ 'labelOptions' => ['class' => 'col-lg-1 col-form-label mr-lg-3'],
+ 'inputOptions' => ['class' => 'col-lg-3 form-control'],
+ 'errorOptions' => ['class' => 'col-lg-7 invalid-feedback'],
+ ],
+ ]); ?>
+
+ = $form->field($model, 'username')->textInput(['autofocus' => true]) ?>
+
+ = $form->field($model, 'password')->passwordInput() ?>
+
+ = $form->field($model, 'rememberMe')->checkbox([
+ 'template' => "
{input} {label}
\n
{error}
",
+ ]) ?>
+
+
+
+
+
+
+ You may login with admin/admin or demo/demo.
+ To modify the username/password, please check out the code app\models\User::$users
.
+
+
+
+
+
diff --git a/vue3/.gitignore b/vue3/.gitignore
new file mode 100644
index 0000000..a547bf3
--- /dev/null
+++ b/vue3/.gitignore
@@ -0,0 +1,24 @@
+# Logs
+logs
+*.log
+npm-debug.log*
+yarn-debug.log*
+yarn-error.log*
+pnpm-debug.log*
+lerna-debug.log*
+
+node_modules
+dist
+dist-ssr
+*.local
+
+# Editor directories and files
+.vscode/*
+!.vscode/extensions.json
+.idea
+.DS_Store
+*.suo
+*.ntvs*
+*.njsproj
+*.sln
+*.sw?
diff --git a/vue3/.vscode/extensions.json b/vue3/.vscode/extensions.json
new file mode 100644
index 0000000..c0a6e5a
--- /dev/null
+++ b/vue3/.vscode/extensions.json
@@ -0,0 +1,3 @@
+{
+ "recommendations": ["Vue.volar", "Vue.vscode-typescript-vue-plugin"]
+}
diff --git a/vue3/README.md b/vue3/README.md
new file mode 100644
index 0000000..e62e093
--- /dev/null
+++ b/vue3/README.md
@@ -0,0 +1,7 @@
+# Vue 3 + Vite
+
+This template should help get you started developing with Vue 3 in Vite. The template uses Vue 3 `
+