├── api
├── models
│ └── .gitkeep
├── config
│ ├── bootstrap.php
│ ├── .gitignore
│ ├── params.php
│ └── main.php
├── runtime
│ └── .gitignore
├── web
│ ├── .gitignore
│ ├── robots.txt
│ ├── favicon.ico
│ └── .htaccess
└── modules
│ └── v1
│ ├── Module.php
│ └── controllers
│ └── DefaultController.php
├── console
├── controllers
│ └── .gitkeep
├── models
│ └── .gitkeep
├── config
│ ├── bootstrap.php
│ ├── .gitignore
│ ├── params.php
│ └── main.php
├── runtime
│ └── .gitignore
└── migrations
│ └── m130524_201442_init.php
├── backend
├── models
│ └── .gitkeep
├── config
│ ├── bootstrap.php
│ ├── .gitignore
│ ├── params.php
│ └── main.php
├── runtime
│ └── .gitignore
├── web
│ ├── assets
│ │ └── .gitignore
│ ├── .gitignore
│ ├── robots.txt
│ ├── favicon.ico
│ ├── .htaccess
│ └── css
│ │ └── site.css
├── views
│ ├── site
│ │ ├── error.php
│ │ ├── login.php
│ │ └── index.php
│ └── layouts
│ │ └── main.php
├── assets
│ └── AppAsset.php
└── controllers
│ └── SiteController.php
├── frontend
├── config
│ ├── bootstrap.php
│ ├── .gitignore
│ ├── params.php
│ └── main.php
├── runtime
│ └── .gitignore
├── web
│ ├── assets
│ │ └── .gitignore
│ ├── robots.txt
│ ├── .gitignore
│ ├── favicon.ico
│ ├── .htaccess
│ └── css
│ │ └── site.css
├── views
│ ├── site
│ │ ├── about.php
│ │ ├── error.php
│ │ ├── resetPassword.php
│ │ ├── requestPasswordResetToken.php
│ │ ├── signup.php
│ │ ├── login.php
│ │ ├── contact.php
│ │ └── index.php
│ └── layouts
│ │ └── main.php
├── assets
│ └── AppAsset.php
├── models
│ ├── ContactForm.php
│ ├── SignupForm.php
│ ├── ResetPasswordForm.php
│ └── PasswordResetRequestForm.php
├── widgets
│ └── Alert.php
└── controllers
│ └── SiteController.php
├── tests
├── codeception
│ ├── api
│ │ ├── unit
│ │ │ ├── fixtures
│ │ │ │ └── data
│ │ │ │ │ └── .gitkeep
│ │ │ ├── _bootstrap.php
│ │ │ ├── TestCase.php
│ │ │ └── DbTestCase.php
│ │ ├── _output
│ │ │ └── .gitignore
│ │ ├── acceptance
│ │ │ ├── _bootstrap.php
│ │ │ └── LoginCept.php
│ │ ├── functional
│ │ │ ├── _bootstrap.php
│ │ │ └── LoginCept.php
│ │ ├── .gitignore
│ │ ├── unit.suite.yml
│ │ ├── codeception.yml
│ │ ├── functional.suite.yml
│ │ ├── acceptance.suite.yml
│ │ └── _bootstrap.php
│ ├── backend
│ │ ├── unit
│ │ │ ├── fixtures
│ │ │ │ └── data
│ │ │ │ │ └── .gitkeep
│ │ │ ├── _bootstrap.php
│ │ │ ├── TestCase.php
│ │ │ └── DbTestCase.php
│ │ ├── _output
│ │ │ └── .gitignore
│ │ ├── acceptance
│ │ │ ├── _bootstrap.php
│ │ │ └── LoginCept.php
│ │ ├── functional
│ │ │ ├── _bootstrap.php
│ │ │ └── LoginCept.php
│ │ ├── .gitignore
│ │ ├── unit.suite.yml
│ │ ├── codeception.yml
│ │ ├── functional.suite.yml
│ │ ├── acceptance.suite.yml
│ │ └── _bootstrap.php
│ ├── console
│ │ ├── unit
│ │ │ ├── fixtures
│ │ │ │ └── data
│ │ │ │ │ └── .gitkeep
│ │ │ ├── _bootstrap.php
│ │ │ ├── TestCase.php
│ │ │ └── DbTestCase.php
│ │ ├── _output
│ │ │ └── .gitignore
│ │ ├── .gitignore
│ │ ├── unit.suite.yml
│ │ ├── codeception.yml
│ │ └── _bootstrap.php
│ ├── _output
│ │ └── .gitignore
│ ├── common
│ │ ├── _output
│ │ │ └── .gitignore
│ │ ├── unit
│ │ │ ├── _bootstrap.php
│ │ │ ├── TestCase.php
│ │ │ ├── DbTestCase.php
│ │ │ ├── fixtures
│ │ │ │ └── data
│ │ │ │ │ └── models
│ │ │ │ │ └── user.php
│ │ │ └── models
│ │ │ │ └── LoginFormTest.php
│ │ ├── .gitignore
│ │ ├── unit.suite.yml
│ │ ├── fixtures
│ │ │ ├── UserFixture.php
│ │ │ └── data
│ │ │ │ └── init_login.php
│ │ ├── codeception.yml
│ │ ├── templates
│ │ │ └── fixtures
│ │ │ │ └── user.php
│ │ ├── _bootstrap.php
│ │ ├── _pages
│ │ │ └── LoginPage.php
│ │ └── _support
│ │ │ └── FixtureHelper.php
│ ├── frontend
│ │ ├── _output
│ │ │ └── .gitignore
│ │ ├── unit
│ │ │ ├── _bootstrap.php
│ │ │ ├── TestCase.php
│ │ │ ├── DbTestCase.php
│ │ │ ├── fixtures
│ │ │ │ └── data
│ │ │ │ │ └── models
│ │ │ │ │ └── user.php
│ │ │ └── models
│ │ │ │ ├── ResetPasswordFormTest.php
│ │ │ │ ├── SignupFormTest.php
│ │ │ │ ├── ContactFormTest.php
│ │ │ │ └── PasswordResetRequestFormTest.php
│ │ ├── acceptance
│ │ │ ├── _bootstrap.php
│ │ │ ├── AboutCept.php
│ │ │ ├── HomeCept.php
│ │ │ ├── LoginCept.php
│ │ │ ├── ContactCept.php
│ │ │ └── SignupCest.php
│ │ ├── functional
│ │ │ ├── _bootstrap.php
│ │ │ ├── AboutCept.php
│ │ │ ├── HomeCept.php
│ │ │ ├── LoginCept.php
│ │ │ ├── ContactCept.php
│ │ │ └── SignupCest.php
│ │ ├── .gitignore
│ │ ├── unit.suite.yml
│ │ ├── _pages
│ │ │ ├── AboutPage.php
│ │ │ ├── ContactPage.php
│ │ │ └── SignupPage.php
│ │ ├── codeception.yml
│ │ ├── functional.suite.yml
│ │ ├── acceptance.suite.yml
│ │ └── _bootstrap.php
│ ├── config
│ │ ├── backend
│ │ │ ├── config.php
│ │ │ ├── unit.php
│ │ │ ├── acceptance.php
│ │ │ └── functional.php
│ │ ├── frontend
│ │ │ ├── config.php
│ │ │ ├── unit.php
│ │ │ ├── functional.php
│ │ │ └── acceptance.php
│ │ ├── unit.php
│ │ ├── acceptance.php
│ │ ├── common
│ │ │ └── unit.php
│ │ ├── console
│ │ │ └── unit.php
│ │ ├── functional.php
│ │ └── config.php
│ └── bin
│ │ ├── yii.bat
│ │ ├── yii
│ │ └── _bootstrap.php
├── codeception.yml
└── README.md
├── .bowerrc
├── common
├── config
│ ├── .gitignore
│ ├── params.php
│ ├── bootstrap.php
│ └── main.php
├── mail
│ ├── passwordResetToken-text.php
│ ├── layouts
│ │ ├── text.php
│ │ └── html.php
│ └── passwordResetToken-html.php
└── models
│ ├── LoginForm.php
│ └── User.php
├── environments
├── prod
│ ├── api
│ │ ├── config
│ │ │ ├── main-local.php
│ │ │ └── params-local.php
│ │ └── web
│ │ │ └── index.php
│ ├── common
│ │ └── config
│ │ │ ├── params-local.php
│ │ │ └── main-local.php
│ ├── console
│ │ └── config
│ │ │ ├── main-local.php
│ │ │ └── params-local.php
│ ├── backend
│ │ ├── config
│ │ │ ├── params-local.php
│ │ │ └── main-local.php
│ │ └── web
│ │ │ └── index.php
│ ├── frontend
│ │ ├── config
│ │ │ ├── params-local.php
│ │ │ └── main-local.php
│ │ └── web
│ │ │ └── index.php
│ └── yii
├── dev
│ ├── api
│ │ ├── config
│ │ │ ├── params-local.php
│ │ │ └── main-local.php
│ │ └── web
│ │ │ ├── index.php
│ │ │ └── index-test.php
│ ├── backend
│ │ ├── config
│ │ │ ├── params-local.php
│ │ │ └── main-local.php
│ │ └── web
│ │ │ ├── index.php
│ │ │ └── index-test.php
│ ├── common
│ │ └── config
│ │ │ ├── params-local.php
│ │ │ └── main-local.php
│ ├── console
│ │ └── config
│ │ │ ├── params-local.php
│ │ │ └── main-local.php
│ ├── frontend
│ │ ├── config
│ │ │ ├── params-local.php
│ │ │ └── main-local.php
│ │ └── web
│ │ │ ├── index.php
│ │ │ └── index-test.php
│ └── yii
└── index.php
├── .gitignore
├── init.bat
├── yii.bat
├── composer.json
├── LICENSE.md
├── README.md
├── requirements.php
└── init
/api/models/.gitkeep:
--------------------------------------------------------------------------------
1 | *
2 |
--------------------------------------------------------------------------------
/console/controllers/.gitkeep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/backend/models/.gitkeep:
--------------------------------------------------------------------------------
1 | *
2 |
--------------------------------------------------------------------------------
/console/models/.gitkeep:
--------------------------------------------------------------------------------
1 | *
2 |
--------------------------------------------------------------------------------
/api/config/bootstrap.php:
--------------------------------------------------------------------------------
1 | 'admin@example.com',
4 | ];
5 |
--------------------------------------------------------------------------------
/backend/config/params.php:
--------------------------------------------------------------------------------
1 | 'admin@example.com',
4 | ];
5 |
--------------------------------------------------------------------------------
/console/config/params.php:
--------------------------------------------------------------------------------
1 | 'admin@example.com',
4 | ];
5 |
--------------------------------------------------------------------------------
/frontend/config/params.php:
--------------------------------------------------------------------------------
1 | 'admin@example.com',
4 | ];
5 |
--------------------------------------------------------------------------------
/api/web/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/desenvolvedorindie/yii2-app-api/HEAD/api/web/favicon.ico
--------------------------------------------------------------------------------
/backend/web/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/desenvolvedorindie/yii2-app-api/HEAD/backend/web/favicon.ico
--------------------------------------------------------------------------------
/frontend/web/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/desenvolvedorindie/yii2-app-api/HEAD/frontend/web/favicon.ico
--------------------------------------------------------------------------------
/tests/codeception/api/unit/_bootstrap.php:
--------------------------------------------------------------------------------
1 | ['gii'],
4 | 'modules' => [
5 | 'gii' => 'yii\gii\Module',
6 | ],
7 | ];
8 |
--------------------------------------------------------------------------------
/tests/codeception/api/.gitignore:
--------------------------------------------------------------------------------
1 | # these files are auto generated by codeception build
2 | /unit/UnitTester.php
3 | /functional/FunctionalTester.php
4 | /acceptance/AcceptanceTester.php
5 |
--------------------------------------------------------------------------------
/tests/codeception/backend/.gitignore:
--------------------------------------------------------------------------------
1 | # these files are auto generated by codeception build
2 | /unit/UnitTester.php
3 | /functional/FunctionalTester.php
4 | /acceptance/AcceptanceTester.php
5 |
--------------------------------------------------------------------------------
/tests/codeception/common/.gitignore:
--------------------------------------------------------------------------------
1 | # these files are auto generated by codeception build
2 | /unit/UnitTester.php
3 | /functional/FunctionalTester.php
4 | /acceptance/AcceptanceTester.php
5 |
--------------------------------------------------------------------------------
/common/config/params.php:
--------------------------------------------------------------------------------
1 | 'admin@example.com',
4 | 'supportEmail' => 'support@example.com',
5 | 'user.passwordResetTokenExpire' => 3600,
6 | ];
7 |
--------------------------------------------------------------------------------
/tests/codeception/frontend/.gitignore:
--------------------------------------------------------------------------------
1 | # these files are auto generated by codeception build
2 | /unit/UnitTester.php
3 | /functional/FunctionalTester.php
4 | /acceptance/AcceptanceTester.php
5 |
--------------------------------------------------------------------------------
/tests/codeception/api/acceptance/LoginCept.php:
--------------------------------------------------------------------------------
1 | [
4 | 'request' => [
5 | // !!! insert a secret key in the following (if it is empty) - this is required by cookie validation
6 | 'cookieValidationKey' => '',
7 | ],
8 | ],
9 | ];
10 |
--------------------------------------------------------------------------------
/environments/prod/frontend/config/main-local.php:
--------------------------------------------------------------------------------
1 | [
4 | 'request' => [
5 | // !!! insert a secret key in the following (if it is empty) - this is required by cookie validation
6 | 'cookieValidationKey' => '',
7 | ],
8 | ],
9 | ];
10 |
--------------------------------------------------------------------------------
/api/modules/v1/Module.php:
--------------------------------------------------------------------------------
1 | wantTo('ensure that about works');
9 | AboutPage::openBy($I);
10 | $I->see('About', 'h1');
11 |
--------------------------------------------------------------------------------
/tests/codeception/frontend/functional/AboutCept.php:
--------------------------------------------------------------------------------
1 | wantTo('ensure that about works');
9 | AboutPage::openBy($I);
10 | $I->see('About', 'h1');
11 |
--------------------------------------------------------------------------------
/common/mail/passwordResetToken-text.php:
--------------------------------------------------------------------------------
1 | urlManager->createAbsoluteUrl(['site/reset-password', 'token' => $user->password_reset_token]);
7 | ?>
8 | Hello = $user->username ?>,
9 |
10 | Follow the link below to reset your password:
11 |
12 | = $resetLink ?>
13 |
--------------------------------------------------------------------------------
/common/config/main.php:
--------------------------------------------------------------------------------
1 | dirname(dirname(__DIR__)) . '/vendor',
5 | 'components' => [
6 | 'cache' => [
7 | 'class' => 'yii\caching\FileCache',
8 | ],
9 | 'urlManager' => [
10 | 'enablePrettyUrl' => true,
11 | 'showScriptName' => false,
12 | ],
13 | ],
14 | ];
15 |
--------------------------------------------------------------------------------
/api/modules/v1/controllers/DefaultController.php:
--------------------------------------------------------------------------------
1 |
8 | beginPage() ?>
9 | beginBody() ?>
10 | = $content ?>
11 | endBody() ?>
12 | endPage() ?>
13 |
--------------------------------------------------------------------------------
/tests/codeception/frontend/acceptance/HomeCept.php:
--------------------------------------------------------------------------------
1 | wantTo('ensure that home page works');
8 | $I->amOnPage(Yii::$app->homeUrl);
9 | $I->see('My Company');
10 | $I->seeLink('About');
11 | $I->click('About');
12 | $I->see('This is the About page.');
13 |
--------------------------------------------------------------------------------
/tests/codeception/frontend/functional/HomeCept.php:
--------------------------------------------------------------------------------
1 | wantTo('ensure that home page works');
8 | $I->amOnPage(Yii::$app->homeUrl);
9 | $I->see('My Company');
10 | $I->seeLink('About');
11 | $I->click('About');
12 | $I->see('This is the About page.');
13 |
--------------------------------------------------------------------------------
/frontend/views/site/about.php:
--------------------------------------------------------------------------------
1 | title = 'About';
6 | $this->params['breadcrumbs'][] = $this->title;
7 | ?>
8 |
9 |
= Html::encode($this->title) ?>
10 |
11 |
This is the About page. You may modify the following file to customize its content:
12 |
13 |
= __FILE__ ?>
14 |
15 |
--------------------------------------------------------------------------------
/environments/dev/api/config/main-local.php:
--------------------------------------------------------------------------------
1 | [
5 | 'request' => [
6 | 'enableCookieValidation' => false,
7 | 'enableCsrfValidation' => false,
8 | ],
9 | ],
10 | ];
11 |
12 | if (!YII_ENV_TEST) {
13 | // configuration adjustments for 'dev' environment
14 | $config['bootstrap'][] = 'debug';
15 | $config['modules']['debug'] = 'yii\debug\Module';
16 | }
17 |
18 | return $config;
19 |
--------------------------------------------------------------------------------
/tests/codeception/config/common/unit.php:
--------------------------------------------------------------------------------
1 | 'app-common',
12 | 'basePath' => dirname(__DIR__),
13 | ]
14 | );
15 |
--------------------------------------------------------------------------------
/environments/prod/common/config/main-local.php:
--------------------------------------------------------------------------------
1 | [
4 | 'db' => [
5 | 'class' => 'yii\db\Connection',
6 | 'dsn' => 'mysql:host=localhost;dbname=yii2advanced',
7 | 'username' => 'root',
8 | 'password' => '',
9 | 'charset' => 'utf8',
10 | ],
11 | 'mailer' => [
12 | 'class' => 'yii\swiftmailer\Mailer',
13 | 'viewPath' => '@common/mail',
14 | ],
15 | ],
16 | ];
17 |
--------------------------------------------------------------------------------
/common/mail/passwordResetToken-html.php:
--------------------------------------------------------------------------------
1 | urlManager->createAbsoluteUrl(['site/reset-password', 'token' => $user->password_reset_token]);
8 | ?>
9 |
10 |
Hello = Html::encode($user->username) ?>,
11 |
12 |
Follow the link below to reset your password:
13 |
14 |
= Html::a(Html::encode($resetLink), $resetLink) ?>
15 |
16 |
--------------------------------------------------------------------------------
/tests/codeception/common/fixtures/data/init_login.php:
--------------------------------------------------------------------------------
1 | 'erau',
6 | 'auth_key' => 'tUu1qHcde0diwUol3xeI-18MuHkkprQI',
7 | // password_0
8 | 'password_hash' => '$2y$13$nJ1WDlBaGcbCdbNC5.5l4.sgy.OMEKCqtDQOdQ2OWpgiKRWYyzzne',
9 | 'password_reset_token' => 'RkD_Jw0_8HEedzLk7MM-ZKEFfYR7VbMr_1392559490',
10 | 'created_at' => '1392559490',
11 | 'updated_at' => '1392559490',
12 | 'email' => 'sfriesen@jenkins.info',
13 | ],
14 | ];
15 |
--------------------------------------------------------------------------------
/tests/codeception/common/unit/fixtures/data/models/user.php:
--------------------------------------------------------------------------------
1 | 'bayer.hudson',
6 | 'auth_key' => 'HP187Mvq7Mmm3CTU80dLkGmni_FUH_lR',
7 | //password_0
8 | 'password_hash' => '$2y$13$EjaPFBnZOQsHdGuHI.xvhuDp1fHpo8hKRSk6yshqa9c5EG8s3C3lO',
9 | 'password_reset_token' => 'ExzkCOaYc1L8IOBs4wdTGGbgNiG3Wz1I_1402312317',
10 | 'created_at' => '1402312317',
11 | 'updated_at' => '1402312317',
12 | 'email' => 'nicole.paucek@schultz.info',
13 | ],
14 | ];
15 |
--------------------------------------------------------------------------------
/tests/codeception/config/console/unit.php:
--------------------------------------------------------------------------------
1 | getSecurity();
8 |
9 | return [
10 | 'username' => $faker->userName,
11 | 'email' => $faker->email,
12 | 'auth_key' => $security->generateRandomString(),
13 | 'password_hash' => $security->generatePasswordHash('password_' . $index),
14 | 'password_reset_token' => $security->generateRandomString() . '_' . time(),
15 | 'created_at' => time(),
16 | 'updated_at' => time(),
17 | ];
18 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # yii console command
2 | /yii
3 |
4 | # phpstorm project files
5 | .idea
6 |
7 | # netbeans project files
8 | nbproject
9 |
10 | # zend studio for eclipse project files
11 | .buildpath
12 | .project
13 | .settings
14 |
15 | # windows thumbnail cache
16 | Thumbs.db
17 |
18 | # composer lock
19 | composer.lock
20 |
21 | # composer vendor dir
22 | /vendor
23 |
24 | # composer itself is not needed
25 | composer.phar
26 |
27 | # Mac DS_Store Files
28 | .DS_Store
29 |
30 | # phpunit itself is not needed
31 | phpunit.phar
32 | # local phpunit config
33 | /phpunit.xml
34 |
--------------------------------------------------------------------------------
/tests/codeception/api/functional.suite.yml:
--------------------------------------------------------------------------------
1 | # Codeception Test Suite Configuration
2 |
3 | # suite for functional (integration) tests.
4 | # emulate web requests and make application process them.
5 | # (tip: better to use with frameworks).
6 |
7 | # RUN `build` COMMAND AFTER ADDING/REMOVING MODULES.
8 | #basic/web/index.php
9 | class_name: FunctionalTester
10 | modules:
11 | enabled:
12 | - Filesystem
13 | - Yii2
14 | - tests\codeception\common\_support\FixtureHelper
15 | config:
16 | Yii2:
17 | configFile: '../config/api/functional.php'
18 |
--------------------------------------------------------------------------------
/tests/codeception/backend/codeception.yml:
--------------------------------------------------------------------------------
1 | namespace: tests\codeception\backend
2 | actor: Tester
3 | paths:
4 | tests: .
5 | log: _output
6 | data: _data
7 | helpers: _support
8 | settings:
9 | bootstrap: _bootstrap.php
10 | suite_class: \PHPUnit_Framework_TestSuite
11 | colors: true
12 | memory_limit: 1024M
13 | log: true
14 | config:
15 | # the entry script URL (with host info) for functional and acceptance tests
16 | # PLEASE ADJUST IT TO THE ACTUAL ENTRY SCRIPT URL
17 | test_entry_url: http://localhost:8080/backend/web/index-test.php
18 |
--------------------------------------------------------------------------------
/tests/codeception/frontend/codeception.yml:
--------------------------------------------------------------------------------
1 | namespace: tests\codeception\frontend
2 | actor: Tester
3 | paths:
4 | tests: .
5 | log: _output
6 | data: _data
7 | helpers: _support
8 | settings:
9 | bootstrap: _bootstrap.php
10 | suite_class: \PHPUnit_Framework_TestSuite
11 | colors: true
12 | memory_limit: 1024M
13 | log: true
14 | config:
15 | # the entry script URL (with host info) for functional and acceptance tests
16 | # PLEASE ADJUST IT TO THE ACTUAL ENTRY SCRIPT URL
17 | test_entry_url: http://localhost:8080/frontend/web/index-test.php
18 |
--------------------------------------------------------------------------------
/tests/codeception/backend/functional.suite.yml:
--------------------------------------------------------------------------------
1 | # Codeception Test Suite Configuration
2 |
3 | # suite for functional (integration) tests.
4 | # emulate web requests and make application process them.
5 | # (tip: better to use with frameworks).
6 |
7 | # RUN `build` COMMAND AFTER ADDING/REMOVING MODULES.
8 | #basic/web/index.php
9 | class_name: FunctionalTester
10 | modules:
11 | enabled:
12 | - Filesystem
13 | - Yii2
14 | - tests\codeception\common\_support\FixtureHelper
15 | config:
16 | Yii2:
17 | configFile: '../config/backend/functional.php'
18 |
--------------------------------------------------------------------------------
/tests/codeception/config/functional.php:
--------------------------------------------------------------------------------
1 | [
7 | 'request' => [
8 | // it's not recommended to run functional tests with CSRF validation enabled
9 | 'enableCsrfValidation' => false,
10 | // but if you absolutely need it set cookie domain to localhost
11 | /*
12 | 'csrfCookie' => [
13 | 'domain' => 'localhost',
14 | ],
15 | */
16 | ],
17 | ],
18 | ];
--------------------------------------------------------------------------------
/tests/codeception/frontend/functional.suite.yml:
--------------------------------------------------------------------------------
1 | # Codeception Test Suite Configuration
2 |
3 | # suite for functional (integration) tests.
4 | # emulate web requests and make application process them.
5 | # (tip: better to use with frameworks).
6 |
7 | # RUN `build` COMMAND AFTER ADDING/REMOVING MODULES.
8 | #basic/web/index.php
9 | class_name: FunctionalTester
10 | modules:
11 | enabled:
12 | - Filesystem
13 | - Yii2
14 | - tests\codeception\common\_support\FixtureHelper
15 | config:
16 | Yii2:
17 | configFile: '../config/frontend/functional.php'
18 |
--------------------------------------------------------------------------------
/init.bat:
--------------------------------------------------------------------------------
1 | @echo off
2 |
3 | rem -------------------------------------------------------------
4 | rem Yii command line init script for Windows.
5 | rem
6 | rem @author Qiang Xue
7 | rem @link http://www.yiiframework.com/
8 | rem @copyright Copyright (c) 2008 Yii Software LLC
9 | rem @license http://www.yiiframework.com/license/
10 | rem -------------------------------------------------------------
11 |
12 | @setlocal
13 |
14 | set YII_PATH=%~dp0
15 |
16 | if "%PHP_COMMAND%" == "" set PHP_COMMAND=php.exe
17 |
18 | "%PHP_COMMAND%" "%YII_PATH%init" %*
19 |
20 | @endlocal
21 |
--------------------------------------------------------------------------------
/yii.bat:
--------------------------------------------------------------------------------
1 | @echo off
2 |
3 | rem -------------------------------------------------------------
4 | rem Yii command line bootstrap script for Windows.
5 | rem
6 | rem @author Qiang Xue
7 | rem @link http://www.yiiframework.com/
8 | rem @copyright Copyright (c) 2008 Yii Software LLC
9 | rem @license http://www.yiiframework.com/license/
10 | rem -------------------------------------------------------------
11 |
12 | @setlocal
13 |
14 | set YII_PATH=%~dp0
15 |
16 | if "%PHP_COMMAND%" == "" set PHP_COMMAND=php.exe
17 |
18 | "%PHP_COMMAND%" "%YII_PATH%yii" %*
19 |
20 | @endlocal
21 |
--------------------------------------------------------------------------------
/tests/codeception/config/backend/unit.php:
--------------------------------------------------------------------------------
1 |
7 | rem @link http://www.yiiframework.com/
8 | rem @copyright Copyright (c) 2008 Yii Software LLC
9 | rem @license http://www.yiiframework.com/license/
10 | rem -------------------------------------------------------------
11 |
12 | @setlocal
13 |
14 | set YII_PATH=%~dp0
15 |
16 | if "%PHP_COMMAND%" == "" set PHP_COMMAND=php.exe
17 |
18 | "%PHP_COMMAND%" "%YII_PATH%yii" %*
19 |
20 | @endlocal
21 |
--------------------------------------------------------------------------------
/tests/codeception/common/_bootstrap.php:
--------------------------------------------------------------------------------
1 | [
5 | 'request' => [
6 | // !!! insert a secret key in the following (if it is empty) - this is required by cookie validation
7 | 'cookieValidationKey' => '',
8 | ],
9 | ],
10 | ];
11 |
12 | if (!YII_ENV_TEST) {
13 | // configuration adjustments for 'dev' environment
14 | $config['bootstrap'][] = 'debug';
15 | $config['modules']['debug'] = 'yii\debug\Module';
16 |
17 | $config['bootstrap'][] = 'gii';
18 | $config['modules']['gii'] = 'yii\gii\Module';
19 | }
20 |
21 | return $config;
22 |
--------------------------------------------------------------------------------
/environments/dev/frontend/config/main-local.php:
--------------------------------------------------------------------------------
1 | [
5 | 'request' => [
6 | // !!! insert a secret key in the following (if it is empty) - this is required by cookie validation
7 | 'cookieValidationKey' => '',
8 | ],
9 | ],
10 | ];
11 |
12 | if (!YII_ENV_TEST) {
13 | // configuration adjustments for 'dev' environment
14 | $config['bootstrap'][] = 'debug';
15 | $config['modules']['debug'] = 'yii\debug\Module';
16 |
17 | $config['bootstrap'][] = 'gii';
18 | $config['modules']['gii'] = 'yii\gii\Module';
19 | }
20 |
21 | return $config;
22 |
--------------------------------------------------------------------------------
/backend/views/site/error.php:
--------------------------------------------------------------------------------
1 | title = $name;
11 | ?>
12 |
13 |
14 |
= Html::encode($this->title) ?>
15 |
16 |
17 | = nl2br(Html::encode($message)) ?>
18 |
19 |
20 |
21 | The above error occurred while the Web server was processing your request.
22 |
23 |
24 | Please contact us if you think this is a server error. Thank you.
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/frontend/views/site/error.php:
--------------------------------------------------------------------------------
1 | title = $name;
11 | ?>
12 |
13 |
14 |
= Html::encode($this->title) ?>
15 |
16 |
17 | = nl2br(Html::encode($message)) ?>
18 |
19 |
20 |
21 | The above error occurred while the Web server was processing your request.
22 |
23 |
24 | Please contact us if you think this is a server error. Thank you.
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/backend/assets/AppAsset.php:
--------------------------------------------------------------------------------
1 |
14 | * @since 2.0
15 | */
16 | class AppAsset extends AssetBundle
17 | {
18 | public $basePath = '@webroot';
19 | public $baseUrl = '@web';
20 | public $css = [
21 | 'css/site.css',
22 | ];
23 | public $js = [
24 | ];
25 | public $depends = [
26 | 'yii\web\YiiAsset',
27 | 'yii\bootstrap\BootstrapAsset',
28 | ];
29 | }
30 |
--------------------------------------------------------------------------------
/frontend/assets/AppAsset.php:
--------------------------------------------------------------------------------
1 |
14 | * @since 2.0
15 | */
16 | class AppAsset extends AssetBundle
17 | {
18 | public $basePath = '@webroot';
19 | public $baseUrl = '@web';
20 | public $css = [
21 | 'css/site.css',
22 | ];
23 | public $js = [
24 | ];
25 | public $depends = [
26 | 'yii\web\YiiAsset',
27 | 'yii\bootstrap\BootstrapAsset',
28 | ];
29 | }
30 |
--------------------------------------------------------------------------------
/tests/codeception/console/_bootstrap.php:
--------------------------------------------------------------------------------
1 | run();
19 |
--------------------------------------------------------------------------------
/environments/dev/api/web/index-test.php:
--------------------------------------------------------------------------------
1 | run();
20 |
--------------------------------------------------------------------------------
/environments/dev/backend/web/index.php:
--------------------------------------------------------------------------------
1 | run();
19 |
--------------------------------------------------------------------------------
/environments/dev/frontend/web/index.php:
--------------------------------------------------------------------------------
1 | run();
19 |
--------------------------------------------------------------------------------
/environments/prod/api/web/index.php:
--------------------------------------------------------------------------------
1 | run();
19 |
--------------------------------------------------------------------------------
/environments/dev/common/config/main-local.php:
--------------------------------------------------------------------------------
1 | [
4 | 'db' => [
5 | 'class' => 'yii\db\Connection',
6 | 'dsn' => 'mysql:host=localhost;dbname=yii2advanced',
7 | 'username' => 'root',
8 | 'password' => '',
9 | 'charset' => 'utf8',
10 | ],
11 | 'mailer' => [
12 | 'class' => 'yii\swiftmailer\Mailer',
13 | 'viewPath' => '@common/mail',
14 | // send all mails to a file by default. You have to set
15 | // 'useFileTransport' to false and configure a transport
16 | // for the mailer to send real emails.
17 | 'useFileTransport' => true,
18 | ],
19 | ],
20 | ];
21 |
--------------------------------------------------------------------------------
/environments/dev/frontend/web/index-test.php:
--------------------------------------------------------------------------------
1 | run();
19 |
--------------------------------------------------------------------------------
/environments/prod/backend/web/index.php:
--------------------------------------------------------------------------------
1 | run();
19 |
--------------------------------------------------------------------------------
/environments/prod/frontend/web/index.php:
--------------------------------------------------------------------------------
1 | run();
19 |
--------------------------------------------------------------------------------
/environments/dev/backend/web/index-test.php:
--------------------------------------------------------------------------------
1 | run();
20 |
--------------------------------------------------------------------------------
/console/config/main.php:
--------------------------------------------------------------------------------
1 | 'app-console',
11 | 'basePath' => dirname(__DIR__),
12 | 'bootstrap' => ['log'],
13 | 'controllerNamespace' => 'console\controllers',
14 | 'components' => [
15 | 'log' => [
16 | 'targets' => [
17 | [
18 | 'class' => 'yii\log\FileTarget',
19 | 'levels' => ['error', 'warning'],
20 | ],
21 | ],
22 | ],
23 | ],
24 | 'params' => $params,
25 | ];
26 |
--------------------------------------------------------------------------------
/tests/codeception/bin/yii:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env php
2 | run();
23 | exit($exitCode);
24 |
--------------------------------------------------------------------------------
/common/mail/layouts/html.php:
--------------------------------------------------------------------------------
1 |
8 | beginPage() ?>
9 |
10 |
11 |
12 |
13 | = Html::encode($this->title) ?>
14 | head() ?>
15 |
16 |
17 | beginBody() ?>
18 | = $content ?>
19 | endBody() ?>
20 |
21 |
22 | endPage() ?>
23 |
--------------------------------------------------------------------------------
/tests/codeception/frontend/_pages/ContactPage.php:
--------------------------------------------------------------------------------
1 | $value) {
21 | $inputType = $field === 'body' ? 'textarea' : 'input';
22 | $this->actor->fillField($inputType . '[name="ContactForm[' . $field . ']"]', $value);
23 | }
24 | $this->actor->click('contact-button');
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/tests/codeception/frontend/_pages/SignupPage.php:
--------------------------------------------------------------------------------
1 | $value) {
22 | $inputType = $field === 'body' ? 'textarea' : 'input';
23 | $this->actor->fillField($inputType . '[name="SignupForm[' . $field . ']"]', $value);
24 | }
25 | $this->actor->click('signup-button');
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/tests/codeception/common/_pages/LoginPage.php:
--------------------------------------------------------------------------------
1 | actor->fillField('input[name="LoginForm[username]"]', $username);
22 | $this->actor->fillField('input[name="LoginForm[password]"]', $password);
23 | $this->actor->click('login-button');
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/tests/codeception/config/config.php:
--------------------------------------------------------------------------------
1 | 'en-US',
7 | 'controllerMap' => [
8 | 'fixture' => [
9 | 'class' => 'yii\faker\FixtureController',
10 | 'fixtureDataPath' => '@tests/codeception/common/fixtures/data',
11 | 'templatePath' => '@tests/codeception/common/templates/fixtures',
12 | 'namespace' => 'tests\codeception\common\fixtures',
13 | ],
14 | ],
15 | 'components' => [
16 | 'db' => [
17 | 'dsn' => 'mysql:host=localhost;dbname=yii2_advanced_tests',
18 | ],
19 | 'mailer' => [
20 | 'useFileTransport' => true,
21 | ],
22 | 'urlManager' => [
23 | 'showScriptName' => true,
24 | ],
25 | ],
26 | ];
27 |
--------------------------------------------------------------------------------
/tests/codeception/bin/_bootstrap.php:
--------------------------------------------------------------------------------
1 | title = 'Reset password';
10 | $this->params['breadcrumbs'][] = $this->title;
11 | ?>
12 |
13 |
= Html::encode($this->title) ?>
14 |
15 |
Please choose your new password:
16 |
17 |
18 |
19 | 'reset-password-form']); ?>
20 | = $form->field($model, 'password')->passwordInput() ?>
21 |
22 | = Html::submitButton('Save', ['class' => 'btn btn-primary']) ?>
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/tests/codeception/frontend/unit/fixtures/data/models/user.php:
--------------------------------------------------------------------------------
1 | 'okirlin',
6 | 'auth_key' => 'iwTNae9t34OmnK6l4vT4IeaTk-YWI2Rv',
7 | 'password_hash' => '$2y$13$CXT0Rkle1EMJ/c1l5bylL.EylfmQ39O5JlHJVFpNn618OUS1HwaIi',
8 | 'password_reset_token' => 't5GU9NwpuGYSfb7FEZMAxqtuz2PkEvv_' . time(),
9 | 'created_at' => '1391885313',
10 | 'updated_at' => '1391885313',
11 | 'email' => 'brady.renner@rutherford.com',
12 | ],
13 | [
14 | 'username' => 'troy.becker',
15 | 'auth_key' => 'EdKfXrx88weFMV0vIxuTMWKgfK2tS3Lp',
16 | 'password_hash' => '$2y$13$g5nv41Px7VBqhS3hVsVN2.MKfgT3jFdkXEsMC4rQJLfaMa7VaJqL2',
17 | 'password_reset_token' => '4BSNyiZNAuxjs5Mty990c47sVrgllIi_' . time(),
18 | 'created_at' => '1391885313',
19 | 'updated_at' => '1391885313',
20 | 'email' => 'nicolas.dianna@hotmail.com',
21 | 'status' => '0',
22 | ],
23 | ];
24 |
--------------------------------------------------------------------------------
/frontend/views/site/requestPasswordResetToken.php:
--------------------------------------------------------------------------------
1 | title = 'Request password reset';
10 | $this->params['breadcrumbs'][] = $this->title;
11 | ?>
12 |
13 |
= Html::encode($this->title) ?>
14 |
15 |
Please fill out your email. A link to reset password will be sent there.
16 |
17 |
18 |
19 | 'request-password-reset-form']); ?>
20 | = $form->field($model, 'email') ?>
21 |
22 | = Html::submitButton('Send', ['class' => 'btn btn-primary']) ?>
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/frontend/config/main.php:
--------------------------------------------------------------------------------
1 | 'app-frontend',
11 | 'basePath' => dirname(__DIR__),
12 | 'bootstrap' => ['log'],
13 | 'controllerNamespace' => 'frontend\controllers',
14 | 'components' => [
15 | 'user' => [
16 | 'identityClass' => 'common\models\User',
17 | 'enableAutoLogin' => true,
18 | ],
19 | 'log' => [
20 | 'traceLevel' => YII_DEBUG ? 3 : 0,
21 | 'targets' => [
22 | [
23 | 'class' => 'yii\log\FileTarget',
24 | 'levels' => ['error', 'warning'],
25 | ],
26 | ],
27 | ],
28 | 'errorHandler' => [
29 | 'errorAction' => 'site/error',
30 | ],
31 | ],
32 | 'params' => $params,
33 | ];
34 |
--------------------------------------------------------------------------------
/frontend/views/site/signup.php:
--------------------------------------------------------------------------------
1 | title = 'Signup';
10 | $this->params['breadcrumbs'][] = $this->title;
11 | ?>
12 |
13 |
= Html::encode($this->title) ?>
14 |
15 |
Please fill out the following fields to signup:
16 |
17 |
18 |
19 | 'form-signup']); ?>
20 | = $form->field($model, 'username') ?>
21 | = $form->field($model, 'email') ?>
22 | = $form->field($model, 'password')->passwordInput() ?>
23 |
24 | = Html::submitButton('Signup', ['class' => 'btn btn-primary', 'name' => 'signup-button']) ?>
25 |
26 |
27 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/backend/config/main.php:
--------------------------------------------------------------------------------
1 | 'app-backend',
11 | 'basePath' => dirname(__DIR__),
12 | 'controllerNamespace' => 'backend\controllers',
13 | 'bootstrap' => ['log'],
14 | 'modules' => [],
15 | 'components' => [
16 | 'user' => [
17 | 'identityClass' => 'common\models\User',
18 | 'enableAutoLogin' => true,
19 | ],
20 | 'log' => [
21 | 'traceLevel' => YII_DEBUG ? 3 : 0,
22 | 'targets' => [
23 | [
24 | 'class' => 'yii\log\FileTarget',
25 | 'levels' => ['error', 'warning'],
26 | ],
27 | ],
28 | ],
29 | 'errorHandler' => [
30 | 'errorAction' => 'site/error',
31 | ],
32 | ],
33 | 'params' => $params,
34 | ];
35 |
--------------------------------------------------------------------------------
/backend/views/site/login.php:
--------------------------------------------------------------------------------
1 | title = 'Login';
10 | $this->params['breadcrumbs'][] = $this->title;
11 | ?>
12 |
13 |
= Html::encode($this->title) ?>
14 |
15 |
Please fill out the following fields to login:
16 |
17 |
18 |
19 | 'login-form']); ?>
20 | = $form->field($model, 'username') ?>
21 | = $form->field($model, 'password')->passwordInput() ?>
22 | = $form->field($model, 'rememberMe')->checkbox() ?>
23 |
24 | = Html::submitButton('Login', ['class' => 'btn btn-primary', 'name' => 'login-button']) ?>
25 |
26 |
27 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/tests/codeception/frontend/functional/LoginCept.php:
--------------------------------------------------------------------------------
1 | wantTo('ensure login page works');
9 |
10 | $loginPage = LoginPage::openBy($I);
11 |
12 | $I->amGoingTo('submit login form with no data');
13 | $loginPage->login('', '');
14 | $I->expectTo('see validations errors');
15 | $I->see('Username cannot be blank.', '.help-block');
16 | $I->see('Password cannot be blank.', '.help-block');
17 |
18 | $I->amGoingTo('try to login with wrong credentials');
19 | $I->expectTo('see validations errors');
20 | $loginPage->login('admin', 'wrong');
21 | $I->expectTo('see validations errors');
22 | $I->see('Incorrect username or password.', '.help-block');
23 |
24 | $I->amGoingTo('try to login with correct credentials');
25 | $loginPage->login('erau', 'password_0');
26 | $I->expectTo('see that user is logged');
27 | $I->seeLink('Logout (erau)');
28 | $I->dontSeeLink('Login');
29 | $I->dontSeeLink('Signup');
30 |
--------------------------------------------------------------------------------
/tests/codeception/backend/functional/LoginCept.php:
--------------------------------------------------------------------------------
1 | wantTo('ensure login page works');
10 |
11 | $loginPage = LoginPage::openBy($I);
12 |
13 | $I->amGoingTo('submit login form with no data');
14 | $loginPage->login('', '');
15 | $I->expectTo('see validations errors');
16 | $I->see('Username cannot be blank.', '.help-block');
17 | $I->see('Password cannot be blank.', '.help-block');
18 |
19 | $I->amGoingTo('try to login with wrong credentials');
20 | $I->expectTo('see validations errors');
21 | $loginPage->login('admin', 'wrong');
22 | $I->expectTo('see validations errors');
23 | $I->see('Incorrect username or password.', '.help-block');
24 |
25 | $I->amGoingTo('try to login with correct credentials');
26 | $loginPage->login('erau', 'password_0');
27 | $I->expectTo('see that user is logged');
28 | $I->seeLink('Logout (erau)');
29 | $I->dontSeeLink('Login');
30 | $I->dontSeeLink('Signup');
31 |
--------------------------------------------------------------------------------
/environments/dev/yii:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env php
2 | run();
32 | exit($exitCode);
33 |
--------------------------------------------------------------------------------
/environments/prod/yii:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env php
2 | run();
32 | exit($exitCode);
33 |
--------------------------------------------------------------------------------
/tests/codeception/api/acceptance.suite.yml:
--------------------------------------------------------------------------------
1 | # Codeception Test Suite Configuration
2 |
3 | # suite for acceptance tests.
4 | # perform tests in browser using the Selenium-like tools.
5 | # powered by Mink (http://mink.behat.org).
6 | # (tip: that's what your customer will see).
7 | # (tip: test your ajax and javascript by one of Mink drivers).
8 |
9 | # RUN `build` COMMAND AFTER ADDING/REMOVING MODULES.
10 |
11 | class_name: AcceptanceTester
12 | modules:
13 | enabled:
14 | - PhpBrowser
15 | - tests\codeception\common\_support\FixtureHelper
16 | # you can use WebDriver instead of PhpBrowser to test javascript and ajax.
17 | # This will require you to install selenium. See http://codeception.com/docs/04-AcceptanceTests#Selenium
18 | # "restart" option is used by the WebDriver to start each time per test-file new session and cookies,
19 | # it is useful if you want to login in your app in each test.
20 | # - WebDriver
21 | config:
22 | PhpBrowser:
23 | # PLEASE ADJUST IT TO THE ACTUAL ENTRY POINT WITHOUT PATH INFO
24 | url: http://localhost:8080
25 | # WebDriver:
26 | # url: http://localhost:8080
27 | # browser: firefox
28 | # restart: true
29 |
--------------------------------------------------------------------------------
/tests/codeception/backend/acceptance.suite.yml:
--------------------------------------------------------------------------------
1 | # Codeception Test Suite Configuration
2 |
3 | # suite for acceptance tests.
4 | # perform tests in browser using the Selenium-like tools.
5 | # powered by Mink (http://mink.behat.org).
6 | # (tip: that's what your customer will see).
7 | # (tip: test your ajax and javascript by one of Mink drivers).
8 |
9 | # RUN `build` COMMAND AFTER ADDING/REMOVING MODULES.
10 |
11 | class_name: AcceptanceTester
12 | modules:
13 | enabled:
14 | - PhpBrowser
15 | - tests\codeception\common\_support\FixtureHelper
16 | # you can use WebDriver instead of PhpBrowser to test javascript and ajax.
17 | # This will require you to install selenium. See http://codeception.com/docs/04-AcceptanceTests#Selenium
18 | # "restart" option is used by the WebDriver to start each time per test-file new session and cookies,
19 | # it is useful if you want to login in your app in each test.
20 | # - WebDriver
21 | config:
22 | PhpBrowser:
23 | # PLEASE ADJUST IT TO THE ACTUAL ENTRY POINT WITHOUT PATH INFO
24 | url: http://localhost:8080
25 | # WebDriver:
26 | # url: http://localhost:8080
27 | # browser: firefox
28 | # restart: true
29 |
--------------------------------------------------------------------------------
/tests/codeception/frontend/acceptance.suite.yml:
--------------------------------------------------------------------------------
1 | # Codeception Test Suite Configuration
2 |
3 | # suite for acceptance tests.
4 | # perform tests in browser using the Selenium-like tools.
5 | # powered by Mink (http://mink.behat.org).
6 | # (tip: that's what your customer will see).
7 | # (tip: test your ajax and javascript by one of Mink drivers).
8 |
9 | # RUN `build` COMMAND AFTER ADDING/REMOVING MODULES.
10 |
11 | class_name: AcceptanceTester
12 | modules:
13 | enabled:
14 | - PhpBrowser
15 | - tests\codeception\common\_support\FixtureHelper
16 | # you can use WebDriver instead of PhpBrowser to test javascript and ajax.
17 | # This will require you to install selenium. See http://codeception.com/docs/04-AcceptanceTests#Selenium
18 | # "restart" option is used by the WebDriver to start each time per test-file new session and cookies,
19 | # it is useful if you want to login in your app in each test.
20 | # - WebDriver
21 | config:
22 | PhpBrowser:
23 | # PLEASE ADJUST IT TO THE ACTUAL ENTRY POINT WITHOUT PATH INFO
24 | url: http://localhost:8080
25 | # WebDriver:
26 | # url: http://localhost:8080
27 | # browser: firefox
28 | # restart: true
29 |
--------------------------------------------------------------------------------
/tests/codeception/frontend/acceptance/LoginCept.php:
--------------------------------------------------------------------------------
1 | wantTo('ensure login page works');
9 |
10 | $loginPage = LoginPage::openBy($I);
11 |
12 | $I->amGoingTo('submit login form with no data');
13 | $loginPage->login('', '');
14 | $I->expectTo('see validations errors');
15 | $I->see('Username cannot be blank.', '.help-block');
16 | $I->see('Password cannot be blank.', '.help-block');
17 |
18 | $I->amGoingTo('try to login with wrong credentials');
19 | $I->expectTo('see validations errors');
20 | $loginPage->login('admin', 'wrong');
21 | $I->expectTo('see validations errors');
22 | $I->see('Incorrect username or password.', '.help-block');
23 |
24 | $I->amGoingTo('try to login with correct credentials');
25 | $loginPage->login('erau', 'password_0');
26 | $I->expectTo('see that user is logged');
27 | $I->seeLink('Logout (erau)');
28 | $I->dontSeeLink('Login');
29 | $I->dontSeeLink('Signup');
30 | /** Uncomment if using WebDriver
31 | * $I->click('Logout (erau)');
32 | * $I->dontSeeLink('Logout (erau)');
33 | * $I->seeLink('Login');
34 | */
35 |
--------------------------------------------------------------------------------
/frontend/views/site/login.php:
--------------------------------------------------------------------------------
1 | title = 'Login';
10 | $this->params['breadcrumbs'][] = $this->title;
11 | ?>
12 |
13 |
= Html::encode($this->title) ?>
14 |
15 |
Please fill out the following fields to login:
16 |
17 |
18 |
19 | 'login-form']); ?>
20 | = $form->field($model, 'username') ?>
21 | = $form->field($model, 'password')->passwordInput() ?>
22 | = $form->field($model, 'rememberMe')->checkbox() ?>
23 |
24 | If you forgot your password you can = Html::a('reset it', ['site/request-password-reset']) ?>.
25 |
26 |
27 | = Html::submitButton('Login', ['class' => 'btn btn-primary', 'name' => 'login-button']) ?>
28 |
29 |
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/tests/codeception/frontend/unit/models/ResetPasswordFormTest.php:
--------------------------------------------------------------------------------
1 | user[0]['password_reset_token']);
31 | expect('password should be resetted', $form->resetPassword())->true();
32 | }
33 |
34 | public function fixtures()
35 | {
36 | return [
37 | 'user' => [
38 | 'class' => UserFixture::className(),
39 | 'dataFile' => '@tests/codeception/frontend/unit/fixtures/data/models/user.php'
40 | ],
41 | ];
42 | }
43 |
44 | }
45 |
--------------------------------------------------------------------------------
/console/migrations/m130524_201442_init.php:
--------------------------------------------------------------------------------
1 | db->driverName === 'mysql') {
12 | // http://stackoverflow.com/questions/766809/whats-the-difference-between-utf8-general-ci-and-utf8-unicode-ci
13 | $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB';
14 | }
15 |
16 | $this->createTable('{{%user}}', [
17 | 'id' => Schema::TYPE_PK,
18 | 'username' => Schema::TYPE_STRING . ' NOT NULL UNIQUE',
19 | 'auth_key' => Schema::TYPE_STRING . '(32) NOT NULL',
20 | 'password_hash' => Schema::TYPE_STRING . ' NOT NULL',
21 | 'password_reset_token' => Schema::TYPE_STRING . ' UNIQUE',
22 | 'email' => Schema::TYPE_STRING . ' NOT NULL UNIQUE',
23 |
24 | 'status' => Schema::TYPE_SMALLINT . ' NOT NULL DEFAULT 10',
25 | 'created_at' => Schema::TYPE_INTEGER . ' NOT NULL',
26 | 'updated_at' => Schema::TYPE_INTEGER . ' NOT NULL',
27 | ], $tableOptions);
28 | }
29 |
30 | public function down()
31 | {
32 | $this->dropTable('{{%user}}');
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/tests/codeception/frontend/_bootstrap.php:
--------------------------------------------------------------------------------
1 | wantTo('ensure login page works');
10 |
11 | $loginPage = LoginPage::openBy($I);
12 |
13 | $I->amGoingTo('submit login form with no data');
14 | $loginPage->login('', '');
15 | if (method_exists($I, 'wait')) {
16 | $I->wait(3); // only for selenium
17 | }
18 | $I->expectTo('see validations errors');
19 | $I->see('Username cannot be blank.', '.help-block');
20 | $I->see('Password cannot be blank.', '.help-block');
21 |
22 | $I->amGoingTo('try to login with wrong credentials');
23 | $I->expectTo('see validations errors');
24 | $loginPage->login('admin', 'wrong');
25 | if (method_exists($I, 'wait')) {
26 | $I->wait(3); // only for selenium
27 | }
28 | $I->expectTo('see validations errors');
29 | $I->see('Incorrect username or password.', '.help-block');
30 |
31 | $I->amGoingTo('try to login with correct credentials');
32 | $loginPage->login('erau', 'password_0');
33 | if (method_exists($I, 'wait')) {
34 | $I->wait(3); // only for selenium
35 | }
36 | $I->expectTo('see that user is logged');
37 | $I->seeLink('Logout (erau)');
38 | $I->dontSeeLink('Login');
39 | $I->dontSeeLink('Signup');
40 | /** Uncomment if using WebDriver
41 | * $I->click('Logout (erau)');
42 | * $I->dontSeeLink('Logout (erau)');
43 | * $I->seeLink('Login');
44 | */
45 |
--------------------------------------------------------------------------------
/frontend/views/site/contact.php:
--------------------------------------------------------------------------------
1 | title = 'Contact';
11 | $this->params['breadcrumbs'][] = $this->title;
12 | ?>
13 |
38 |
--------------------------------------------------------------------------------
/frontend/models/ContactForm.php:
--------------------------------------------------------------------------------
1 | 'Verification Code',
41 | ];
42 | }
43 |
44 | /**
45 | * Sends an email to the specified email address using the information collected by this model.
46 | *
47 | * @param string $email the target email address
48 | * @return boolean whether the email was sent
49 | */
50 | public function sendEmail($email)
51 | {
52 | return Yii::$app->mailer->compose()
53 | ->setTo($email)
54 | ->setFrom([$this->email => $this->name])
55 | ->setSubject($this->subject)
56 | ->setTextBody($this->body)
57 | ->send();
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/composer.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "yiisoft/yii2-app-advanced",
3 | "description": "Yii 2 Advanced Project Template",
4 | "keywords": ["yii2", "framework", "advanced", "project template"],
5 | "homepage": "http://www.yiiframework.com/",
6 | "type": "project",
7 | "license": "BSD-3-Clause",
8 | "support": {
9 | "issues": "https://github.com/yiisoft/yii2/issues?state=open",
10 | "forum": "http://www.yiiframework.com/forum/",
11 | "wiki": "http://www.yiiframework.com/wiki/",
12 | "irc": "irc://irc.freenode.net/yii",
13 | "source": "https://github.com/yiisoft/yii2"
14 | },
15 | "minimum-stability": "stable",
16 | "require": {
17 | "php": ">=5.6.0",
18 | "yiisoft/yii2": "~2.0.14",
19 | "yiisoft/yii2-bootstrap": "~2.0.0",
20 | "yiisoft/yii2-swiftmailer": "~2.0.0 || ~2.1.0"
21 | },
22 | "require-dev": {
23 | "yiisoft/yii2-debug": "~2.1.0",
24 | "yiisoft/yii2-gii": "~2.1.0",
25 | "yiisoft/yii2-faker": "~2.0.0",
26 | "codeception/codeception": "^4.0",
27 | "codeception/module-asserts": "^1.0",
28 | "codeception/module-yii2": "^1.0",
29 | "codeception/module-filesystem": "^1.0",
30 | "codeception/verify": "~0.5.0 || ~1.1.0",
31 | "symfony/browser-kit": ">=2.7 <=4.2.4"
32 | },
33 | "config": {
34 | "process-timeout": 1800,
35 | "fxp-asset": {
36 | "enabled": false
37 | }
38 | },
39 | "repositories": [
40 | {
41 | "type": "composer",
42 | "url": "https://asset-packagist.org"
43 | }
44 | ]
45 | }
46 |
--------------------------------------------------------------------------------
/frontend/models/SignupForm.php:
--------------------------------------------------------------------------------
1 | 'trim'],
24 | ['username', 'required'],
25 | ['username', 'unique', 'targetClass' => '\common\models\User', 'message' => 'This username has already been taken.'],
26 | ['username', 'string', 'min' => 2, 'max' => 255],
27 |
28 | ['email', 'filter', 'filter' => 'trim'],
29 | ['email', 'required'],
30 | ['email', 'email'],
31 | ['email', 'unique', 'targetClass' => '\common\models\User', 'message' => 'This email address has already been taken.'],
32 |
33 | ['password', 'required'],
34 | ['password', 'string', 'min' => 6],
35 | ];
36 | }
37 |
38 | /**
39 | * Signs user up.
40 | *
41 | * @return User|null the saved model or null if saving fails
42 | */
43 | public function signup()
44 | {
45 | if ($this->validate()) {
46 | $user = new User();
47 | $user->username = $this->username;
48 | $user->email = $this->email;
49 | $user->setPassword($this->password);
50 | $user->generateAuthKey();
51 | if ($user->save()) {
52 | return $user;
53 | }
54 | }
55 |
56 | return null;
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/LICENSE.md:
--------------------------------------------------------------------------------
1 | The Yii framework is free software. It is released under the terms of
2 | the following BSD License.
3 |
4 | Copyright © 2008 by Yii Software LLC (http://www.yiisoft.com)
5 | All rights reserved.
6 |
7 | Redistribution and use in source and binary forms, with or without
8 | modification, are permitted provided that the following conditions
9 | are met:
10 |
11 | * Redistributions of source code must retain the above copyright
12 | notice, this list of conditions and the following disclaimer.
13 | * Redistributions in binary form must reproduce the above copyright
14 | notice, this list of conditions and the following disclaimer in
15 | the documentation and/or other materials provided with the
16 | distribution.
17 | * Neither the name of Yii Software LLC nor the names of its
18 | contributors may be used to endorse or promote products derived
19 | from this software without specific prior written permission.
20 |
21 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 | COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 | POSSIBILITY OF SUCH DAMAGE.
33 |
--------------------------------------------------------------------------------
/tests/codeception/frontend/unit/models/SignupFormTest.php:
--------------------------------------------------------------------------------
1 | 'some_username',
19 | 'email' => 'some_email@example.com',
20 | 'password' => 'some_password',
21 | ]);
22 |
23 | $user = $model->signup();
24 |
25 | $this->assertInstanceOf('common\models\User', $user, 'user should be valid');
26 |
27 | expect('username should be correct', $user->username)->equals('some_username');
28 | expect('email should be correct', $user->email)->equals('some_email@example.com');
29 | expect('password should be correct', $user->validatePassword('some_password'))->true();
30 | }
31 |
32 | public function testNotCorrectSignup()
33 | {
34 | $model = new SignupForm([
35 | 'username' => 'troy.becker',
36 | 'email' => 'nicolas.dianna@hotmail.com',
37 | 'password' => 'some_password',
38 | ]);
39 |
40 | expect('username and email are in use, user should not be created', $model->signup())->null();
41 | }
42 |
43 | public function fixtures()
44 | {
45 | return [
46 | 'user' => [
47 | 'class' => UserFixture::className(),
48 | 'dataFile' => '@tests/codeception/frontend/unit/fixtures/data/models/user.php',
49 | ],
50 | ];
51 | }
52 |
53 | }
54 |
--------------------------------------------------------------------------------
/backend/web/css/site.css:
--------------------------------------------------------------------------------
1 | html,
2 | body {
3 | height: 100%;
4 | }
5 |
6 | .wrap {
7 | min-height: 100%;
8 | height: auto;
9 | margin: 0 auto -60px;
10 | padding: 0 0 60px;
11 | }
12 |
13 | .wrap > .container {
14 | padding: 70px 15px 20px;
15 | }
16 |
17 | .footer {
18 | height: 60px;
19 | background-color: #f5f5f5;
20 | border-top: 1px solid #ddd;
21 | padding-top: 20px;
22 | }
23 |
24 | .jumbotron {
25 | text-align: center;
26 | background-color: transparent;
27 | }
28 |
29 | .jumbotron .btn {
30 | font-size: 21px;
31 | padding: 14px 24px;
32 | }
33 |
34 | .not-set {
35 | color: #c55;
36 | font-style: italic;
37 | }
38 |
39 | /* add sorting icons to gridview sort links */
40 | a.asc:after, a.desc:after {
41 | position: relative;
42 | top: 1px;
43 | display: inline-block;
44 | font-family: 'Glyphicons Halflings';
45 | font-style: normal;
46 | font-weight: normal;
47 | line-height: 1;
48 | padding-left: 5px;
49 | }
50 |
51 | a.asc:after {
52 | content: /*"\e113"*/ "\e151";
53 | }
54 |
55 | a.desc:after {
56 | content: /*"\e114"*/ "\e152";
57 | }
58 |
59 | .sort-numerical a.asc:after {
60 | content: "\e153";
61 | }
62 |
63 | .sort-numerical a.desc:after {
64 | content: "\e154";
65 | }
66 |
67 | .sort-ordinal a.asc:after {
68 | content: "\e155";
69 | }
70 |
71 | .sort-ordinal a.desc:after {
72 | content: "\e156";
73 | }
74 |
75 | .grid-view th {
76 | white-space: nowrap;
77 | }
78 |
79 | .hint-block {
80 | display: block;
81 | margin-top: 5px;
82 | color: #999;
83 | }
84 |
85 | .error-summary {
86 | color: #a94442;
87 | background: #fdf7f7;
88 | border-left: 3px solid #eed3d7;
89 | padding: 10px 20px;
90 | margin: 0 0 15px 0;
91 | }
92 |
--------------------------------------------------------------------------------
/frontend/web/css/site.css:
--------------------------------------------------------------------------------
1 | html,
2 | body {
3 | height: 100%;
4 | }
5 |
6 | .wrap {
7 | min-height: 100%;
8 | height: auto;
9 | margin: 0 auto -60px;
10 | padding: 0 0 60px;
11 | }
12 |
13 | .wrap > .container {
14 | padding: 70px 15px 20px;
15 | }
16 |
17 | .footer {
18 | height: 60px;
19 | background-color: #f5f5f5;
20 | border-top: 1px solid #ddd;
21 | padding-top: 20px;
22 | }
23 |
24 | .jumbotron {
25 | text-align: center;
26 | background-color: transparent;
27 | }
28 |
29 | .jumbotron .btn {
30 | font-size: 21px;
31 | padding: 14px 24px;
32 | }
33 |
34 | .not-set {
35 | color: #c55;
36 | font-style: italic;
37 | }
38 |
39 | /* add sorting icons to gridview sort links */
40 | a.asc:after, a.desc:after {
41 | position: relative;
42 | top: 1px;
43 | display: inline-block;
44 | font-family: 'Glyphicons Halflings';
45 | font-style: normal;
46 | font-weight: normal;
47 | line-height: 1;
48 | padding-left: 5px;
49 | }
50 |
51 | a.asc:after {
52 | content: /*"\e113"*/ "\e151";
53 | }
54 |
55 | a.desc:after {
56 | content: /*"\e114"*/ "\e152";
57 | }
58 |
59 | .sort-numerical a.asc:after {
60 | content: "\e153";
61 | }
62 |
63 | .sort-numerical a.desc:after {
64 | content: "\e154";
65 | }
66 |
67 | .sort-ordinal a.asc:after {
68 | content: "\e155";
69 | }
70 |
71 | .sort-ordinal a.desc:after {
72 | content: "\e156";
73 | }
74 |
75 | .grid-view th {
76 | white-space: nowrap;
77 | }
78 |
79 | .hint-block {
80 | display: block;
81 | margin-top: 5px;
82 | color: #999;
83 | }
84 |
85 | .error-summary {
86 | color: #a94442;
87 | background: #fdf7f7;
88 | border-left: 3px solid #eed3d7;
89 | padding: 10px 20px;
90 | margin: 0 0 15px 0;
91 | }
92 |
--------------------------------------------------------------------------------
/tests/codeception/frontend/functional/ContactCept.php:
--------------------------------------------------------------------------------
1 | wantTo('ensure that contact works');
9 |
10 | $contactPage = ContactPage::openBy($I);
11 |
12 | $I->see('Contact', 'h1');
13 |
14 | $I->amGoingTo('submit contact form with no data');
15 | $contactPage->submit([]);
16 | $I->expectTo('see validations errors');
17 | $I->see('Contact', 'h1');
18 | $I->see('Name cannot be blank', '.help-block');
19 | $I->see('Email cannot be blank', '.help-block');
20 | $I->see('Subject cannot be blank', '.help-block');
21 | $I->see('Body cannot be blank', '.help-block');
22 | $I->see('The verification code is incorrect', '.help-block');
23 |
24 | $I->amGoingTo('submit contact form with not correct email');
25 | $contactPage->submit([
26 | 'name' => 'tester',
27 | 'email' => 'tester.email',
28 | 'subject' => 'test subject',
29 | 'body' => 'test content',
30 | 'verifyCode' => 'testme',
31 | ]);
32 | $I->expectTo('see that email adress is wrong');
33 | $I->dontSee('Name cannot be blank', '.help-block');
34 | $I->see('Email is not a valid email address.', '.help-block');
35 | $I->dontSee('Subject cannot be blank', '.help-block');
36 | $I->dontSee('Body cannot be blank', '.help-block');
37 | $I->dontSee('The verification code is incorrect', '.help-block');
38 |
39 | $I->amGoingTo('submit contact form with correct data');
40 | $contactPage->submit([
41 | 'name' => 'tester',
42 | 'email' => 'tester@example.com',
43 | 'subject' => 'test subject',
44 | 'body' => 'test content',
45 | 'verifyCode' => 'testme',
46 | ]);
47 | $I->see('Thank you for contacting us. We will respond to you as soon as possible.');
48 |
--------------------------------------------------------------------------------
/frontend/models/ResetPasswordForm.php:
--------------------------------------------------------------------------------
1 | _user = User::findByPasswordResetToken($token);
35 | if (!$this->_user) {
36 | throw new InvalidParamException('Wrong password reset token.');
37 | }
38 | parent::__construct($config);
39 | }
40 |
41 | /**
42 | * @inheritdoc
43 | */
44 | public function rules()
45 | {
46 | return [
47 | ['password', 'required'],
48 | ['password', 'string', 'min' => 6],
49 | ];
50 | }
51 |
52 | /**
53 | * Resets password.
54 | *
55 | * @return boolean if password was reset.
56 | */
57 | public function resetPassword()
58 | {
59 | $user = $this->_user;
60 | $user->setPassword($this->password);
61 | $user->removePasswordResetToken();
62 |
63 | return $user->save(false);
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/frontend/models/PasswordResetRequestForm.php:
--------------------------------------------------------------------------------
1 | 'trim'],
21 | ['email', 'required'],
22 | ['email', 'email'],
23 | ['email', 'exist',
24 | 'targetClass' => '\common\models\User',
25 | 'filter' => ['status' => User::STATUS_ACTIVE],
26 | 'message' => 'There is no user with such email.'
27 | ],
28 | ];
29 | }
30 |
31 | /**
32 | * Sends an email with a link, for resetting the password.
33 | *
34 | * @return boolean whether the email was send
35 | */
36 | public function sendEmail()
37 | {
38 | /* @var $user User */
39 | $user = User::findOne([
40 | 'status' => User::STATUS_ACTIVE,
41 | 'email' => $this->email,
42 | ]);
43 |
44 | if ($user) {
45 | if (!User::isPasswordResetTokenValid($user->password_reset_token)) {
46 | $user->generatePasswordResetToken();
47 | }
48 |
49 | if ($user->save()) {
50 | return \Yii::$app->mailer->compose(['html' => 'passwordResetToken-html', 'text' => 'passwordResetToken-text'], ['user' => $user])
51 | ->setFrom([\Yii::$app->params['supportEmail'] => \Yii::$app->name . ' robot'])
52 | ->setTo($this->email)
53 | ->setSubject('Password reset for ' . \Yii::$app->name)
54 | ->send();
55 | }
56 | }
57 |
58 | return false;
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/tests/README.md:
--------------------------------------------------------------------------------
1 | This directory contains various tests for the advanced applications.
2 |
3 | Tests in `codeception` directory are developed with [Codeception PHP Testing Framework](http://codeception.com/).
4 |
5 | After creating and setting up the advanced application, follow these steps to prepare for the tests:
6 |
7 | 1. Install Codeception if it's not yet installed:
8 |
9 | ```
10 | composer global require "codeception/codeception=2.0.*" "codeception/specify=*" "codeception/verify=*"
11 | ```
12 |
13 | If you've never used Composer for global packages run `composer global status`. It should output:
14 |
15 | ```
16 | Changed current directory to
17 | ```
18 |
19 | Then add `/vendor/bin` to you `PATH` environment variable. Now you're able to use `codecept` from command
20 | line globally.
21 |
22 | 2. Install faker extension by running the following from template root directory where `composer.json` is:
23 |
24 | ```
25 | composer require --dev yiisoft/yii2-faker:*
26 | ```
27 |
28 | 3. Create `yii2_advanced_tests` database then update it by applying migrations:
29 |
30 | ```
31 | codeception/bin/yii migrate
32 | ```
33 |
34 | 4. In order to be able to run acceptance tests you need to start a webserver. The simplest way is to use PHP built in
35 | webserver. In the root directory where `common`, `frontend` etc. are execute the following:
36 |
37 | ```
38 | php -S localhost:8080
39 | ```
40 |
41 | 5. Now you can run the tests with the following commands, assuming you are in the `tests/codeception` directory:
42 |
43 | ```
44 | # frontend tests
45 | cd frontend
46 | codecept build
47 | codecept run
48 |
49 | # backend tests
50 |
51 | cd backend
52 | codecept build
53 | codecept run
54 |
55 | # etc.
56 | ```
57 |
58 | If you already have run `codecept build` for each application, you can skip that step and run all tests by a single `codecept run`.
59 |
--------------------------------------------------------------------------------
/tests/codeception/frontend/unit/models/ContactFormTest.php:
--------------------------------------------------------------------------------
1 | mailer->fileTransportCallback = function ($mailer, $message) {
18 | return 'testing_message.eml';
19 | };
20 | }
21 |
22 | protected function tearDown()
23 | {
24 | unlink($this->getMessageFile());
25 | parent::tearDown();
26 | }
27 |
28 | public function testContact()
29 | {
30 | $model = new ContactForm();
31 |
32 | $model->attributes = [
33 | 'name' => 'Tester',
34 | 'email' => 'tester@example.com',
35 | 'subject' => 'very important letter subject',
36 | 'body' => 'body of current message',
37 | ];
38 |
39 | $model->sendEmail('admin@example.com');
40 |
41 | $this->specify('email should be send', function () {
42 | expect('email file should exist', file_exists($this->getMessageFile()))->true();
43 | });
44 |
45 | $this->specify('message should contain correct data', function () use ($model) {
46 | $emailMessage = file_get_contents($this->getMessageFile());
47 |
48 | expect('email should contain user name', $emailMessage)->contains($model->name);
49 | expect('email should contain sender email', $emailMessage)->contains($model->email);
50 | expect('email should contain subject', $emailMessage)->contains($model->subject);
51 | expect('email should contain body', $emailMessage)->contains($model->body);
52 | });
53 | }
54 |
55 | private function getMessageFile()
56 | {
57 | return Yii::getAlias(Yii::$app->mailer->fileTransportPath) . '/testing_message.eml';
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/tests/codeception/frontend/acceptance/ContactCept.php:
--------------------------------------------------------------------------------
1 | wantTo('ensure that contact works');
9 |
10 | $contactPage = ContactPage::openBy($I);
11 |
12 | $I->see('Contact', 'h1');
13 |
14 | $I->amGoingTo('submit contact form with no data');
15 | $contactPage->submit([]);
16 | if (method_exists($I, 'wait')) {
17 | $I->wait(3); // only for selenium
18 | }
19 | $I->expectTo('see validations errors');
20 | $I->see('Contact', 'h1');
21 | $I->see('Name cannot be blank', '.help-block');
22 | $I->see('Email cannot be blank', '.help-block');
23 | $I->see('Subject cannot be blank', '.help-block');
24 | $I->see('Body cannot be blank', '.help-block');
25 | $I->see('The verification code is incorrect', '.help-block');
26 |
27 | $I->amGoingTo('submit contact form with not correct email');
28 | $contactPage->submit([
29 | 'name' => 'tester',
30 | 'email' => 'tester.email',
31 | 'subject' => 'test subject',
32 | 'body' => 'test content',
33 | 'verifyCode' => 'testme',
34 | ]);
35 | if (method_exists($I, 'wait')) {
36 | $I->wait(3); // only for selenium
37 | }
38 | $I->expectTo('see that email adress is wrong');
39 | $I->dontSee('Name cannot be blank', '.help-block');
40 | $I->see('Email is not a valid email address.', '.help-block');
41 | $I->dontSee('Subject cannot be blank', '.help-block');
42 | $I->dontSee('Body cannot be blank', '.help-block');
43 | $I->dontSee('The verification code is incorrect', '.help-block');
44 |
45 | $I->amGoingTo('submit contact form with correct data');
46 | $contactPage->submit([
47 | 'name' => 'tester',
48 | 'email' => 'tester@example.com',
49 | 'subject' => 'test subject',
50 | 'body' => 'test content',
51 | 'verifyCode' => 'testme',
52 | ]);
53 | if (method_exists($I, 'wait')) {
54 | $I->wait(3); // only for selenium
55 | }
56 | $I->see('Thank you for contacting us. We will respond to you as soon as possible.');
57 |
--------------------------------------------------------------------------------
/tests/codeception/common/_support/FixtureHelper.php:
--------------------------------------------------------------------------------
1 | loadFixtures();
40 | }
41 |
42 | /**
43 | * Method is called after all suite tests run
44 | */
45 | public function _afterSuite()
46 | {
47 | $this->unloadFixtures();
48 | }
49 |
50 | /**
51 | * @inheritdoc
52 | */
53 | public function globalFixtures()
54 | {
55 | return [
56 | InitDbFixture::className(),
57 | ];
58 | }
59 |
60 | /**
61 | * @inheritdoc
62 | */
63 | public function fixtures()
64 | {
65 | return [
66 | 'user' => [
67 | 'class' => UserFixture::className(),
68 | 'dataFile' => '@tests/codeception/common/fixtures/data/init_login.php',
69 | ],
70 | ];
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/backend/controllers/SiteController.php:
--------------------------------------------------------------------------------
1 | [
22 | 'class' => AccessControl::className(),
23 | 'rules' => [
24 | [
25 | 'actions' => ['login', 'error'],
26 | 'allow' => true,
27 | ],
28 | [
29 | 'actions' => ['logout', 'index'],
30 | 'allow' => true,
31 | 'roles' => ['@'],
32 | ],
33 | ],
34 | ],
35 | 'verbs' => [
36 | 'class' => VerbFilter::className(),
37 | 'actions' => [
38 | 'logout' => ['post'],
39 | ],
40 | ],
41 | ];
42 | }
43 |
44 | /**
45 | * @inheritdoc
46 | */
47 | public function actions()
48 | {
49 | return [
50 | 'error' => [
51 | 'class' => 'yii\web\ErrorAction',
52 | ],
53 | ];
54 | }
55 |
56 | public function actionIndex()
57 | {
58 | return $this->render('index');
59 | }
60 |
61 | public function actionLogin()
62 | {
63 | if (!\Yii::$app->user->isGuest) {
64 | return $this->goHome();
65 | }
66 |
67 | $model = new LoginForm();
68 | if ($model->load(Yii::$app->request->post()) && $model->login()) {
69 | return $this->goBack();
70 | } else {
71 | return $this->render('login', [
72 | 'model' => $model,
73 | ]);
74 | }
75 | }
76 |
77 | public function actionLogout()
78 | {
79 | Yii::$app->user->logout();
80 |
81 | return $this->goHome();
82 | }
83 | }
84 |
--------------------------------------------------------------------------------
/common/models/LoginForm.php:
--------------------------------------------------------------------------------
1 | hasErrors()) {
44 | $user = $this->getUser();
45 | if (!$user || !$user->validatePassword($this->password)) {
46 | $this->addError($attribute, 'Incorrect username or password.');
47 | }
48 | }
49 | }
50 |
51 | /**
52 | * Logs in a user using the provided username and password.
53 | *
54 | * @return boolean whether the user is logged in successfully
55 | */
56 | public function login()
57 | {
58 | if ($this->validate()) {
59 | return Yii::$app->user->login($this->getUser(), $this->rememberMe ? 3600 * 24 * 30 : 0);
60 | } else {
61 | return false;
62 | }
63 | }
64 |
65 | /**
66 | * Finds user by [[username]]
67 | *
68 | * @return User|null
69 | */
70 | public function getUser()
71 | {
72 | if ($this->_user === false) {
73 | $this->_user = User::findByUsername($this->username);
74 | }
75 |
76 | return $this->_user;
77 | }
78 | }
79 |
--------------------------------------------------------------------------------
/environments/index.php:
--------------------------------------------------------------------------------
1 | [
11 | * 'path' => 'directory storing the local files',
12 | * 'skipFiles' => [
13 | * // list of files that should only copied once and skipped if they already exist
14 | * ],
15 | * 'setWritable' => [
16 | * // list of directories that should be set writable
17 | * ],
18 | * 'setExecutable' => [
19 | * // list of files that should be set executable
20 | * ],
21 | * 'setCookieValidationKey' => [
22 | * // list of config files that need to be inserted with automatically generated cookie validation keys
23 | * ],
24 | * 'createSymlink' => [
25 | * // list of symlinks to be created. Keys are symlinks, and values are the targets.
26 | * ],
27 | * ],
28 | * ];
29 | * ```
30 | */
31 | return [
32 | 'Development' => [
33 | 'path' => 'dev',
34 | 'setWritable' => [
35 | 'backend/runtime',
36 | 'backend/web/assets',
37 | 'api/runtime',
38 | 'api/web/assets',
39 | 'frontend/runtime',
40 | 'frontend/web/assets',
41 | ],
42 | 'setExecutable' => [
43 | 'yii',
44 | 'tests/codeception/bin/yii',
45 | ],
46 | 'setCookieValidationKey' => [
47 | 'backend/config/main-local.php',
48 | 'frontend/config/main-local.php',
49 | ],
50 | ],
51 | 'Production' => [
52 | 'path' => 'prod',
53 | 'setWritable' => [
54 | 'backend/runtime',
55 | 'backend/web/assets',
56 | 'api/runtime',
57 | 'api/web/assets',
58 | 'frontend/runtime',
59 | 'frontend/web/assets',
60 | ],
61 | 'setExecutable' => [
62 | 'yii',
63 | ],
64 | 'setCookieValidationKey' => [
65 | 'backend/config/main-local.php',
66 | 'frontend/config/main-local.php',
67 | ],
68 | ],
69 | ];
70 |
--------------------------------------------------------------------------------
/api/config/main.php:
--------------------------------------------------------------------------------
1 | 'app-api',
12 | 'basePath' => dirname(__DIR__),
13 | 'controllerNamespace' => 'api\controllers',
14 | 'defaultRoute' => 'v1/default',
15 | 'modules' => [
16 | 'v1' => [
17 | 'basePath' => '@app/modules/v1',
18 | 'class' => \api\modules\v1\Module::className(),
19 | ]
20 | ],
21 | 'bootstrap' => [
22 | 'log',
23 | [
24 | 'class' => \yii\filters\ContentNegotiator::className(),
25 | 'formats' => [
26 | 'application/json' => \yii\web\Response::FORMAT_JSON,
27 | 'application/xml' => \yii\web\Response::FORMAT_XML,
28 | ],
29 | ],
30 | ],
31 | 'components' => [
32 | 'user' => [
33 | 'identityClass' => 'common\models\User',
34 | 'enableAutoLogin' => true,
35 | ],
36 | 'log' => [
37 | 'traceLevel' => YII_DEBUG ? 3 : 0,
38 | 'targets' => [
39 | [
40 | 'class' => 'yii\log\FileTarget',
41 | 'levels' => ['error', 'warning'],
42 | ],
43 | ],
44 | ],
45 | 'urlManager' => [
46 | 'rules' => [
47 | '/' => 'v1//view',
48 | '//' => 'v1//',
49 | '/' => 'v1//',
50 | ],
51 | ],
52 | 'response' => [
53 | 'class' => \yii\web\Response::className(),
54 | 'on beforeSend' => function ($event) {
55 | $response = $event->sender;
56 | if ($response->data !== null && ($exception = Yii::$app->getErrorHandler()->exception) !== null) {
57 | $response->data = [
58 | 'error' => $response->data,
59 | ];
60 | }
61 | },
62 | ],
63 | ],
64 | 'params' => $params,
65 | ];
66 |
67 |
--------------------------------------------------------------------------------
/backend/views/layouts/main.php:
--------------------------------------------------------------------------------
1 |
13 | beginPage() ?>
14 |
15 |
16 |
17 |
18 |
19 | = Html::csrfMetaTags() ?>
20 | = Html::encode($this->title) ?>
21 | head() ?>
22 |
23 |
24 | beginBody() ?>
25 |
26 | 'My Company',
29 | 'brandUrl' => Yii::$app->homeUrl,
30 | 'options' => [
31 | 'class' => 'navbar-inverse navbar-fixed-top',
32 | ],
33 | ]);
34 | $menuItems = [
35 | ['label' => 'Home', 'url' => ['/site/index']],
36 | ];
37 | if (Yii::$app->user->isGuest) {
38 | $menuItems[] = ['label' => 'Login', 'url' => ['/site/login']];
39 | } else {
40 | $menuItems[] = [
41 | 'label' => 'Logout (' . Yii::$app->user->identity->username . ')',
42 | 'url' => ['/site/logout'],
43 | 'linkOptions' => ['data-method' => 'post']
44 | ];
45 | }
46 | echo Nav::widget([
47 | 'options' => ['class' => 'navbar-nav navbar-right'],
48 | 'items' => $menuItems,
49 | ]);
50 | NavBar::end();
51 | ?>
52 |
53 |
54 | = Breadcrumbs::widget([
55 | 'links' => isset($this->params['breadcrumbs']) ? $this->params['breadcrumbs'] : [],
56 | ]) ?>
57 | = $content ?>
58 |
59 |
60 |
61 |
67 |
68 | endBody() ?>
69 |
70 |
71 | endPage() ?>
72 |
--------------------------------------------------------------------------------
/frontend/views/site/index.php:
--------------------------------------------------------------------------------
1 | title = 'My Yii Application';
4 | ?>
5 |
6 |
7 |
8 |
Congratulations!
9 |
10 |
You have successfully created your Yii-powered application.
11 |
12 |
Get started with Yii
13 |
14 |
15 |
16 |
17 |
18 |
19 |
Heading
20 |
21 |
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et
22 | dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip
23 | ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu
24 | fugiat nulla pariatur.
25 |
26 |
Yii Documentation »
27 |
28 |
29 |
Heading
30 |
31 |
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et
32 | dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip
33 | ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu
34 | fugiat nulla pariatur.
35 |
36 |
Yii Forum »
37 |
38 |
39 |
Heading
40 |
41 |
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et
42 | dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip
43 | ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu
44 | fugiat nulla pariatur.
45 |
46 |
Yii Extensions »
47 |
48 |
49 |
50 |
51 |
52 |
--------------------------------------------------------------------------------
/backend/views/site/index.php:
--------------------------------------------------------------------------------
1 | title = 'My Yii Application';
5 | ?>
6 |
7 |
8 |
9 |
Congratulations!
10 |
11 |
You have successfully created your Yii-powered application.
12 |
13 |
Get started with Yii
14 |
15 |
16 |
17 |
18 |
19 |
20 |
Heading
21 |
22 |
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et
23 | dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip
24 | ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu
25 | fugiat nulla pariatur.
26 |
27 |
Yii Documentation »
28 |
29 |
30 |
Heading
31 |
32 |
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et
33 | dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip
34 | ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu
35 | fugiat nulla pariatur.
36 |
37 |
Yii Forum »
38 |
39 |
40 |
Heading
41 |
42 |
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et
43 | dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip
44 | ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu
45 | fugiat nulla pariatur.
46 |
47 |
Yii Extensions »
48 |
49 |
50 |
51 |
52 |
53 |
--------------------------------------------------------------------------------
/frontend/views/layouts/main.php:
--------------------------------------------------------------------------------
1 |
14 | beginPage() ?>
15 |
16 |
17 |
18 |
19 |
20 | = Html::csrfMetaTags() ?>
21 | = Html::encode($this->title) ?>
22 | head() ?>
23 |
24 |
25 | beginBody() ?>
26 |
27 | 'My Company',
30 | 'brandUrl' => Yii::$app->homeUrl,
31 | 'options' => [
32 | 'class' => 'navbar-inverse navbar-fixed-top',
33 | ],
34 | ]);
35 | $menuItems = [
36 | ['label' => 'Home', 'url' => ['/site/index']],
37 | ['label' => 'About', 'url' => ['/site/about']],
38 | ['label' => 'Contact', 'url' => ['/site/contact']],
39 | ];
40 | if (Yii::$app->user->isGuest) {
41 | $menuItems[] = ['label' => 'Signup', 'url' => ['/site/signup']];
42 | $menuItems[] = ['label' => 'Login', 'url' => ['/site/login']];
43 | } else {
44 | $menuItems[] = [
45 | 'label' => 'Logout (' . Yii::$app->user->identity->username . ')',
46 | 'url' => ['/site/logout'],
47 | 'linkOptions' => ['data-method' => 'post']
48 | ];
49 | }
50 | echo Nav::widget([
51 | 'options' => ['class' => 'navbar-nav navbar-right'],
52 | 'items' => $menuItems,
53 | ]);
54 | NavBar::end();
55 | ?>
56 |
57 |
58 | = Breadcrumbs::widget([
59 | 'links' => isset($this->params['breadcrumbs']) ? $this->params['breadcrumbs'] : [],
60 | ]) ?>
61 | = Alert::widget() ?>
62 | = $content ?>
63 |
64 |
65 |
66 |
72 |
73 | endBody() ?>
74 |
75 |
76 | endPage() ?>
77 |
--------------------------------------------------------------------------------
/tests/codeception/frontend/acceptance/SignupCest.php:
--------------------------------------------------------------------------------
1 | 'tester.email@example.com',
27 | 'username' => 'tester',
28 | ]);
29 | }
30 |
31 | /**
32 | * This method is called when test fails.
33 | * @param \Codeception\Event\FailEvent $event
34 | */
35 | public function _fail($event)
36 | {
37 | }
38 |
39 | /**
40 | * @param \codeception_frontend\AcceptanceTester $I
41 | * @param \Codeception\Scenario $scenario
42 | */
43 | public function testUserSignup($I, $scenario)
44 | {
45 | $I->wantTo('ensure that signup works');
46 |
47 | $signupPage = SignupPage::openBy($I);
48 | $I->see('Signup', 'h1');
49 | $I->see('Please fill out the following fields to signup:');
50 |
51 | $I->amGoingTo('submit signup form with no data');
52 |
53 | $signupPage->submit([]);
54 |
55 | $I->expectTo('see validation errors');
56 | $I->see('Username cannot be blank.', '.help-block');
57 | $I->see('Email cannot be blank.', '.help-block');
58 | $I->see('Password cannot be blank.', '.help-block');
59 |
60 | $I->amGoingTo('submit signup form with not correct email');
61 | $signupPage->submit([
62 | 'username' => 'tester',
63 | 'email' => 'tester.email',
64 | 'password' => 'tester_password',
65 | ]);
66 |
67 | $I->expectTo('see that email address is wrong');
68 | $I->dontSee('Username cannot be blank.', '.help-block');
69 | $I->dontSee('Password cannot be blank.', '.help-block');
70 | $I->see('Email is not a valid email address.', '.help-block');
71 |
72 | $I->amGoingTo('submit signup form with correct email');
73 | $signupPage->submit([
74 | 'username' => 'tester',
75 | 'email' => 'tester.email@example.com',
76 | 'password' => 'tester_password',
77 | ]);
78 |
79 | $I->expectTo('see that user logged in');
80 | $I->seeLink('Logout (tester)');
81 | }
82 | }
83 |
--------------------------------------------------------------------------------
/frontend/widgets/Alert.php:
--------------------------------------------------------------------------------
1 | getSession()->setFlash('error', 'This is the message');
16 | * \Yii::$app->getSession()->setFlash('success', 'This is the message');
17 | * \Yii::$app->getSession()->setFlash('info', 'This is the message');
18 | * ```
19 | *
20 | * Multiple messages could be set as follows:
21 | *
22 | * ```php
23 | * \Yii::$app->getSession()->setFlash('error', ['Error 1', 'Error 2']);
24 | * ```
25 | *
26 | * @author Kartik Visweswaran
27 | * @author Alexander Makarov
28 | */
29 | class Alert extends \yii\bootstrap\Widget
30 | {
31 | /**
32 | * @var array the alert types configuration for the flash messages.
33 | * This array is setup as $key => $value, where:
34 | * - $key is the name of the session flash variable
35 | * - $value is the bootstrap alert type (i.e. danger, success, info, warning)
36 | */
37 | public $alertTypes = [
38 | 'error' => 'alert-danger',
39 | 'danger' => 'alert-danger',
40 | 'success' => 'alert-success',
41 | 'info' => 'alert-info',
42 | 'warning' => 'alert-warning'
43 | ];
44 |
45 | /**
46 | * @var array the options for rendering the close button tag.
47 | */
48 | public $closeButton = [];
49 |
50 | public function init()
51 | {
52 | parent::init();
53 |
54 | $session = \Yii::$app->getSession();
55 | $flashes = $session->getAllFlashes();
56 | $appendCss = isset($this->options['class']) ? ' ' . $this->options['class'] : '';
57 |
58 | foreach ($flashes as $type => $data) {
59 | if (isset($this->alertTypes[$type])) {
60 | $data = (array) $data;
61 | foreach ($data as $i => $message) {
62 | /* initialize css class for each alert box */
63 | $this->options['class'] = $this->alertTypes[$type] . $appendCss;
64 |
65 | /* assign unique id to each alert box */
66 | $this->options['id'] = $this->getId() . '-' . $type . '-' . $i;
67 |
68 | echo \yii\bootstrap\Alert::widget([
69 | 'body' => $message,
70 | 'closeButton' => $this->closeButton,
71 | 'options' => $this->options,
72 | ]);
73 | }
74 |
75 | $session->removeFlash($type);
76 | }
77 | }
78 | }
79 | }
80 |
--------------------------------------------------------------------------------
/tests/codeception/frontend/unit/models/PasswordResetRequestFormTest.php:
--------------------------------------------------------------------------------
1 | mailer->fileTransportCallback = function ($mailer, $message) {
21 | return 'testing_message.eml';
22 | };
23 | }
24 |
25 | protected function tearDown()
26 | {
27 | @unlink($this->getMessageFile());
28 |
29 | parent::tearDown();
30 | }
31 |
32 | public function testSendEmailWrongUser()
33 | {
34 | $this->specify('no user with such email, message should not be sent', function () {
35 |
36 | $model = new PasswordResetRequestForm();
37 | $model->email = 'not-existing-email@example.com';
38 |
39 | expect('email not sent', $model->sendEmail())->false();
40 |
41 | });
42 |
43 | $this->specify('user is not active, message should not be sent', function () {
44 |
45 | $model = new PasswordResetRequestForm();
46 | $model->email = $this->user[1]['email'];
47 |
48 | expect('email not sent', $model->sendEmail())->false();
49 |
50 | });
51 | }
52 |
53 | public function testSendEmailCorrectUser()
54 | {
55 | $model = new PasswordResetRequestForm();
56 | $model->email = $this->user[0]['email'];
57 | $user = User::findOne(['password_reset_token' => $this->user[0]['password_reset_token']]);
58 |
59 | expect('email sent', $model->sendEmail())->true();
60 | expect('user has valid token', $user->password_reset_token)->notNull();
61 |
62 | $this->specify('message has correct format', function () use ($model) {
63 |
64 | expect('message file exists', file_exists($this->getMessageFile()))->true();
65 |
66 | $message = file_get_contents($this->getMessageFile());
67 | expect('message "from" is correct', $message)->contains(Yii::$app->params['supportEmail']);
68 | expect('message "to" is correct', $message)->contains($model->email);
69 |
70 | });
71 | }
72 |
73 | public function fixtures()
74 | {
75 | return [
76 | 'user' => [
77 | 'class' => UserFixture::className(),
78 | 'dataFile' => '@tests/codeception/frontend/unit/fixtures/data/models/user.php'
79 | ],
80 | ];
81 | }
82 |
83 | private function getMessageFile()
84 | {
85 | return Yii::getAlias(Yii::$app->mailer->fileTransportPath) . '/testing_message.eml';
86 | }
87 |
88 | }
89 |
--------------------------------------------------------------------------------
/tests/codeception/frontend/functional/SignupCest.php:
--------------------------------------------------------------------------------
1 | 'tester.email@example.com',
27 | 'username' => 'tester',
28 | ]);
29 | }
30 |
31 | /**
32 | * This method is called when test fails.
33 | * @param \Codeception\Event\FailEvent $event
34 | */
35 | public function _fail($event)
36 | {
37 |
38 | }
39 |
40 | /**
41 | *
42 | * @param \codeception_frontend\FunctionalTester $I
43 | * @param \Codeception\Scenario $scenario
44 | */
45 | public function testUserSignup($I, $scenario)
46 | {
47 | $I->wantTo('ensure that signup works');
48 |
49 | $signupPage = SignupPage::openBy($I);
50 | $I->see('Signup', 'h1');
51 | $I->see('Please fill out the following fields to signup:');
52 |
53 | $I->amGoingTo('submit signup form with no data');
54 |
55 | $signupPage->submit([]);
56 |
57 | $I->expectTo('see validation errors');
58 | $I->see('Username cannot be blank.', '.help-block');
59 | $I->see('Email cannot be blank.', '.help-block');
60 | $I->see('Password cannot be blank.', '.help-block');
61 |
62 | $I->amGoingTo('submit signup form with not correct email');
63 | $signupPage->submit([
64 | 'username' => 'tester',
65 | 'email' => 'tester.email',
66 | 'password' => 'tester_password',
67 | ]);
68 |
69 | $I->expectTo('see that email address is wrong');
70 | $I->dontSee('Username cannot be blank.', '.help-block');
71 | $I->dontSee('Password cannot be blank.', '.help-block');
72 | $I->see('Email is not a valid email address.', '.help-block');
73 |
74 | $I->amGoingTo('submit signup form with correct email');
75 | $signupPage->submit([
76 | 'username' => 'tester',
77 | 'email' => 'tester.email@example.com',
78 | 'password' => 'tester_password',
79 | ]);
80 |
81 | $I->expectTo('see that user is created');
82 | $I->seeRecord('common\models\User', [
83 | 'username' => 'tester',
84 | 'email' => 'tester.email@example.com',
85 | ]);
86 |
87 | $I->expectTo('see that user logged in');
88 | $I->seeLink('Logout (tester)');
89 | }
90 | }
91 |
--------------------------------------------------------------------------------
/tests/codeception/common/unit/models/LoginFormTest.php:
--------------------------------------------------------------------------------
1 | [
25 | 'user' => [
26 | 'class' => 'yii\web\User',
27 | 'identityClass' => 'common\models\User',
28 | ],
29 | ],
30 | ]);
31 | }
32 |
33 | protected function tearDown()
34 | {
35 | Yii::$app->user->logout();
36 | parent::tearDown();
37 | }
38 |
39 | public function testLoginNoUser()
40 | {
41 | $model = new LoginForm([
42 | 'username' => 'not_existing_username',
43 | 'password' => 'not_existing_password',
44 | ]);
45 |
46 | $this->specify('user should not be able to login, when there is no identity', function () use ($model) {
47 | expect('model should not login user', $model->login())->false();
48 | expect('user should not be logged in', Yii::$app->user->isGuest)->true();
49 | });
50 | }
51 |
52 | public function testLoginWrongPassword()
53 | {
54 | $model = new LoginForm([
55 | 'username' => 'bayer.hudson',
56 | 'password' => 'wrong_password',
57 | ]);
58 |
59 | $this->specify('user should not be able to login with wrong password', function () use ($model) {
60 | expect('model should not login user', $model->login())->false();
61 | expect('error message should be set', $model->errors)->hasKey('password');
62 | expect('user should not be logged in', Yii::$app->user->isGuest)->true();
63 | });
64 | }
65 |
66 | public function testLoginCorrect()
67 | {
68 |
69 | $model = new LoginForm([
70 | 'username' => 'bayer.hudson',
71 | 'password' => 'password_0',
72 | ]);
73 |
74 | $this->specify('user should be able to login with correct credentials', function () use ($model) {
75 | expect('model should login user', $model->login())->true();
76 | expect('error message should not be set', $model->errors)->hasntKey('password');
77 | expect('user should be logged in', Yii::$app->user->isGuest)->false();
78 | });
79 | }
80 |
81 | /**
82 | * @inheritdoc
83 | */
84 | public function fixtures()
85 | {
86 | return [
87 | 'user' => [
88 | 'class' => UserFixture::className(),
89 | 'dataFile' => '@tests/codeception/common/unit/fixtures/data/models/user.php'
90 | ],
91 | ];
92 | }
93 |
94 | }
95 |
--------------------------------------------------------------------------------
/common/models/User.php:
--------------------------------------------------------------------------------
1 | self::STATUS_ACTIVE],
54 | ['status', 'in', 'range' => [self::STATUS_ACTIVE, self::STATUS_DELETED]],
55 | ];
56 | }
57 |
58 | /**
59 | * @inheritdoc
60 | */
61 | public static function findIdentity($id)
62 | {
63 | return static::findOne(['id' => $id, 'status' => self::STATUS_ACTIVE]);
64 | }
65 |
66 | /**
67 | * @inheritdoc
68 | */
69 | public static function findIdentityByAccessToken($token, $type = null)
70 | {
71 | throw new NotSupportedException('"findIdentityByAccessToken" is not implemented.');
72 | }
73 |
74 | /**
75 | * Finds user by username
76 | *
77 | * @param string $username
78 | * @return static|null
79 | */
80 | public static function findByUsername($username)
81 | {
82 | return static::findOne(['username' => $username, 'status' => self::STATUS_ACTIVE]);
83 | }
84 |
85 | /**
86 | * Finds user by password reset token
87 | *
88 | * @param string $token password reset token
89 | * @return static|null
90 | */
91 | public static function findByPasswordResetToken($token)
92 | {
93 | if (!static::isPasswordResetTokenValid($token)) {
94 | return null;
95 | }
96 |
97 | return static::findOne([
98 | 'password_reset_token' => $token,
99 | 'status' => self::STATUS_ACTIVE,
100 | ]);
101 | }
102 |
103 | /**
104 | * Finds out if password reset token is valid
105 | *
106 | * @param string $token password reset token
107 | * @return boolean
108 | */
109 | public static function isPasswordResetTokenValid($token)
110 | {
111 | if (empty($token)) {
112 | return false;
113 | }
114 | $expire = Yii::$app->params['user.passwordResetTokenExpire'];
115 | $parts = explode('_', $token);
116 | $timestamp = (int) end($parts);
117 | return $timestamp + $expire >= time();
118 | }
119 |
120 | /**
121 | * @inheritdoc
122 | */
123 | public function getId()
124 | {
125 | return $this->getPrimaryKey();
126 | }
127 |
128 | /**
129 | * @inheritdoc
130 | */
131 | public function getAuthKey()
132 | {
133 | return $this->auth_key;
134 | }
135 |
136 | /**
137 | * @inheritdoc
138 | */
139 | public function validateAuthKey($authKey)
140 | {
141 | return $this->getAuthKey() === $authKey;
142 | }
143 |
144 | /**
145 | * Validates password
146 | *
147 | * @param string $password password to validate
148 | * @return boolean if password provided is valid for current user
149 | */
150 | public function validatePassword($password)
151 | {
152 | return Yii::$app->security->validatePassword($password, $this->password_hash);
153 | }
154 |
155 | /**
156 | * Generates password hash from password and sets it to the model
157 | *
158 | * @param string $password
159 | */
160 | public function setPassword($password)
161 | {
162 | $this->password_hash = Yii::$app->security->generatePasswordHash($password);
163 | }
164 |
165 | /**
166 | * Generates "remember me" authentication key
167 | */
168 | public function generateAuthKey()
169 | {
170 | $this->auth_key = Yii::$app->security->generateRandomString();
171 | }
172 |
173 | /**
174 | * Generates new password reset token
175 | */
176 | public function generatePasswordResetToken()
177 | {
178 | $this->password_reset_token = Yii::$app->security->generateRandomString() . '_' . time();
179 | }
180 |
181 | /**
182 | * Removes password reset token
183 | */
184 | public function removePasswordResetToken()
185 | {
186 | $this->password_reset_token = null;
187 | }
188 | }
189 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | Yii 2 API Project Template
2 | ===============================
3 |
4 | Yii 2 API Project Template is a skeleton [Yii 2](http://www.yiiframework.com/) application best for
5 | developing complex Web applications with multiple tiers.
6 |
7 | The template includes four tiers: front end, back end, api, and console, each of which
8 | is a separate Yii application.
9 |
10 | The template is designed to work in a team development environment. It supports
11 | deploying the application in different environments.
12 |
13 | [](https://packagist.org/packages/wfcreations/yii2-app-api) [](https://packagist.org/packages/wfcreations/yii2-app-api) [](https://packagist.org/packages/wfcreations/yii2-app-api) [](https://packagist.org/packages/wfcreations/yii2-app-api)
14 |
15 | DIRECTORY STRUCTURE
16 | -------------------
17 |
18 | ```
19 | api
20 | config/ contains api configurations
21 | controllers/ contains Web controller classes
22 | models/ contains api-specific model classes
23 | runtime/ contains files generated during runtime
24 | modules/ contains api versioning
25 | v1/ contains module version 1
26 | web/ contains the entry script and Web resources
27 | common
28 | config/ contains shared configurations
29 | mail/ contains view files for e-mails
30 | models/ contains model classes used in both backend and frontend
31 | console
32 | config/ contains console configurations
33 | controllers/ contains console controllers (commands)
34 | migrations/ contains database migrations
35 | models/ contains console-specific model classes
36 | runtime/ contains files generated during runtime
37 | backend
38 | assets/ contains application assets such as JavaScript and CSS
39 | config/ contains backend configurations
40 | controllers/ contains Web controller classes
41 | models/ contains backend-specific model classes
42 | runtime/ contains files generated during runtime
43 | views/ contains view files for the Web application
44 | web/ contains the entry script and Web resources
45 | frontend
46 | assets/ contains application assets such as JavaScript and CSS
47 | config/ contains frontend configurations
48 | controllers/ contains Web controller classes
49 | models/ contains frontend-specific model classes
50 | runtime/ contains files generated during runtime
51 | views/ contains view files for the Web application
52 | web/ contains the entry script and Web resources
53 | widgets/ contains frontend widgets
54 | vendor/ contains dependent 3rd-party packages
55 | environments/ contains environment-based overrides
56 | tests contains various tests for the advanced application
57 | codeception/ contains tests developed with Codeception PHP Testing Framework
58 | ```
59 | INSTALLATION
60 | ------------
61 |
62 | ### Install via Composer
63 |
64 | If you do not have [Composer](http://getcomposer.org/), you may install it by following the instructions
65 | at [getcomposer.org](http://getcomposer.org/doc/00-intro.md#installation-nix).
66 |
67 | You can then install this project template using the following command:
68 |
69 | ~~~
70 | composer global require "fxp/composer-asset-plugin:~1.0.0"
71 | composer create-project --prefer-dist --stability=dev wfcreations/yii2-app-api app
72 | ~~~
73 |
74 | Now you should be able to access the application through the following URL, assuming `app` is the directory
75 | directly under the Web root.
76 |
77 | ~~~
78 | http://localhost/app/api/web/
79 | http://localhost/app/backend/web/
80 | http://localhost/app/frontend/web/
81 | ~~~
82 |
83 |
84 | CONFIGURATION
85 | -------------
86 |
87 | ### Database
88 |
89 | Edit the file `common/config/db.php` with real data, for example:
90 |
91 | ```php
92 | return [
93 | 'class' => 'yii\db\Connection',
94 | 'dsn' => 'mysql:host=localhost;dbname=yii2app',
95 | 'username' => 'root',
96 | 'password' => '1234',
97 | 'charset' => 'utf8',
98 | ];
99 | ```
100 |
101 | **NOTE:** Yii won't create the database for you, this has to be done manually before you can access it.
102 |
103 | ### Enabling JSON Input
104 |
105 | To let the API accept input data in JSON format, configure the [[yii\web\Request::$parsers]] property of
106 | the `request` [application component](http://www.yiiframework.com/doc-2.0/guide-structure-application-components.html)
107 | to use the [[yii\web\JsonParser]] for JSON input:
108 |
109 | ```php
110 | 'request' => [
111 | 'parsers' => [
112 | 'application/json' => 'yii\web\JsonParser',
113 | ]
114 | ]
115 | ```
116 |
117 | > Info: The above configuration is optional. Without the above configuration, the API would only recognize
118 | `application/x-www-form-urlencoded` and `multipart/form-data` input formats.
119 |
--------------------------------------------------------------------------------
/frontend/controllers/SiteController.php:
--------------------------------------------------------------------------------
1 | [
28 | 'class' => AccessControl::className(),
29 | 'only' => ['logout', 'signup'],
30 | 'rules' => [
31 | [
32 | 'actions' => ['signup'],
33 | 'allow' => true,
34 | 'roles' => ['?'],
35 | ],
36 | [
37 | 'actions' => ['logout'],
38 | 'allow' => true,
39 | 'roles' => ['@'],
40 | ],
41 | ],
42 | ],
43 | 'verbs' => [
44 | 'class' => VerbFilter::className(),
45 | 'actions' => [
46 | 'logout' => ['post'],
47 | ],
48 | ],
49 | ];
50 | }
51 |
52 | /**
53 | * @inheritdoc
54 | */
55 | public function actions()
56 | {
57 | return [
58 | 'error' => [
59 | 'class' => 'yii\web\ErrorAction',
60 | ],
61 | 'captcha' => [
62 | 'class' => 'yii\captcha\CaptchaAction',
63 | 'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null,
64 | ],
65 | ];
66 | }
67 |
68 | public function actionIndex()
69 | {
70 | return $this->render('index');
71 | }
72 |
73 | public function actionLogin()
74 | {
75 | if (!\Yii::$app->user->isGuest) {
76 | return $this->goHome();
77 | }
78 |
79 | $model = new LoginForm();
80 | if ($model->load(Yii::$app->request->post()) && $model->login()) {
81 | return $this->goBack();
82 | } else {
83 | return $this->render('login', [
84 | 'model' => $model,
85 | ]);
86 | }
87 | }
88 |
89 | public function actionLogout()
90 | {
91 | Yii::$app->user->logout();
92 |
93 | return $this->goHome();
94 | }
95 |
96 | public function actionContact()
97 | {
98 | $model = new ContactForm();
99 | if ($model->load(Yii::$app->request->post()) && $model->validate()) {
100 | if ($model->sendEmail(Yii::$app->params['adminEmail'])) {
101 | Yii::$app->session->setFlash('success', 'Thank you for contacting us. We will respond to you as soon as possible.');
102 | } else {
103 | Yii::$app->session->setFlash('error', 'There was an error sending email.');
104 | }
105 |
106 | return $this->refresh();
107 | } else {
108 | return $this->render('contact', [
109 | 'model' => $model,
110 | ]);
111 | }
112 | }
113 |
114 | public function actionAbout()
115 | {
116 | return $this->render('about');
117 | }
118 |
119 | public function actionSignup()
120 | {
121 | $model = new SignupForm();
122 | if ($model->load(Yii::$app->request->post())) {
123 | if ($user = $model->signup()) {
124 | if (Yii::$app->getUser()->login($user)) {
125 | return $this->goHome();
126 | }
127 | }
128 | }
129 |
130 | return $this->render('signup', [
131 | 'model' => $model,
132 | ]);
133 | }
134 |
135 | public function actionRequestPasswordReset()
136 | {
137 | $model = new PasswordResetRequestForm();
138 | if ($model->load(Yii::$app->request->post()) && $model->validate()) {
139 | if ($model->sendEmail()) {
140 | Yii::$app->getSession()->setFlash('success', 'Check your email for further instructions.');
141 |
142 | return $this->goHome();
143 | } else {
144 | Yii::$app->getSession()->setFlash('error', 'Sorry, we are unable to reset password for email provided.');
145 | }
146 | }
147 |
148 | return $this->render('requestPasswordResetToken', [
149 | 'model' => $model,
150 | ]);
151 | }
152 |
153 | public function actionResetPassword($token)
154 | {
155 | try {
156 | $model = new ResetPasswordForm($token);
157 | } catch (InvalidParamException $e) {
158 | throw new BadRequestHttpException($e->getMessage());
159 | }
160 |
161 | if ($model->load(Yii::$app->request->post()) && $model->validate() && $model->resetPassword()) {
162 | Yii::$app->getSession()->setFlash('success', 'New password was saved.');
163 |
164 | return $this->goHome();
165 | }
166 |
167 | return $this->render('resetPassword', [
168 | 'model' => $model,
169 | ]);
170 | }
171 | }
172 |
--------------------------------------------------------------------------------
/requirements.php:
--------------------------------------------------------------------------------
1 | Error';
18 | echo 'The path to yii framework seems to be incorrect.
';
19 | echo 'You need to install Yii framework via composer or adjust the framework path in file ' . basename(__FILE__) . '.
';
20 | echo 'Please refer to the README on how to install Yii.
';
21 | }
22 |
23 | require_once($frameworkPath . '/requirements/YiiRequirementChecker.php');
24 | $requirementsChecker = new YiiRequirementChecker();
25 |
26 | $gdMemo = $imagickMemo = 'Either GD PHP extension with FreeType support or ImageMagick PHP extension with PNG support is required for image CAPTCHA.';
27 | $gdOK = $imagickOK = false;
28 |
29 | if (extension_loaded('imagick')) {
30 | $imagick = new Imagick();
31 | $imagickFormats = $imagick->queryFormats('PNG');
32 | if (in_array('PNG', $imagickFormats)) {
33 | $imagickOK = true;
34 | } else {
35 | $imagickMemo = 'Imagick extension should be installed with PNG support in order to be used for image CAPTCHA.';
36 | }
37 | }
38 |
39 | if (extension_loaded('gd')) {
40 | $gdInfo = gd_info();
41 | if (!empty($gdInfo['FreeType Support'])) {
42 | $gdOK = true;
43 | } else {
44 | $gdMemo = 'GD extension should be installed with FreeType support in order to be used for image CAPTCHA.';
45 | }
46 | }
47 |
48 | /**
49 | * Adjust requirements according to your application specifics.
50 | */
51 | $requirements = array(
52 | // Database :
53 | array(
54 | 'name' => 'PDO extension',
55 | 'mandatory' => true,
56 | 'condition' => extension_loaded('pdo'),
57 | 'by' => 'All DB-related classes',
58 | ),
59 | array(
60 | 'name' => 'PDO SQLite extension',
61 | 'mandatory' => false,
62 | 'condition' => extension_loaded('pdo_sqlite'),
63 | 'by' => 'All DB-related classes',
64 | 'memo' => 'Required for SQLite database.',
65 | ),
66 | array(
67 | 'name' => 'PDO MySQL extension',
68 | 'mandatory' => false,
69 | 'condition' => extension_loaded('pdo_mysql'),
70 | 'by' => 'All DB-related classes',
71 | 'memo' => 'Required for MySQL database.',
72 | ),
73 | array(
74 | 'name' => 'PDO PostgreSQL extension',
75 | 'mandatory' => false,
76 | 'condition' => extension_loaded('pdo_pgsql'),
77 | 'by' => 'All DB-related classes',
78 | 'memo' => 'Required for PostgreSQL database.',
79 | ),
80 | // Cache :
81 | array(
82 | 'name' => 'Memcache extension',
83 | 'mandatory' => false,
84 | 'condition' => extension_loaded('memcache') || extension_loaded('memcached'),
85 | 'by' => 'MemCache',
86 | 'memo' => extension_loaded('memcached') ? 'To use memcached set MemCache::useMemcached to true.' : ''
87 | ),
88 | array(
89 | 'name' => 'APC extension',
90 | 'mandatory' => false,
91 | 'condition' => extension_loaded('apc'),
92 | 'by' => 'ApcCache',
93 | ),
94 | // CAPTCHA:
95 | array(
96 | 'name' => 'GD PHP extension with FreeType support',
97 | 'mandatory' => false,
98 | 'condition' => $gdOK,
99 | 'by' => 'Captcha',
100 | 'memo' => $gdMemo,
101 | ),
102 | array(
103 | 'name' => 'ImageMagick PHP extension with PNG support',
104 | 'mandatory' => false,
105 | 'condition' => $imagickOK,
106 | 'by' => 'Captcha',
107 | 'memo' => $imagickMemo,
108 | ),
109 | // PHP ini :
110 | 'phpExposePhp' => array(
111 | 'name' => 'Expose PHP',
112 | 'mandatory' => false,
113 | 'condition' => $requirementsChecker->checkPhpIniOff("expose_php"),
114 | 'by' => 'Security reasons',
115 | 'memo' => '"expose_php" should be disabled at php.ini',
116 | ),
117 | 'phpAllowUrlInclude' => array(
118 | 'name' => 'PHP allow url include',
119 | 'mandatory' => false,
120 | 'condition' => $requirementsChecker->checkPhpIniOff("allow_url_include"),
121 | 'by' => 'Security reasons',
122 | 'memo' => '"allow_url_include" should be disabled at php.ini',
123 | ),
124 | 'phpSmtp' => array(
125 | 'name' => 'PHP mail SMTP',
126 | 'mandatory' => false,
127 | 'condition' => strlen(ini_get('SMTP')) > 0,
128 | 'by' => 'Email sending',
129 | 'memo' => 'PHP mail SMTP server required',
130 | ),
131 | );
132 | $requirementsChecker->checkYii()->check($requirements)->render();
133 |
--------------------------------------------------------------------------------
/init:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env php
2 |
11 | *
12 | * @link http://www.yiiframework.com/
13 | * @copyright Copyright (c) 2008 Yii Software LLC
14 | * @license http://www.yiiframework.com/license/
15 | */
16 |
17 | if (!extension_loaded('openssl')) {
18 | die('The OpenSSL PHP extension is required by Yii2.');
19 | }
20 |
21 | $params = getParams();
22 | $root = str_replace('\\', '/', __DIR__);
23 | $envs = require("$root/environments/index.php");
24 | $envNames = array_keys($envs);
25 |
26 | echo "Yii Application Initialization Tool v1.0\n\n";
27 |
28 | $envName = null;
29 | if (empty($params['env']) || $params['env'] === '1') {
30 | echo "Which environment do you want the application to be initialized in?\n\n";
31 | foreach ($envNames as $i => $name) {
32 | echo " [$i] $name\n";
33 | }
34 | echo "\n Your choice [0-" . (count($envs) - 1) . ', or "q" to quit] ';
35 | $answer = trim(fgets(STDIN));
36 |
37 | if (!ctype_digit($answer) || !in_array($answer, range(0, count($envs) - 1))) {
38 | echo "\n Quit initialization.\n";
39 | exit(0);
40 | }
41 |
42 | if (isset($envNames[$answer])) {
43 | $envName = $envNames[$answer];
44 | }
45 | } else {
46 | $envName = $params['env'];
47 | }
48 |
49 | if (!in_array($envName, $envNames)) {
50 | $envsList = implode(', ', $envNames);
51 | echo "\n $envName is not a valid environment. Try one of the following: $envsList. \n";
52 | exit(2);
53 | }
54 |
55 | $env = $envs[$envName];
56 |
57 | if (empty($params['env'])) {
58 | echo "\n Initialize the application under '{$envNames[$answer]}' environment? [yes|no] ";
59 | $answer = trim(fgets(STDIN));
60 | if (strncasecmp($answer, 'y', 1)) {
61 | echo "\n Quit initialization.\n";
62 | exit(0);
63 | }
64 | }
65 |
66 | echo "\n Start initialization ...\n\n";
67 | $files = getFileList("$root/environments/{$env['path']}");
68 | if (isset($env['skipFiles'])) {
69 | $skipFiles = $env['skipFiles'];
70 | array_walk($skipFiles, function(&$value) use($env, $root) { $value = "$root/$value"; });
71 | $files = array_diff($files, array_intersect_key($env['skipFiles'], array_filter($skipFiles, 'file_exists')));
72 | }
73 | $all = false;
74 | foreach ($files as $file) {
75 | if (!copyFile($root, "environments/{$env['path']}/$file", $file, $all, $params)) {
76 | break;
77 | }
78 | }
79 |
80 | $callbacks = ['setCookieValidationKey', 'setWritable', 'setExecutable', 'createSymlink'];
81 | foreach ($callbacks as $callback) {
82 | if (!empty($env[$callback])) {
83 | $callback($root, $env[$callback]);
84 | }
85 | }
86 |
87 | echo "\n ... initialization completed.\n\n";
88 |
89 | function getFileList($root, $basePath = '')
90 | {
91 | $files = [];
92 | $handle = opendir($root);
93 | while (($path = readdir($handle)) !== false) {
94 | if ($path === '.git' || $path === '.svn' || $path === '.' || $path === '..') {
95 | continue;
96 | }
97 | $fullPath = "$root/$path";
98 | $relativePath = $basePath === '' ? $path : "$basePath/$path";
99 | if (is_dir($fullPath)) {
100 | $files = array_merge($files, getFileList($fullPath, $relativePath));
101 | } else {
102 | $files[] = $relativePath;
103 | }
104 | }
105 | closedir($handle);
106 | return $files;
107 | }
108 |
109 | function copyFile($root, $source, $target, &$all, $params)
110 | {
111 | if (!is_file($root . '/' . $source)) {
112 | echo " skip $target ($source not exist)\n";
113 | return true;
114 | }
115 | if (is_file($root . '/' . $target)) {
116 | if (file_get_contents($root . '/' . $source) === file_get_contents($root . '/' . $target)) {
117 | echo " unchanged $target\n";
118 | return true;
119 | }
120 | if ($all) {
121 | echo " overwrite $target\n";
122 | } else {
123 | echo " exist $target\n";
124 | echo " ...overwrite? [Yes|No|All|Quit] ";
125 |
126 |
127 | $answer = !empty($params['overwrite']) ? $params['overwrite'] : trim(fgets(STDIN));
128 | if (!strncasecmp($answer, 'q', 1)) {
129 | return false;
130 | } else {
131 | if (!strncasecmp($answer, 'y', 1)) {
132 | echo " overwrite $target\n";
133 | } else {
134 | if (!strncasecmp($answer, 'a', 1)) {
135 | echo " overwrite $target\n";
136 | $all = true;
137 | } else {
138 | echo " skip $target\n";
139 | return true;
140 | }
141 | }
142 | }
143 | }
144 | file_put_contents($root . '/' . $target, file_get_contents($root . '/' . $source));
145 | return true;
146 | }
147 | echo " generate $target\n";
148 | @mkdir(dirname($root . '/' . $target), 0777, true);
149 | file_put_contents($root . '/' . $target, file_get_contents($root . '/' . $source));
150 | return true;
151 | }
152 |
153 | function getParams()
154 | {
155 | $rawParams = [];
156 | if (isset($_SERVER['argv'])) {
157 | $rawParams = $_SERVER['argv'];
158 | array_shift($rawParams);
159 | }
160 |
161 | $params = [];
162 | foreach ($rawParams as $param) {
163 | if (preg_match('/^--(\w+)(=(.*))?$/', $param, $matches)) {
164 | $name = $matches[1];
165 | $params[$name] = isset($matches[3]) ? $matches[3] : true;
166 | } else {
167 | $params[] = $param;
168 | }
169 | }
170 | return $params;
171 | }
172 |
173 | function setWritable($root, $paths)
174 | {
175 | foreach ($paths as $writable) {
176 | echo " chmod 0777 $writable\n";
177 | @chmod("$root/$writable", 0777);
178 | }
179 | }
180 |
181 | function setExecutable($root, $paths)
182 | {
183 | foreach ($paths as $executable) {
184 | echo " chmod 0755 $executable\n";
185 | @chmod("$root/$executable", 0755);
186 | }
187 | }
188 |
189 | function setCookieValidationKey($root, $paths)
190 | {
191 | foreach ($paths as $file) {
192 | echo " generate cookie validation key in $file\n";
193 | $file = $root . '/' . $file;
194 | $length = 32;
195 | $bytes = openssl_random_pseudo_bytes($length);
196 | $key = strtr(substr(base64_encode($bytes), 0, $length), '+/=', '_-.');
197 | $content = preg_replace('/(("|\')cookieValidationKey("|\')\s*=>\s*)(""|\'\')/', "\\1'$key'", file_get_contents($file));
198 | file_put_contents($file, $content);
199 | }
200 | }
201 |
202 | function createSymlink($root, $links) {
203 | foreach ($links as $link => $target) {
204 | echo " symlink " . $root . "/" . $target . " " . $root . "/" . $link . "\n";
205 | //first removing folders to avoid errors if the folder already exists
206 | @rmdir($root . "/" . $link);
207 | @symlink($root . "/" . $target, $root . "/" . $link);
208 | }
209 | }
210 |
--------------------------------------------------------------------------------