├── .bowerrc ├── .gitignore ├── LICENSE.md ├── README.md ├── assets └── AppAsset.php ├── commands └── HelloController.php ├── composer.json ├── composer.lock ├── config ├── assets-prod.php ├── console.php ├── db.php ├── params.php └── web.php ├── controllers └── SiteController.php ├── mail └── layouts │ └── html.php ├── models ├── ContactForm.php ├── LoginForm.php └── User.php ├── requirements.php ├── runtime └── .gitignore ├── tests ├── README.md ├── codeception.yml └── codeception │ ├── .gitignore │ ├── _bootstrap.php │ ├── _output │ └── .gitignore │ ├── _pages │ ├── AboutPage.php │ ├── ContactPage.php │ └── LoginPage.php │ ├── acceptance.suite.yml │ ├── acceptance │ ├── AboutCept.php │ ├── ContactCept.php │ ├── HomeCept.php │ ├── LoginCept.php │ └── _bootstrap.php │ ├── bin │ ├── _bootstrap.php │ ├── yii │ └── yii.bat │ ├── config │ ├── acceptance.php │ ├── config.php │ ├── functional.php │ └── unit.php │ ├── fixtures │ └── .gitignore │ ├── functional.suite.yml │ ├── functional │ ├── AboutCept.php │ ├── ContactCept.php │ ├── HomeCept.php │ ├── LoginCept.php │ └── _bootstrap.php │ ├── templates │ └── .gitignore │ ├── unit.suite.yml │ └── unit │ ├── _bootstrap.php │ ├── fixtures │ ├── .gitkeep │ └── data │ │ └── .gitkeep │ ├── models │ ├── ContactFormTest.php │ ├── LoginFormTest.php │ └── UserTest.php │ └── templates │ └── fixtures │ └── .gitkeep ├── tools └── gulp │ ├── assets-config.php │ ├── gulpfile.js │ ├── node_modules │ └── .gitignore │ └── package.json ├── views ├── layouts │ └── main.php └── site │ ├── about.php │ ├── contact.php │ ├── error.php │ ├── index.php │ └── login.php ├── web ├── assets │ └── .gitignore ├── css │ └── site.css ├── favicon.ico ├── index-test.php ├── index.php └── robots.txt ├── yii └── yii.bat /.bowerrc: -------------------------------------------------------------------------------- 1 | { 2 | "directory" : "vendor/bower" 3 | } 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # phpstorm project files 2 | .idea 3 | 4 | # netbeans project files 5 | nbproject 6 | 7 | # zend studio for eclipse project files 8 | .buildpath 9 | .project 10 | .settings 11 | 12 | # windows thumbnail cache 13 | Thumbs.db 14 | 15 | # composer vendor dir 16 | /vendor 17 | 18 | # composer itself is not needed 19 | composer.phar 20 | 21 | # Mac DS_Store Files 22 | .DS_Store 23 | 24 | # phpunit itself is not needed 25 | phpunit.phar 26 | # local phpunit config 27 | /phpunit.xml 28 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Yii2 and Gulp 2 | Simple app with working Yii2 asset command and Gulp. 3 | 4 | This is configured [yiisoft/yii2-app-basic](https://github.com/yiisoft/yii2-app-basic) which uses Gulp. 5 | 6 | ## App installation 7 | 8 | * Install NodeJS from [here](http://nodejs.org/) 9 | * Install Gulp globaly ``npm install -g gulp``. 10 | * IMPORTANT: Make sure that Gulp works fine. Check it with ``gulp --version``, if it works you should see something like ``CLI version 3.8.11`` 11 | * Clone this repository 12 | ``git clone https://github.com/lukicdarkoo/yii2-and-gulp.git`` 13 | * Navigate to ``/yii2-and-gulp`` and run ``composer update --prefer-dist`` 14 | * Navigate to ``/yii2-and-gulp/tools/gulp`` and run ``npm update`` 15 | * To generate combined and compressed *.js and *.css files navigate to ``/yii2-and-gulp`` and run ``yii asset tools/gulp/assets-config.php config/assets-prod.php`` 16 | * FINISH! Run app and check source code, you should see only one *.js and one *.css file, combined and compressed. 17 | 18 | 19 | ## Integrate to your app 20 | 21 | * Copy directory ``/tools`` to your application 22 | * Change **bundles** and **targets** for your needs in ``/tools/grunt/assets-config.php``, check Yii2 Guide [Using the asset Command](http://www.yiiframework.com/doc-2.0/guide-structure-assets.html#using-the-asset-command) 23 | * Configure component to your config file: 24 | ``` 25 | 'assetManager' => [ 26 | 'bundles' => require(__DIR__ . '/' . 'assets-prod.php' ), 27 | ], 28 | ``` 29 | * Install NodeJS from [here](http://nodejs.org/) 30 | * Install Gulp globaly ``npm install -g gulp``. 31 | * IMPORTANT: Make sure does Gulp work fine. Check it with ``gulp --version``, if it works you should see something like ``CLI version 3.8.11`` 32 | * Navigate to ``/your-app-root/tools/gulp`` and run ``npm update`` 33 | * To generate combined and compressed *.js and *.css files navigate to ``/your-app-root`` and run ``yii asset tools/gulp/assets-config.php config/assets-prod.php`` 34 | * FINISH! Run app and check source code, you should see only one *.js and one *.css file, combined and compressed. 35 | -------------------------------------------------------------------------------- /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 $jsOptions = [ 26 | 'position' => \yii\web\View::POS_HEAD 27 | ]; 28 | public $depends = [ 29 | 'yii\web\YiiAsset', 30 | 'yii\bootstrap\BootstrapAsset', 31 | ]; 32 | } 33 | -------------------------------------------------------------------------------- /commands/HelloController.php: -------------------------------------------------------------------------------- 1 | 18 | * @since 2.0 19 | */ 20 | class HelloController extends Controller 21 | { 22 | /** 23 | * This command echoes what you have entered as the message. 24 | * @param string $message the message to be echoed. 25 | */ 26 | public function actionIndex($message = 'hello world') 27 | { 28 | echo $message . "\n"; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "lukicdarkoo/yii2-and-gulp", 3 | "description": "Yii 2 Basic Application and Gulp", 4 | "keywords": ["yii2", "gulp"], 5 | "homepage": "http://www.yiiframework.com/", 6 | "type": "project", 7 | "license": "BSD-3-Clause", 8 | "support": { 9 | "issues": "https://github.com/lukicdarkoo/yii2-and-gulp/issues", 10 | "source": "https://github.com/lukicdarkoo/yii2-and-gulp" 11 | }, 12 | "minimum-stability": "dev", 13 | "require": { 14 | "php": ">=5.4.0", 15 | "yiisoft/yii2": "*", 16 | "yiisoft/yii2-bootstrap": "*", 17 | "yiisoft/yii2-swiftmailer": "*" 18 | }, 19 | "require-dev": { 20 | "yiisoft/yii2-codeception": "*", 21 | "yiisoft/yii2-debug": "*", 22 | "yiisoft/yii2-gii": "*", 23 | "yiisoft/yii2-faker": "*" 24 | }, 25 | "config": { 26 | "process-timeout": 1800 27 | }, 28 | "scripts": { 29 | "post-create-project-cmd": [ 30 | "yii\\composer\\Installer::postCreateProject" 31 | ] 32 | }, 33 | "extra": { 34 | "yii\\composer\\Installer::postCreateProject": { 35 | "setPermission": [ 36 | { 37 | "runtime": "0777", 38 | "web/assets": "0777", 39 | "yii": "0755" 40 | } 41 | ], 42 | "generateCookieValidationKey": [ 43 | "config/web.php" 44 | ] 45 | }, 46 | "asset-installer-paths": { 47 | "npm-asset-library": "vendor/npm", 48 | "bower-asset-library": "vendor/bower" 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /composer.lock: -------------------------------------------------------------------------------- 1 | { 2 | "_readme": [ 3 | "This file locks the dependencies of your project to a known state", 4 | "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", 5 | "This file is @generated automatically" 6 | ], 7 | "hash": "80f4231ab64bee3ffb22c87bfdc3a50c", 8 | "packages": [ 9 | { 10 | "name": "bower-asset/bootstrap", 11 | "version": "v3.3.2", 12 | "source": { 13 | "type": "git", 14 | "url": "https://github.com/twbs/bootstrap.git", 15 | "reference": "bcf7dd38b5ab180256e2e4fb5da0369551b3f082" 16 | }, 17 | "dist": { 18 | "type": "zip", 19 | "url": "https://api.github.com/repos/twbs/bootstrap/zipball/bcf7dd38b5ab180256e2e4fb5da0369551b3f082", 20 | "reference": "bcf7dd38b5ab180256e2e4fb5da0369551b3f082", 21 | "shasum": "" 22 | }, 23 | "require": { 24 | "bower-asset/jquery": ">=1.9.1" 25 | }, 26 | "type": "bower-asset-library", 27 | "extra": { 28 | "bower-asset-main": [ 29 | "less/bootstrap.less", 30 | "dist/css/bootstrap.css", 31 | "dist/js/bootstrap.js", 32 | "dist/fonts/glyphicons-halflings-regular.eot", 33 | "dist/fonts/glyphicons-halflings-regular.svg", 34 | "dist/fonts/glyphicons-halflings-regular.ttf", 35 | "dist/fonts/glyphicons-halflings-regular.woff" 36 | ], 37 | "bower-asset-ignore": [ 38 | "/.*", 39 | "_config.yml", 40 | "CNAME", 41 | "composer.json", 42 | "CONTRIBUTING.md", 43 | "docs", 44 | "js/tests", 45 | "test-infra" 46 | ] 47 | }, 48 | "description": "The most popular front-end framework for developing responsive, mobile first projects on the web.", 49 | "keywords": [ 50 | "css", 51 | "framework", 52 | "front-end", 53 | "js", 54 | "less", 55 | "mobile-first", 56 | "responsive", 57 | "web" 58 | ] 59 | }, 60 | { 61 | "name": "bower-asset/jquery", 62 | "version": "2.1.3", 63 | "source": { 64 | "type": "git", 65 | "url": "https://github.com/jquery/jquery.git", 66 | "reference": "8f2a9d9272d6ed7f32d3a484740ab342c02541e0" 67 | }, 68 | "dist": { 69 | "type": "zip", 70 | "url": "https://api.github.com/repos/jquery/jquery/zipball/8f2a9d9272d6ed7f32d3a484740ab342c02541e0", 71 | "reference": "8f2a9d9272d6ed7f32d3a484740ab342c02541e0", 72 | "shasum": "" 73 | }, 74 | "require-dev": { 75 | "bower-asset/qunit": "1.14.0", 76 | "bower-asset/requirejs": "2.1.10", 77 | "bower-asset/sinon": "1.8.1", 78 | "bower-asset/sizzle": "2.1.1-patch2" 79 | }, 80 | "type": "bower-asset-library", 81 | "extra": { 82 | "bower-asset-main": "dist/jquery.js", 83 | "bower-asset-ignore": [ 84 | "**/.*", 85 | "build", 86 | "speed", 87 | "test", 88 | "*.md", 89 | "AUTHORS.txt", 90 | "Gruntfile.js", 91 | "package.json" 92 | ] 93 | }, 94 | "license": [ 95 | "MIT" 96 | ], 97 | "keywords": [ 98 | "javascript", 99 | "jquery", 100 | "library" 101 | ] 102 | }, 103 | { 104 | "name": "bower-asset/jquery.inputmask", 105 | "version": "3.1.61", 106 | "source": { 107 | "type": "git", 108 | "url": "https://github.com/RobinHerbots/jquery.inputmask.git", 109 | "reference": "f2c086411d2557fc485c47afb3cecfa6c1de9ee2" 110 | }, 111 | "dist": { 112 | "type": "zip", 113 | "url": "https://api.github.com/repos/RobinHerbots/jquery.inputmask/zipball/f2c086411d2557fc485c47afb3cecfa6c1de9ee2", 114 | "reference": "f2c086411d2557fc485c47afb3cecfa6c1de9ee2", 115 | "shasum": "" 116 | }, 117 | "require": { 118 | "bower-asset/jquery": ">=1.7" 119 | }, 120 | "type": "bower-asset-library", 121 | "extra": { 122 | "bower-asset-main": [ 123 | "./dist/inputmask/jquery.inputmask.js", 124 | "./dist/inputmask/jquery.inputmask.extensions.js", 125 | "./dist/inputmask/jquery.inputmask.date.extensions.js", 126 | "./dist/inputmask/jquery.inputmask.numeric.extensions.js", 127 | "./dist/inputmask/jquery.inputmask.phone.extensions.js", 128 | "./dist/inputmask/jquery.inputmask.regex.extensions.js" 129 | ], 130 | "bower-asset-ignore": [ 131 | "**/.*", 132 | "qunit/", 133 | "nuget/", 134 | "tools/", 135 | "js/", 136 | "*.md", 137 | "build.properties", 138 | "build.xml", 139 | "jquery.inputmask.jquery.json" 140 | ] 141 | }, 142 | "license": [ 143 | "http://opensource.org/licenses/mit-license.php" 144 | ], 145 | "description": "jquery.inputmask is a jquery plugin which create an input mask.", 146 | "keywords": [ 147 | "form", 148 | "input", 149 | "inputmask", 150 | "jquery", 151 | "mask", 152 | "plugins" 153 | ] 154 | }, 155 | { 156 | "name": "bower-asset/punycode", 157 | "version": "v1.3.2", 158 | "source": { 159 | "type": "git", 160 | "url": "https://github.com/bestiejs/punycode.js.git", 161 | "reference": "38c8d3131a82567bfef18da09f7f4db68c84f8a3" 162 | }, 163 | "dist": { 164 | "type": "zip", 165 | "url": "https://api.github.com/repos/bestiejs/punycode.js/zipball/38c8d3131a82567bfef18da09f7f4db68c84f8a3", 166 | "reference": "38c8d3131a82567bfef18da09f7f4db68c84f8a3", 167 | "shasum": "" 168 | }, 169 | "type": "bower-asset-library", 170 | "extra": { 171 | "bower-asset-main": "punycode.js", 172 | "bower-asset-ignore": [ 173 | "coverage", 174 | "tests", 175 | ".*", 176 | "component.json", 177 | "Gruntfile.js", 178 | "node_modules", 179 | "package.json" 180 | ] 181 | } 182 | }, 183 | { 184 | "name": "bower-asset/yii2-pjax", 185 | "version": "dev-master", 186 | "source": { 187 | "type": "git", 188 | "url": "https://github.com/yiisoft/jquery-pjax.git", 189 | "reference": "b7491aec282bfd2e78faf33b18df865299b88d36" 190 | }, 191 | "dist": { 192 | "type": "zip", 193 | "url": "https://api.github.com/repos/yiisoft/jquery-pjax/zipball/b7491aec282bfd2e78faf33b18df865299b88d36", 194 | "reference": "b7491aec282bfd2e78faf33b18df865299b88d36", 195 | "shasum": "" 196 | }, 197 | "require": { 198 | "bower-asset/jquery": ">=1.8" 199 | }, 200 | "type": "bower-asset-library", 201 | "extra": { 202 | "bower-asset-main": "./jquery.pjax.js", 203 | "bower-asset-ignore": [ 204 | ".travis.yml", 205 | "Gemfile", 206 | "Gemfile.lock", 207 | "vendor/", 208 | "script/", 209 | "test/" 210 | ], 211 | "branch-alias": { 212 | "dev-master": "2.0.2-dev" 213 | } 214 | }, 215 | "license": [ 216 | "MIT" 217 | ] 218 | }, 219 | { 220 | "name": "cebe/markdown", 221 | "version": "dev-master", 222 | "source": { 223 | "type": "git", 224 | "url": "https://github.com/cebe/markdown.git", 225 | "reference": "f89dc1da1fc6823f0286d6cad736a642efd0f59e" 226 | }, 227 | "dist": { 228 | "type": "zip", 229 | "url": "https://api.github.com/repos/cebe/markdown/zipball/f89dc1da1fc6823f0286d6cad736a642efd0f59e", 230 | "reference": "f89dc1da1fc6823f0286d6cad736a642efd0f59e", 231 | "shasum": "" 232 | }, 233 | "require": { 234 | "lib-pcre": "*", 235 | "php": ">=5.4.0" 236 | }, 237 | "require-dev": { 238 | "cebe/indent": "*", 239 | "facebook/xhprof": "*@dev", 240 | "phpunit/phpunit": "3.7.*" 241 | }, 242 | "bin": [ 243 | "bin/markdown" 244 | ], 245 | "type": "library", 246 | "extra": { 247 | "branch-alias": { 248 | "dev-master": "1.0.x-dev" 249 | } 250 | }, 251 | "autoload": { 252 | "psr-4": { 253 | "cebe\\markdown\\": "" 254 | } 255 | }, 256 | "notification-url": "https://packagist.org/downloads/", 257 | "license": [ 258 | "MIT" 259 | ], 260 | "authors": [ 261 | { 262 | "name": "Carsten Brandt", 263 | "email": "mail@cebe.cc", 264 | "homepage": "http://cebe.cc/", 265 | "role": "Creator" 266 | } 267 | ], 268 | "description": "A super fast, highly extensible markdown parser for PHP", 269 | "homepage": "https://github.com/cebe/markdown#readme", 270 | "keywords": [ 271 | "extensible", 272 | "fast", 273 | "gfm", 274 | "markdown", 275 | "markdown-extra" 276 | ], 277 | "time": "2014-12-18 00:45:32" 278 | }, 279 | { 280 | "name": "ezyang/htmlpurifier", 281 | "version": "v4.6.0", 282 | "source": { 283 | "type": "git", 284 | "url": "https://github.com/ezyang/htmlpurifier.git", 285 | "reference": "6f389f0f25b90d0b495308efcfa073981177f0fd" 286 | }, 287 | "dist": { 288 | "type": "zip", 289 | "url": "https://api.github.com/repos/ezyang/htmlpurifier/zipball/6f389f0f25b90d0b495308efcfa073981177f0fd", 290 | "reference": "6f389f0f25b90d0b495308efcfa073981177f0fd", 291 | "shasum": "" 292 | }, 293 | "require": { 294 | "php": ">=5.2" 295 | }, 296 | "type": "library", 297 | "autoload": { 298 | "psr-0": { 299 | "HTMLPurifier": "library/" 300 | }, 301 | "files": [ 302 | "library/HTMLPurifier.composer.php" 303 | ] 304 | }, 305 | "notification-url": "https://packagist.org/downloads/", 306 | "license": [ 307 | "LGPL" 308 | ], 309 | "authors": [ 310 | { 311 | "name": "Edward Z. Yang", 312 | "email": "admin@htmlpurifier.org", 313 | "homepage": "http://ezyang.com" 314 | } 315 | ], 316 | "description": "Standards compliant HTML filter written in PHP", 317 | "homepage": "http://htmlpurifier.org/", 318 | "keywords": [ 319 | "html" 320 | ], 321 | "time": "2013-11-30 08:25:19" 322 | }, 323 | { 324 | "name": "swiftmailer/swiftmailer", 325 | "version": "dev-master", 326 | "source": { 327 | "type": "git", 328 | "url": "https://github.com/swiftmailer/swiftmailer.git", 329 | "reference": "db95cfa68a8bc91d1c54f75c416f481c9a8bd100" 330 | }, 331 | "dist": { 332 | "type": "zip", 333 | "url": "https://api.github.com/repos/swiftmailer/swiftmailer/zipball/db95cfa68a8bc91d1c54f75c416f481c9a8bd100", 334 | "reference": "db95cfa68a8bc91d1c54f75c416f481c9a8bd100", 335 | "shasum": "" 336 | }, 337 | "require": { 338 | "php": ">=5.3.3" 339 | }, 340 | "require-dev": { 341 | "mockery/mockery": "~0.9.1" 342 | }, 343 | "type": "library", 344 | "extra": { 345 | "branch-alias": { 346 | "dev-master": "5.3-dev" 347 | } 348 | }, 349 | "autoload": { 350 | "files": [ 351 | "lib/swift_required.php" 352 | ] 353 | }, 354 | "notification-url": "https://packagist.org/downloads/", 355 | "license": [ 356 | "MIT" 357 | ], 358 | "authors": [ 359 | { 360 | "name": "Chris Corbyn" 361 | }, 362 | { 363 | "name": "Fabien Potencier", 364 | "email": "fabien@symfony.com" 365 | } 366 | ], 367 | "description": "Swiftmailer, free feature-rich PHP mailer", 368 | "homepage": "http://swiftmailer.org", 369 | "keywords": [ 370 | "mail", 371 | "mailer" 372 | ], 373 | "time": "2015-01-18 13:49:36" 374 | }, 375 | { 376 | "name": "yiisoft/yii2", 377 | "version": "dev-master", 378 | "source": { 379 | "type": "git", 380 | "url": "https://github.com/yiisoft/yii2-framework.git", 381 | "reference": "f2c3cba2947a1dc3a3997288bd3affda2452ad73" 382 | }, 383 | "dist": { 384 | "type": "zip", 385 | "url": "https://api.github.com/repos/yiisoft/yii2-framework/zipball/f2c3cba2947a1dc3a3997288bd3affda2452ad73", 386 | "reference": "f2c3cba2947a1dc3a3997288bd3affda2452ad73", 387 | "shasum": "" 388 | }, 389 | "require": { 390 | "bower-asset/jquery": "2.1.*@stable | 1.11.*@stable", 391 | "bower-asset/jquery.inputmask": "3.1.*", 392 | "bower-asset/punycode": "1.3.*", 393 | "bower-asset/yii2-pjax": ">=2.0.1", 394 | "cebe/markdown": "~1.0.0", 395 | "ext-mbstring": "*", 396 | "ezyang/htmlpurifier": "4.6.*", 397 | "lib-pcre": "*", 398 | "php": ">=5.4.0", 399 | "yiisoft/yii2-composer": "*" 400 | }, 401 | "bin": [ 402 | "yii" 403 | ], 404 | "type": "library", 405 | "extra": { 406 | "branch-alias": { 407 | "dev-master": "2.0.x-dev" 408 | } 409 | }, 410 | "autoload": { 411 | "psr-4": { 412 | "yii\\": "" 413 | } 414 | }, 415 | "notification-url": "https://packagist.org/downloads/", 416 | "license": [ 417 | "BSD-3-Clause" 418 | ], 419 | "authors": [ 420 | { 421 | "name": "Qiang Xue", 422 | "email": "qiang.xue@gmail.com", 423 | "homepage": "http://www.yiiframework.com/", 424 | "role": "Founder and project lead" 425 | }, 426 | { 427 | "name": "Alexander Makarov", 428 | "email": "sam@rmcreative.ru", 429 | "homepage": "http://rmcreative.ru/", 430 | "role": "Core framework development" 431 | }, 432 | { 433 | "name": "Maurizio Domba", 434 | "homepage": "http://mdomba.info/", 435 | "role": "Core framework development" 436 | }, 437 | { 438 | "name": "Carsten Brandt", 439 | "email": "mail@cebe.cc", 440 | "homepage": "http://cebe.cc/", 441 | "role": "Core framework development" 442 | }, 443 | { 444 | "name": "Timur Ruziev", 445 | "email": "resurtm@gmail.com", 446 | "homepage": "http://resurtm.com/", 447 | "role": "Core framework development" 448 | }, 449 | { 450 | "name": "Paul Klimov", 451 | "email": "klimov.paul@gmail.com", 452 | "role": "Core framework development" 453 | } 454 | ], 455 | "description": "Yii PHP Framework Version 2", 456 | "homepage": "http://www.yiiframework.com/", 457 | "keywords": [ 458 | "framework", 459 | "yii2" 460 | ], 461 | "time": "2015-02-26 18:06:51" 462 | }, 463 | { 464 | "name": "yiisoft/yii2-bootstrap", 465 | "version": "dev-master", 466 | "source": { 467 | "type": "git", 468 | "url": "https://github.com/yiisoft/yii2-bootstrap.git", 469 | "reference": "2ce0254cc3860d65ca5d6a2d6c22e575ee812c2a" 470 | }, 471 | "dist": { 472 | "type": "zip", 473 | "url": "https://api.github.com/repos/yiisoft/yii2-bootstrap/zipball/2ce0254cc3860d65ca5d6a2d6c22e575ee812c2a", 474 | "reference": "2ce0254cc3860d65ca5d6a2d6c22e575ee812c2a", 475 | "shasum": "" 476 | }, 477 | "require": { 478 | "bower-asset/bootstrap": "3.3.* | 3.2.* | 3.1.*", 479 | "yiisoft/yii2": "~2.0.0" 480 | }, 481 | "type": "yii2-extension", 482 | "extra": { 483 | "branch-alias": { 484 | "dev-master": "2.0.x-dev" 485 | } 486 | }, 487 | "autoload": { 488 | "psr-4": { 489 | "yii\\bootstrap\\": "" 490 | } 491 | }, 492 | "notification-url": "https://packagist.org/downloads/", 493 | "license": [ 494 | "BSD-3-Clause" 495 | ], 496 | "authors": [ 497 | { 498 | "name": "Qiang Xue", 499 | "email": "qiang.xue@gmail.com" 500 | } 501 | ], 502 | "description": "The Twitter Bootstrap extension for the Yii framework", 503 | "keywords": [ 504 | "bootstrap", 505 | "yii2" 506 | ], 507 | "time": "2015-02-26 10:03:31" 508 | }, 509 | { 510 | "name": "yiisoft/yii2-composer", 511 | "version": "dev-master", 512 | "source": { 513 | "type": "git", 514 | "url": "https://github.com/yiisoft/yii2-composer.git", 515 | "reference": "12e9db0629b51aebc3f0e63f234499a558249de3" 516 | }, 517 | "dist": { 518 | "type": "zip", 519 | "url": "https://api.github.com/repos/yiisoft/yii2-composer/zipball/12e9db0629b51aebc3f0e63f234499a558249de3", 520 | "reference": "12e9db0629b51aebc3f0e63f234499a558249de3", 521 | "shasum": "" 522 | }, 523 | "require": { 524 | "composer-plugin-api": "1.0.0" 525 | }, 526 | "type": "composer-plugin", 527 | "extra": { 528 | "class": "yii\\composer\\Plugin", 529 | "branch-alias": { 530 | "dev-master": "2.0.x-dev" 531 | } 532 | }, 533 | "autoload": { 534 | "psr-4": { 535 | "yii\\composer\\": "" 536 | } 537 | }, 538 | "notification-url": "https://packagist.org/downloads/", 539 | "license": [ 540 | "BSD-3-Clause" 541 | ], 542 | "authors": [ 543 | { 544 | "name": "Qiang Xue", 545 | "email": "qiang.xue@gmail.com" 546 | } 547 | ], 548 | "description": "The composer plugin for Yii extension installer", 549 | "keywords": [ 550 | "composer", 551 | "extension installer", 552 | "yii2" 553 | ], 554 | "time": "2015-02-24 11:03:41" 555 | }, 556 | { 557 | "name": "yiisoft/yii2-swiftmailer", 558 | "version": "dev-master", 559 | "source": { 560 | "type": "git", 561 | "url": "https://github.com/yiisoft/yii2-swiftmailer.git", 562 | "reference": "c3becc8341a9a6eaf0aab22cdcd85bb853272774" 563 | }, 564 | "dist": { 565 | "type": "zip", 566 | "url": "https://api.github.com/repos/yiisoft/yii2-swiftmailer/zipball/c3becc8341a9a6eaf0aab22cdcd85bb853272774", 567 | "reference": "c3becc8341a9a6eaf0aab22cdcd85bb853272774", 568 | "shasum": "" 569 | }, 570 | "require": { 571 | "swiftmailer/swiftmailer": "*", 572 | "yiisoft/yii2": "~2.0.0" 573 | }, 574 | "type": "yii2-extension", 575 | "extra": { 576 | "branch-alias": { 577 | "dev-master": "2.0.x-dev" 578 | } 579 | }, 580 | "autoload": { 581 | "psr-4": { 582 | "yii\\swiftmailer\\": "" 583 | } 584 | }, 585 | "notification-url": "https://packagist.org/downloads/", 586 | "license": [ 587 | "BSD-3-Clause" 588 | ], 589 | "authors": [ 590 | { 591 | "name": "Paul Klimov", 592 | "email": "klimov.paul@gmail.com" 593 | } 594 | ], 595 | "description": "The SwiftMailer integration for the Yii framework", 596 | "keywords": [ 597 | "email", 598 | "mail", 599 | "mailer", 600 | "swift", 601 | "swiftmailer", 602 | "yii2" 603 | ], 604 | "time": "2015-02-26 10:03:31" 605 | } 606 | ], 607 | "packages-dev": [ 608 | { 609 | "name": "bower-asset/typeahead.js", 610 | "version": "v0.10.5", 611 | "source": { 612 | "type": "git", 613 | "url": "https://github.com/twitter/typeahead.js.git", 614 | "reference": "5f198b87d1af845da502ea9df93a5e84801ce742" 615 | }, 616 | "dist": { 617 | "type": "zip", 618 | "url": "https://api.github.com/repos/twitter/typeahead.js/zipball/5f198b87d1af845da502ea9df93a5e84801ce742", 619 | "reference": "5f198b87d1af845da502ea9df93a5e84801ce742", 620 | "shasum": "" 621 | }, 622 | "require": { 623 | "bower-asset/jquery": ">=1.7" 624 | }, 625 | "require-dev": { 626 | "bower-asset/jasmine-ajax": "~1.3.1", 627 | "bower-asset/jasmine-jquery": "~1.5.2", 628 | "bower-asset/jquery": "~1.7" 629 | }, 630 | "type": "bower-asset-library", 631 | "extra": { 632 | "bower-asset-main": "dist/typeahead.bundle.js" 633 | } 634 | }, 635 | { 636 | "name": "fzaninotto/faker", 637 | "version": "dev-master", 638 | "source": { 639 | "type": "git", 640 | "url": "https://github.com/fzaninotto/Faker.git", 641 | "reference": "2495d3361ac1e9fc15608a1b33ec2dd41c56b2dc" 642 | }, 643 | "dist": { 644 | "type": "zip", 645 | "url": "https://api.github.com/repos/fzaninotto/Faker/zipball/2495d3361ac1e9fc15608a1b33ec2dd41c56b2dc", 646 | "reference": "2495d3361ac1e9fc15608a1b33ec2dd41c56b2dc", 647 | "shasum": "" 648 | }, 649 | "require": { 650 | "php": ">=5.3.3" 651 | }, 652 | "require-dev": { 653 | "phpunit/phpunit": "~4.0", 654 | "squizlabs/php_codesniffer": "~1.5" 655 | }, 656 | "suggest": { 657 | "ext-intl": "*" 658 | }, 659 | "type": "library", 660 | "extra": { 661 | "branch-alias": { 662 | "dev-master": "1.5.x-dev" 663 | } 664 | }, 665 | "autoload": { 666 | "psr-4": { 667 | "Faker\\": "src/Faker/" 668 | } 669 | }, 670 | "notification-url": "https://packagist.org/downloads/", 671 | "license": [ 672 | "MIT" 673 | ], 674 | "authors": [ 675 | { 676 | "name": "François Zaninotto" 677 | } 678 | ], 679 | "description": "Faker is a PHP library that generates fake data for you.", 680 | "keywords": [ 681 | "data", 682 | "faker", 683 | "fixtures" 684 | ], 685 | "time": "2015-02-23 10:49:44" 686 | }, 687 | { 688 | "name": "phpspec/php-diff", 689 | "version": "dev-master", 690 | "source": { 691 | "type": "git", 692 | "url": "https://github.com/phpspec/php-diff.git", 693 | "reference": "30e103d19519fe678ae64a60d77884ef3d71b28a" 694 | }, 695 | "dist": { 696 | "type": "zip", 697 | "url": "https://api.github.com/repos/phpspec/php-diff/zipball/30e103d19519fe678ae64a60d77884ef3d71b28a", 698 | "reference": "30e103d19519fe678ae64a60d77884ef3d71b28a", 699 | "shasum": "" 700 | }, 701 | "type": "library", 702 | "autoload": { 703 | "psr-0": { 704 | "Diff": "lib/" 705 | } 706 | }, 707 | "notification-url": "https://packagist.org/downloads/", 708 | "license": [ 709 | "BSD-3-Clause" 710 | ], 711 | "authors": [ 712 | { 713 | "name": "Chris Boulton", 714 | "homepage": "http://github.com/chrisboulton", 715 | "role": "Original developer" 716 | } 717 | ], 718 | "description": "A comprehensive library for generating differences between two hashable objects (strings or arrays).", 719 | "time": "2013-11-01 13:02:21" 720 | }, 721 | { 722 | "name": "yiisoft/yii2-codeception", 723 | "version": "dev-master", 724 | "source": { 725 | "type": "git", 726 | "url": "https://github.com/yiisoft/yii2-codeception.git", 727 | "reference": "12a2cb182a8601ceb5e6440c8ad7d6e291834f61" 728 | }, 729 | "dist": { 730 | "type": "zip", 731 | "url": "https://api.github.com/repos/yiisoft/yii2-codeception/zipball/12a2cb182a8601ceb5e6440c8ad7d6e291834f61", 732 | "reference": "12a2cb182a8601ceb5e6440c8ad7d6e291834f61", 733 | "shasum": "" 734 | }, 735 | "require": { 736 | "yiisoft/yii2": "~2.0.0" 737 | }, 738 | "type": "yii2-extension", 739 | "extra": { 740 | "branch-alias": { 741 | "dev-master": "2.0.x-dev" 742 | } 743 | }, 744 | "autoload": { 745 | "psr-4": { 746 | "yii\\codeception\\": "" 747 | } 748 | }, 749 | "notification-url": "https://packagist.org/downloads/", 750 | "license": [ 751 | "BSD-3-Clause" 752 | ], 753 | "authors": [ 754 | { 755 | "name": "Mark Jebri", 756 | "email": "mark.github@yandex.ru" 757 | } 758 | ], 759 | "description": "The Codeception integration for the Yii framework", 760 | "keywords": [ 761 | "codeception", 762 | "yii2" 763 | ], 764 | "time": "2015-02-26 10:03:31" 765 | }, 766 | { 767 | "name": "yiisoft/yii2-debug", 768 | "version": "dev-master", 769 | "source": { 770 | "type": "git", 771 | "url": "https://github.com/yiisoft/yii2-debug.git", 772 | "reference": "8aa266ab08b51ef61b4786ec735a4e1697c15eed" 773 | }, 774 | "dist": { 775 | "type": "zip", 776 | "url": "https://api.github.com/repos/yiisoft/yii2-debug/zipball/8aa266ab08b51ef61b4786ec735a4e1697c15eed", 777 | "reference": "8aa266ab08b51ef61b4786ec735a4e1697c15eed", 778 | "shasum": "" 779 | }, 780 | "require": { 781 | "yiisoft/yii2": "~2.0.0", 782 | "yiisoft/yii2-bootstrap": "~2.0.0" 783 | }, 784 | "type": "yii2-extension", 785 | "extra": { 786 | "branch-alias": { 787 | "dev-master": "2.0.x-dev" 788 | } 789 | }, 790 | "autoload": { 791 | "psr-4": { 792 | "yii\\debug\\": "" 793 | } 794 | }, 795 | "notification-url": "https://packagist.org/downloads/", 796 | "license": [ 797 | "BSD-3-Clause" 798 | ], 799 | "authors": [ 800 | { 801 | "name": "Qiang Xue", 802 | "email": "qiang.xue@gmail.com" 803 | } 804 | ], 805 | "description": "The debugger extension for the Yii framework", 806 | "keywords": [ 807 | "debug", 808 | "debugger", 809 | "yii2" 810 | ], 811 | "time": "2015-02-26 10:03:31" 812 | }, 813 | { 814 | "name": "yiisoft/yii2-faker", 815 | "version": "dev-master", 816 | "source": { 817 | "type": "git", 818 | "url": "https://github.com/yiisoft/yii2-faker.git", 819 | "reference": "af4f1f4d2ba5357339ce3bc2b985512816c3e3db" 820 | }, 821 | "dist": { 822 | "type": "zip", 823 | "url": "https://api.github.com/repos/yiisoft/yii2-faker/zipball/af4f1f4d2ba5357339ce3bc2b985512816c3e3db", 824 | "reference": "af4f1f4d2ba5357339ce3bc2b985512816c3e3db", 825 | "shasum": "" 826 | }, 827 | "require": { 828 | "fzaninotto/faker": "*", 829 | "yiisoft/yii2": "~2.0.0" 830 | }, 831 | "type": "yii2-extension", 832 | "extra": { 833 | "branch-alias": { 834 | "dev-master": "2.0.x-dev" 835 | } 836 | }, 837 | "autoload": { 838 | "psr-4": { 839 | "yii\\faker\\": "" 840 | } 841 | }, 842 | "notification-url": "https://packagist.org/downloads/", 843 | "license": [ 844 | "BSD-3-Clause" 845 | ], 846 | "authors": [ 847 | { 848 | "name": "Mark Jebri", 849 | "email": "mark.github@yandex.ru" 850 | } 851 | ], 852 | "description": "Fixture generator. The Faker integration for the Yii framework.", 853 | "keywords": [ 854 | "Fixture", 855 | "faker", 856 | "yii2" 857 | ], 858 | "time": "2015-02-26 10:03:31" 859 | }, 860 | { 861 | "name": "yiisoft/yii2-gii", 862 | "version": "dev-master", 863 | "source": { 864 | "type": "git", 865 | "url": "https://github.com/yiisoft/yii2-gii.git", 866 | "reference": "ed68a18a1e8353c07ff07eb43b1242996898fc94" 867 | }, 868 | "dist": { 869 | "type": "zip", 870 | "url": "https://api.github.com/repos/yiisoft/yii2-gii/zipball/ed68a18a1e8353c07ff07eb43b1242996898fc94", 871 | "reference": "ed68a18a1e8353c07ff07eb43b1242996898fc94", 872 | "shasum": "" 873 | }, 874 | "require": { 875 | "bower-asset/typeahead.js": "0.10.*", 876 | "phpspec/php-diff": ">=1.0.2", 877 | "yiisoft/yii2": "~2.0.0", 878 | "yiisoft/yii2-bootstrap": "~2.0.0" 879 | }, 880 | "type": "yii2-extension", 881 | "extra": { 882 | "branch-alias": { 883 | "dev-master": "2.0.x-dev" 884 | } 885 | }, 886 | "autoload": { 887 | "psr-4": { 888 | "yii\\gii\\": "" 889 | } 890 | }, 891 | "notification-url": "https://packagist.org/downloads/", 892 | "license": [ 893 | "BSD-3-Clause" 894 | ], 895 | "authors": [ 896 | { 897 | "name": "Qiang Xue", 898 | "email": "qiang.xue@gmail.com" 899 | } 900 | ], 901 | "description": "The Gii extension for the Yii framework", 902 | "keywords": [ 903 | "code generator", 904 | "gii", 905 | "yii2" 906 | ], 907 | "time": "2015-02-26 10:03:31" 908 | } 909 | ], 910 | "aliases": [], 911 | "minimum-stability": "dev", 912 | "stability-flags": [], 913 | "prefer-stable": false, 914 | "prefer-lowest": false, 915 | "platform": { 916 | "php": ">=5.4.0" 917 | }, 918 | "platform-dev": [] 919 | } 920 | -------------------------------------------------------------------------------- /config/assets-prod.php: -------------------------------------------------------------------------------- 1 | [ 9 | 'class' => 'yii\\web\\AssetBundle', 10 | 'basePath' => '@webroot/assets', 11 | 'baseUrl' => '@web/assets', 12 | 'js' => [ 13 | 'all-b1fdf5f6bfc41de115b5cf76dd8f28e5.js', 14 | ], 15 | 'css' => [ 16 | 'all-a5f9c3d16c68f80aea88e79e14da6a00.css', 17 | ], 18 | ], 19 | 'yii\\web\\JqueryAsset' => [ 20 | 'sourcePath' => null, 21 | 'js' => [], 22 | 'css' => [], 23 | 'depends' => [ 24 | 'all', 25 | ], 26 | ], 27 | 'yii\\web\\YiiAsset' => [ 28 | 'sourcePath' => null, 29 | 'js' => [], 30 | 'css' => [], 31 | 'depends' => [ 32 | 'yii\\web\\JqueryAsset', 33 | 'all', 34 | ], 35 | ], 36 | 'yii\\bootstrap\\BootstrapAsset' => [ 37 | 'sourcePath' => null, 38 | 'js' => [], 39 | 'css' => [], 40 | 'depends' => [ 41 | 'all', 42 | ], 43 | ], 44 | 'app\\assets\\AppAsset' => [ 45 | 'sourcePath' => null, 46 | 'js' => [], 47 | 'css' => [], 48 | 'depends' => [ 49 | 'yii\\web\\YiiAsset', 50 | 'yii\\bootstrap\\BootstrapAsset', 51 | 'all', 52 | ], 53 | ], 54 | ]; -------------------------------------------------------------------------------- /config/console.php: -------------------------------------------------------------------------------- 1 | 'basic-console', 10 | 'basePath' => dirname(__DIR__), 11 | 'bootstrap' => ['log', 'gii'], 12 | 'controllerNamespace' => 'app\commands', 13 | 'modules' => [ 14 | 'gii' => 'yii\gii\Module', 15 | ], 16 | 'components' => [ 17 | 'cache' => [ 18 | 'class' => 'yii\caching\FileCache', 19 | ], 20 | 'log' => [ 21 | 'targets' => [ 22 | [ 23 | 'class' => 'yii\log\FileTarget', 24 | 'levels' => ['error', 'warning'], 25 | ], 26 | ], 27 | ], 28 | 'db' => $db, 29 | ], 30 | 'params' => $params, 31 | ]; 32 | -------------------------------------------------------------------------------- /config/db.php: -------------------------------------------------------------------------------- 1 | 'yii\db\Connection', 5 | 'dsn' => 'mysql:host=localhost;dbname=yii2basic', 6 | 'username' => 'root', 7 | 'password' => '', 8 | 'charset' => 'utf8', 9 | ]; 10 | -------------------------------------------------------------------------------- /config/params.php: -------------------------------------------------------------------------------- 1 | 'admin@example.com', 5 | ]; 6 | -------------------------------------------------------------------------------- /config/web.php: -------------------------------------------------------------------------------- 1 | 'basic', 7 | 'basePath' => dirname(__DIR__), 8 | 'bootstrap' => ['log'], 9 | 'components' => [ 10 | 'assetManager' => [ 11 | 'bundles' => require(__DIR__ . '/' . 'assets-prod.php' ), 12 | ], 13 | 14 | 'request' => [ 15 | 'cookieValidationKey' => 'test', 16 | ], 17 | 'cache' => [ 18 | 'class' => 'yii\caching\FileCache', 19 | ], 20 | 'user' => [ 21 | 'identityClass' => 'app\models\User', 22 | 'enableAutoLogin' => true, 23 | ], 24 | 'errorHandler' => [ 25 | 'errorAction' => 'site/error', 26 | ], 27 | 'mailer' => [ 28 | 'class' => 'yii\swiftmailer\Mailer', 29 | // send all mails to a file by default. You have to set 30 | // 'useFileTransport' to false and configure a transport 31 | // for the mailer to send real emails. 32 | 'useFileTransport' => true, 33 | ], 34 | 'log' => [ 35 | 'traceLevel' => YII_DEBUG ? 3 : 0, 36 | 'targets' => [ 37 | [ 38 | 'class' => 'yii\log\FileTarget', 39 | 'levels' => ['error', 'warning'], 40 | ], 41 | ], 42 | ], 43 | 'db' => require(__DIR__ . '/db.php'), 44 | ], 45 | 'params' => $params, 46 | ]; 47 | 48 | if (YII_ENV_DEV) { 49 | // configuration adjustments for 'dev' environment 50 | $config['bootstrap'][] = 'debug'; 51 | $config['modules']['debug'] = 'yii\debug\Module'; 52 | 53 | $config['bootstrap'][] = 'gii'; 54 | $config['modules']['gii'] = 'yii\gii\Module'; 55 | } 56 | 57 | return $config; 58 | -------------------------------------------------------------------------------- /controllers/SiteController.php: -------------------------------------------------------------------------------- 1 | [ 18 | 'class' => AccessControl::className(), 19 | 'only' => ['logout'], 20 | 'rules' => [ 21 | [ 22 | 'actions' => ['logout'], 23 | 'allow' => true, 24 | 'roles' => ['@'], 25 | ], 26 | ], 27 | ], 28 | 'verbs' => [ 29 | 'class' => VerbFilter::className(), 30 | 'actions' => [ 31 | 'logout' => ['post'], 32 | ], 33 | ], 34 | ]; 35 | } 36 | 37 | public function actions() 38 | { 39 | return [ 40 | 'error' => [ 41 | 'class' => 'yii\web\ErrorAction', 42 | ], 43 | 'captcha' => [ 44 | 'class' => 'yii\captcha\CaptchaAction', 45 | 'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null, 46 | ], 47 | ]; 48 | } 49 | 50 | public function actionIndex() 51 | { 52 | return $this->render('index'); 53 | } 54 | 55 | public function actionLogin() 56 | { 57 | if (!\Yii::$app->user->isGuest) { 58 | return $this->goHome(); 59 | } 60 | 61 | $model = new LoginForm(); 62 | if ($model->load(Yii::$app->request->post()) && $model->login()) { 63 | return $this->goBack(); 64 | } else { 65 | return $this->render('login', [ 66 | 'model' => $model, 67 | ]); 68 | } 69 | } 70 | 71 | public function actionLogout() 72 | { 73 | Yii::$app->user->logout(); 74 | 75 | return $this->goHome(); 76 | } 77 | 78 | public function actionContact() 79 | { 80 | $model = new ContactForm(); 81 | if ($model->load(Yii::$app->request->post()) && $model->contact(Yii::$app->params['adminEmail'])) { 82 | Yii::$app->session->setFlash('contactFormSubmitted'); 83 | 84 | return $this->refresh(); 85 | } else { 86 | return $this->render('contact', [ 87 | 'model' => $model, 88 | ]); 89 | } 90 | } 91 | 92 | public function actionAbout() 93 | { 94 | return $this->render('about'); 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /mail/layouts/html.php: -------------------------------------------------------------------------------- 1 | 8 | beginPage() ?> 9 | 10 | 11 | 12 | 13 | <?= Html::encode($this->title) ?> 14 | head() ?> 15 | 16 | 17 | beginBody() ?> 18 | 19 | endBody() ?> 20 | 21 | 22 | endPage() ?> 23 | -------------------------------------------------------------------------------- /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 | * @param string $email the target email address 47 | * @return boolean whether the model passes validation 48 | */ 49 | public function contact($email) 50 | { 51 | if ($this->validate()) { 52 | 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 | return true; 60 | } else { 61 | return false; 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /models/LoginForm.php: -------------------------------------------------------------------------------- 1 | hasErrors()) { 45 | $user = $this->getUser(); 46 | 47 | if (!$user || !$user->validatePassword($this->password)) { 48 | $this->addError($attribute, 'Incorrect username or password.'); 49 | } 50 | } 51 | } 52 | 53 | /** 54 | * Logs in a user using the provided username and password. 55 | * @return boolean whether the user is logged in successfully 56 | */ 57 | public function login() 58 | { 59 | if ($this->validate()) { 60 | return Yii::$app->user->login($this->getUser(), $this->rememberMe ? 3600*24*30 : 0); 61 | } else { 62 | return false; 63 | } 64 | } 65 | 66 | /** 67 | * Finds user by [[username]] 68 | * 69 | * @return User|null 70 | */ 71 | public function getUser() 72 | { 73 | if ($this->_user === false) { 74 | $this->_user = User::findByUsername($this->username); 75 | } 76 | 77 | return $this->_user; 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /models/User.php: -------------------------------------------------------------------------------- 1 | [ 15 | 'id' => '100', 16 | 'username' => 'admin', 17 | 'password' => 'admin', 18 | 'authKey' => 'test100key', 19 | 'accessToken' => '100-token', 20 | ], 21 | '101' => [ 22 | 'id' => '101', 23 | 'username' => 'demo', 24 | 'password' => 'demo', 25 | 'authKey' => 'test101key', 26 | 'accessToken' => '101-token', 27 | ], 28 | ]; 29 | 30 | /** 31 | * @inheritdoc 32 | */ 33 | public static function findIdentity($id) 34 | { 35 | return isset(self::$users[$id]) ? new static(self::$users[$id]) : null; 36 | } 37 | 38 | /** 39 | * @inheritdoc 40 | */ 41 | public static function findIdentityByAccessToken($token, $type = null) 42 | { 43 | foreach (self::$users as $user) { 44 | if ($user['accessToken'] === $token) { 45 | return new static($user); 46 | } 47 | } 48 | 49 | return null; 50 | } 51 | 52 | /** 53 | * Finds user by username 54 | * 55 | * @param string $username 56 | * @return static|null 57 | */ 58 | public static function findByUsername($username) 59 | { 60 | foreach (self::$users as $user) { 61 | if (strcasecmp($user['username'], $username) === 0) { 62 | return new static($user); 63 | } 64 | } 65 | 66 | return null; 67 | } 68 | 69 | /** 70 | * @inheritdoc 71 | */ 72 | public function getId() 73 | { 74 | return $this->id; 75 | } 76 | 77 | /** 78 | * @inheritdoc 79 | */ 80 | public function getAuthKey() 81 | { 82 | return $this->authKey; 83 | } 84 | 85 | /** 86 | * @inheritdoc 87 | */ 88 | public function validateAuthKey($authKey) 89 | { 90 | return $this->authKey === $authKey; 91 | } 92 | 93 | /** 94 | * Validates password 95 | * 96 | * @param string $password password to validate 97 | * @return boolean if password provided is valid for current user 98 | */ 99 | public function validatePassword($password) 100 | { 101 | return $this->password === $password; 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /runtime/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore -------------------------------------------------------------------------------- /tests/README.md: -------------------------------------------------------------------------------- 1 | This directory contains various tests for the basic application. 2 | 3 | Tests in `codeception` directory are developed with [Codeception PHP Testing Framework](http://codeception.com/). 4 | 5 | After creating the basic 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.*" 11 | composer global require "codeception/specify=*" 12 | composer global require "codeception/verify=*" 13 | ``` 14 | 15 | If you've never used Composer for global packages run `composer global status`. It should output: 16 | 17 | ``` 18 | Changed current directory to 19 | ``` 20 | 21 | Then add `/vendor/bin` to you `PATH` environment variable. Now we're able to use `codecept` from command 22 | line globally. 23 | 24 | 2. Install faker extension by running the following from template root directory where `composer.json` is: 25 | 26 | ``` 27 | composer require --dev yiisoft/yii2-faker:* 28 | ``` 29 | 30 | 3. Create `yii2_basic_tests` database and update it by applying migrations: 31 | 32 | ``` 33 | codeception/bin/yii migrate 34 | ``` 35 | 36 | 4. Build the test suites: 37 | 38 | ``` 39 | codecept build 40 | ``` 41 | 42 | 5. In order to be able to run acceptance tests you need to start a webserver. The simplest way is to use PHP built in 43 | webserver. In the `web` directory execute the following: 44 | 45 | ``` 46 | php -S localhost:8080 47 | ``` 48 | 49 | 6. Now you can run the tests with the following commands: 50 | 51 | ``` 52 | # run all available tests 53 | codecept run 54 | # run acceptance tests 55 | codecept run acceptance 56 | # run functional tests 57 | codecept run functional 58 | # run unit tests 59 | codecept run unit 60 | ``` 61 | 62 | Code coverage support 63 | --------------------- 64 | 65 | By default, code coverage is disabled in `codeception.yml` configuration file, you should uncomment needed rows to be able 66 | to collect code coverage. You can run your tests and collect coverage with the following command: 67 | 68 | ``` 69 | #collect coverage for all tests 70 | codecept run --coverage-html --coverage-xml 71 | 72 | #collect coverage only for unit tests 73 | codecept run unit --coverage-html --coverage-xml 74 | 75 | #collect coverage for unit and functional tests 76 | codecept run functional,unit --coverage-html --coverage-xml 77 | ``` 78 | 79 | You can see code coverage output under the `tests/_output` directory. 80 | 81 | ###Remote code coverage 82 | 83 | When you run your tests not in the same process where code coverage is collected, then you should uncomment `remote` option and its 84 | related options, to be able to collect code coverage correctly. To setup remote code coverage you should follow [instructions](http://codeception.com/docs/11-Codecoverage) 85 | from codeception site. 86 | 87 | 1. install `Codeception c3` remote support `composer require "codeception/c3:*"`; 88 | 89 | 2. copy `c3.php` file under your `web` directory; 90 | 91 | 3. include `c3.php` file in your `index-test.php` file before application run, so it can catch needed requests. 92 | 93 | Configuration options that are used by remote code coverage: 94 | 95 | - c3_url: url pointing to entry script that includes `c3.php` file, so `Codeception` will be able to produce code coverage; 96 | - remote: whether to enable remote code coverage or not; 97 | - remote_config: path to the `codeception.yml` configuration file, from the directory where `c3.php` file is located. This is needed 98 | so that `Codeception` can create itself instance and collect code coverage correctly. 99 | 100 | By default `c3_url` and `remote_config` setup correctly, you only need to copy and include `c3.php` file in your `index-test.php` 101 | 102 | After that you should be able to collect code coverage from tests that run through `PhpBrowser` or `WebDriver` with same command 103 | as for other tests: 104 | 105 | ``` 106 | #collect coverage from remote 107 | codecept run acceptance --coverage-html --coverage-xml 108 | ``` 109 | 110 | Please refer to [Codeception tutorial](http://codeception.com/docs/01-Introduction) for 111 | more details about writing and running acceptance, functional and unit tests. 112 | -------------------------------------------------------------------------------- /tests/codeception.yml: -------------------------------------------------------------------------------- 1 | actor: Tester 2 | #coverage: 3 | # #c3_url: http://localhost:8080/index-test.php/ 4 | # enabled: true 5 | # #remote: true 6 | # #remote_config: '../tests/codeception.yml' 7 | # white_list: 8 | # include: 9 | # - ../models/* 10 | # - ../controllers/* 11 | # - ../commands/* 12 | # - ../mail/* 13 | # blacklist: 14 | # include: 15 | # - ../assets/* 16 | # - ../config/* 17 | # - ../runtime/* 18 | # - ../vendor/* 19 | # - ../views/* 20 | # - ../web/* 21 | # - ../tests/* 22 | paths: 23 | tests: codeception 24 | log: codeception/_output 25 | data: codeception/_data 26 | helpers: codeception/_support 27 | settings: 28 | bootstrap: _bootstrap.php 29 | suite_class: \PHPUnit_Framework_TestSuite 30 | memory_limit: 1024M 31 | log: true 32 | colors: true 33 | config: 34 | # the entry script URL (with host info) for functional and acceptance tests 35 | # PLEASE ADJUST IT TO THE ACTUAL ENTRY SCRIPT URL 36 | test_entry_url: http://localhost:8080/index-test.php -------------------------------------------------------------------------------- /tests/codeception/.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/_bootstrap.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/_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/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 | # you can use WebDriver instead of PhpBrowser to test javascript and ajax. 16 | # This will require you to install selenium. See http://codeception.com/docs/04-AcceptanceTests#Selenium 17 | # "restart" option is used by the WebDriver to start each time per test-file new session and cookies, 18 | # it is useful if you want to login in your app in each test. 19 | # - WebDriver 20 | config: 21 | PhpBrowser: 22 | # PLEASE ADJUST IT TO THE ACTUAL ENTRY POINT WITHOUT PATH INFO 23 | url: http://localhost:8080 24 | # WebDriver: 25 | # url: http://localhost:8080 26 | # browser: firefox 27 | # restart: true 28 | -------------------------------------------------------------------------------- /tests/codeception/acceptance/AboutCept.php: -------------------------------------------------------------------------------- 1 | wantTo('ensure that about works'); 9 | AboutPage::openBy($I); 10 | $I->see('About', 'h1'); 11 | -------------------------------------------------------------------------------- /tests/codeception/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'); 22 | $I->see('Email cannot be blank'); 23 | $I->see('Subject cannot be blank'); 24 | $I->see('Body cannot be blank'); 25 | $I->see('The verification code is incorrect'); 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-inline'); 40 | $I->see('Email is not a valid email address.'); 41 | $I->dontSee('Subject cannot be blank', '.help-inline'); 42 | $I->dontSee('Body cannot be blank', '.help-inline'); 43 | $I->dontSee('The verification code is incorrect', '.help-inline'); 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->dontSeeElement('#contact-form'); 57 | $I->see('Thank you for contacting us. We will respond to you as soon as possible.'); 58 | -------------------------------------------------------------------------------- /tests/codeception/acceptance/HomeCept.php: -------------------------------------------------------------------------------- 1 | wantTo('ensure that home page works'); 7 | $I->amOnPage(Yii::$app->homeUrl); 8 | $I->see('My Company'); 9 | $I->seeLink('About'); 10 | $I->click('About'); 11 | $I->see('This is the About page.'); 12 | -------------------------------------------------------------------------------- /tests/codeception/acceptance/LoginCept.php: -------------------------------------------------------------------------------- 1 | wantTo('ensure that login works'); 9 | 10 | $loginPage = LoginPage::openBy($I); 11 | 12 | $I->see('Login', 'h1'); 13 | 14 | $I->amGoingTo('try to login with empty credentials'); 15 | $loginPage->login('', ''); 16 | if (method_exists($I, 'wait')) { 17 | $I->wait(3); // only for selenium 18 | } 19 | $I->expectTo('see validations errors'); 20 | $I->see('Username cannot be blank.'); 21 | $I->see('Password cannot be blank.'); 22 | 23 | $I->amGoingTo('try to login with wrong credentials'); 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.'); 30 | 31 | $I->amGoingTo('try to login with correct credentials'); 32 | $loginPage->login('admin', 'admin'); 33 | if (method_exists($I, 'wait')) { 34 | $I->wait(3); // only for selenium 35 | } 36 | $I->expectTo('see user info'); 37 | $I->see('Logout (admin)'); 38 | -------------------------------------------------------------------------------- /tests/codeception/acceptance/_bootstrap.php: -------------------------------------------------------------------------------- 1 | run(); 20 | exit($exitCode); 21 | -------------------------------------------------------------------------------- /tests/codeception/bin/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/acceptance.php: -------------------------------------------------------------------------------- 1 | [ 7 | 'fixture' => [ 8 | 'class' => 'yii\faker\FixtureController', 9 | 'fixtureDataPath' => '@tests/codeception/fixtures', 10 | 'templatePath' => '@tests/codeception/templates', 11 | 'namespace' => 'tests\codeception\fixtures', 12 | ], 13 | ], 14 | 'components' => [ 15 | 'db' => [ 16 | 'dsn' => 'mysql:host=localhost;dbname=yii2_basic_tests', 17 | ], 18 | 'mailer' => [ 19 | 'useFileTransport' => true, 20 | ], 21 | 'urlManager' => [ 22 | 'showScriptName' => true, 23 | ], 24 | ], 25 | ]; 26 | -------------------------------------------------------------------------------- /tests/codeception/config/functional.php: -------------------------------------------------------------------------------- 1 | [ 13 | 'request' => [ 14 | // it's not recommended to run functional tests with CSRF validation enabled 15 | 'enableCsrfValidation' => false, 16 | // but if you absolutely need it set cookie domain to localhost 17 | /* 18 | 'csrfCookie' => [ 19 | 'domain' => 'localhost', 20 | ], 21 | */ 22 | ], 23 | ], 24 | ] 25 | ); 26 | -------------------------------------------------------------------------------- /tests/codeception/config/unit.php: -------------------------------------------------------------------------------- 1 | wantTo('ensure that about works'); 9 | AboutPage::openBy($I); 10 | $I->see('About', 'h1'); 11 | -------------------------------------------------------------------------------- /tests/codeception/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'); 19 | $I->see('Email cannot be blank'); 20 | $I->see('Subject cannot be blank'); 21 | $I->see('Body cannot be blank'); 22 | $I->see('The verification code is incorrect'); 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-inline'); 34 | $I->see('Email is not a valid email address.'); 35 | $I->dontSee('Subject cannot be blank', '.help-inline'); 36 | $I->dontSee('Body cannot be blank', '.help-inline'); 37 | $I->dontSee('The verification code is incorrect', '.help-inline'); 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->dontSeeElement('#contact-form'); 48 | $I->see('Thank you for contacting us. We will respond to you as soon as possible.'); 49 | -------------------------------------------------------------------------------- /tests/codeception/functional/HomeCept.php: -------------------------------------------------------------------------------- 1 | wantTo('ensure that home page works'); 7 | $I->amOnPage(Yii::$app->homeUrl); 8 | $I->see('My Company'); 9 | $I->seeLink('About'); 10 | $I->click('About'); 11 | $I->see('This is the About page.'); 12 | -------------------------------------------------------------------------------- /tests/codeception/functional/LoginCept.php: -------------------------------------------------------------------------------- 1 | wantTo('ensure that login works'); 9 | 10 | $loginPage = LoginPage::openBy($I); 11 | 12 | $I->see('Login', 'h1'); 13 | 14 | $I->amGoingTo('try to login with empty credentials'); 15 | $loginPage->login('', ''); 16 | $I->expectTo('see validations errors'); 17 | $I->see('Username cannot be blank.'); 18 | $I->see('Password cannot be blank.'); 19 | 20 | $I->amGoingTo('try to login with wrong credentials'); 21 | $loginPage->login('admin', 'wrong'); 22 | $I->expectTo('see validations errors'); 23 | $I->see('Incorrect username or password.'); 24 | 25 | $I->amGoingTo('try to login with correct credentials'); 26 | $loginPage->login('admin', 'admin'); 27 | $I->expectTo('see user info'); 28 | $I->see('Logout (admin)'); 29 | -------------------------------------------------------------------------------- /tests/codeception/functional/_bootstrap.php: -------------------------------------------------------------------------------- 1 | mailer->fileTransportCallback = function ($mailer, $message) { 17 | return 'testing_message.eml'; 18 | }; 19 | } 20 | 21 | protected function tearDown() 22 | { 23 | unlink($this->getMessageFile()); 24 | parent::tearDown(); 25 | } 26 | 27 | public function testContact() 28 | { 29 | $model = $this->getMock('app\models\ContactForm', ['validate']); 30 | $model->expects($this->once())->method('validate')->will($this->returnValue(true)); 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->contact('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 | } 61 | -------------------------------------------------------------------------------- /tests/codeception/unit/models/LoginFormTest.php: -------------------------------------------------------------------------------- 1 | user->logout(); 17 | parent::tearDown(); 18 | } 19 | 20 | public function testLoginNoUser() 21 | { 22 | $model = new LoginForm([ 23 | 'username' => 'not_existing_username', 24 | 'password' => 'not_existing_password', 25 | ]); 26 | 27 | $this->specify('user should not be able to login, when there is no identity', function () use ($model) { 28 | expect('model should not login user', $model->login())->false(); 29 | expect('user should not be logged in', Yii::$app->user->isGuest)->true(); 30 | }); 31 | } 32 | 33 | public function testLoginWrongPassword() 34 | { 35 | $model = new LoginForm([ 36 | 'username' => 'demo', 37 | 'password' => 'wrong_password', 38 | ]); 39 | 40 | $this->specify('user should not be able to login with wrong password', function () use ($model) { 41 | expect('model should not login user', $model->login())->false(); 42 | expect('error message should be set', $model->errors)->hasKey('password'); 43 | expect('user should not be logged in', Yii::$app->user->isGuest)->true(); 44 | }); 45 | } 46 | 47 | public function testLoginCorrect() 48 | { 49 | $model = new LoginForm([ 50 | 'username' => 'demo', 51 | 'password' => 'demo', 52 | ]); 53 | 54 | $this->specify('user should be able to login with correct credentials', function () use ($model) { 55 | expect('model should login user', $model->login())->true(); 56 | expect('error message should not be set', $model->errors)->hasntKey('password'); 57 | expect('user should be logged in', Yii::$app->user->isGuest)->false(); 58 | }); 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /tests/codeception/unit/models/UserTest.php: -------------------------------------------------------------------------------- 1 | loadFixtures(['user']); 14 | } 15 | 16 | // TODO add test methods here 17 | } 18 | -------------------------------------------------------------------------------- /tests/codeception/unit/templates/fixtures/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lukicdarkoo/yii2-and-gulp/a0c8b3a827992fda1a62c7f6faa0af73ce2b9e6c/tests/codeception/unit/templates/fixtures/.gitkeep -------------------------------------------------------------------------------- /tools/gulp/assets-config.php: -------------------------------------------------------------------------------- 1 | 'gulp compress-js --gulpfile tools/gulp/gulpfile.js --src {from} --dist {to}', 12 | 'cssCompressor' => 'gulp compress-css --gulpfile tools/gulp/gulpfile.js --src {from} --dist {to}', 13 | 'bundles' => [ 14 | 'app\assets\AppAsset', 15 | ], 16 | 'targets' => [ 17 | 'all' => [ 18 | 'class' => 'yii\web\AssetBundle', 19 | 'basePath' => '@webroot/assets', 20 | 'baseUrl' => '@web/assets', 21 | 'js' => 'all-{hash}.js', 22 | 'css' => 'all-{hash}.css', 23 | 'depends' => [ 24 | ], 25 | ], 26 | ], 27 | // Asset manager configuration: 28 | 'assetManager' => [ 29 | 'basePath' => '@webroot/assets', 30 | 'baseUrl' => '@web/assets', 31 | ], 32 | ]; 33 | -------------------------------------------------------------------------------- /tools/gulp/gulpfile.js: -------------------------------------------------------------------------------- 1 | var gulp = require('gulp'); 2 | var uglify = require('gulp-uglify'); 3 | var cssMin = require('gulp-css'); 4 | 5 | 6 | // Need because of `yii console` 7 | var rename = require('gulp-rename'); 8 | var minimist = require('minimist'); 9 | var options = minimist(process.argv.slice(2), { string: 'src', string: 'dist' }); 10 | var destDir = options.dist.substring(0, options.dist.lastIndexOf("/")); 11 | var destFile = options.dist.replace(/^.*[\\\/]/, ''); 12 | 13 | 14 | // Use `compress-js` task for JavaScript files 15 | gulp.task('compress-js', function() { 16 | gulp.src(options.src) 17 | .pipe(uglify()) 18 | 19 | .pipe(rename(destFile)) 20 | .pipe(gulp.dest(destDir)) 21 | }); 22 | 23 | // Use `compress-css` task for CSS files 24 | gulp.task('compress-css', function() { 25 | gulp.src(options.src) 26 | .pipe(cssMin()) 27 | 28 | .pipe(rename(destFile)) 29 | .pipe(gulp.dest(destDir)) 30 | }); -------------------------------------------------------------------------------- /tools/gulp/node_modules/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /tools/gulp/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "yii2-gulp", 3 | "version": "1.0.0", 4 | "description": "Yii2 Gulp", 5 | "keywords": [ 6 | "tools" 7 | ], 8 | "author": "Darko Lukic", 9 | "license": "ISC", 10 | "dependencies": { 11 | "gulp": "*", 12 | "gulp-uglify": "*", 13 | "minimist": "*", 14 | "gulp-rename": "*", 15 | "gulp-css": "*" 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /views/layouts/main.php: -------------------------------------------------------------------------------- 1 | 13 | beginPage() ?> 14 | 15 | 16 | 17 | 18 | 19 | 20 | <?= Html::encode($this->title) ?> 21 | head() ?> 22 | 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 | echo Nav::widget([ 36 | 'options' => ['class' => 'navbar-nav navbar-right'], 37 | 'items' => [ 38 | ['label' => 'Home', 'url' => ['/site/index']], 39 | ['label' => 'About', 'url' => ['/site/about']], 40 | ['label' => 'Contact', 'url' => ['/site/contact']], 41 | Yii::$app->user->isGuest ? 42 | ['label' => 'Login', 'url' => ['/site/login']] : 43 | ['label' => 'Logout (' . Yii::$app->user->identity->username . ')', 44 | 'url' => ['/site/logout'], 45 | 'linkOptions' => ['data-method' => 'post']], 46 | ], 47 | ]); 48 | NavBar::end(); 49 | ?> 50 | 51 |
52 | isset($this->params['breadcrumbs']) ? $this->params['breadcrumbs'] : [], 54 | ]) ?> 55 | 56 |
57 |
58 | 59 |
60 |
61 |

© My Company

62 |

63 |
64 |
65 | 66 | endBody() ?> 67 | 68 | 69 | endPage() ?> 70 | -------------------------------------------------------------------------------- /views/site/about.php: -------------------------------------------------------------------------------- 1 | title = 'About'; 6 | $this->params['breadcrumbs'][] = $this->title; 7 | ?> 8 |
9 |

title) ?>

10 | 11 |

12 | This is the About page. You may modify the following file to customize its content: 13 |

14 | 15 | 16 |
17 | -------------------------------------------------------------------------------- /views/site/contact.php: -------------------------------------------------------------------------------- 1 | title = 'Contact'; 11 | $this->params['breadcrumbs'][] = $this->title; 12 | ?> 13 |
14 |

title) ?>

15 | 16 | session->hasFlash('contactFormSubmitted')): ?> 17 | 18 |
19 | Thank you for contacting us. We will respond to you as soon as possible. 20 |
21 | 22 |

23 | Note that if you turn on the Yii debugger, you should be able 24 | to view the mail message on the mail panel of the debugger. 25 | mailer->useFileTransport): ?> 26 | Because the application is in development mode, the email is not sent but saved as 27 | a file under mailer->fileTransportPath) ?>. 28 | Please configure the useFileTransport property of the mail 29 | application component to be false to enable email sending. 30 | 31 |

32 | 33 | 34 | 35 |

36 | If you have business inquiries or other questions, please fill out the following form to contact us. Thank you. 37 |

38 | 39 |
40 |
41 | 'contact-form']); ?> 42 | field($model, 'name') ?> 43 | field($model, 'email') ?> 44 | field($model, 'subject') ?> 45 | field($model, 'body')->textArea(['rows' => 6]) ?> 46 | field($model, 'verifyCode')->widget(Captcha::className(), [ 47 | 'template' => '
{image}
{input}
', 48 | ]) ?> 49 |
50 | 'btn btn-primary', 'name' => 'contact-button']) ?> 51 |
52 | 53 |
54 |
55 | 56 | 57 |
58 | -------------------------------------------------------------------------------- /views/site/error.php: -------------------------------------------------------------------------------- 1 | title = $name; 11 | ?> 12 |
13 | 14 |

title) ?>

15 | 16 |
17 | 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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /views/site/login.php: -------------------------------------------------------------------------------- 1 | title = 'Login'; 10 | $this->params['breadcrumbs'][] = $this->title; 11 | ?> 12 | 47 | -------------------------------------------------------------------------------- /web/assets/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /web/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lukicdarkoo/yii2-and-gulp/a0c8b3a827992fda1a62c7f6faa0af73ce2b9e6c/web/favicon.ico -------------------------------------------------------------------------------- /web/index-test.php: -------------------------------------------------------------------------------- 1 | run(); 17 | -------------------------------------------------------------------------------- /web/index.php: -------------------------------------------------------------------------------- 1 | run(); 13 | -------------------------------------------------------------------------------- /web/robots.txt: -------------------------------------------------------------------------------- 1 | User-agent: * 2 | Disallow: -------------------------------------------------------------------------------- /yii: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env php 2 | run(); 24 | exit($exitCode); 25 | -------------------------------------------------------------------------------- /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 | --------------------------------------------------------------------------------