|
| 1 | +<?php |
| 2 | +declare(strict_types=1); |
| 3 | + |
| 4 | +namespace Phalcon\DevTools\Tests\Acceptance\Web\Template; |
| 5 | + |
| 6 | +use AcceptanceTester; |
| 7 | +use Codeception\Util\Fixtures; |
| 8 | +use Codeception\Util\Locator; |
| 9 | + |
| 10 | +final class ScaffoldPhtmlCest |
| 11 | +{ |
| 12 | + /** |
| 13 | + * @group mysql |
| 14 | + */ |
| 15 | + public function before(AcceptanceTester $I): void |
| 16 | + { |
| 17 | + $namespace = 'Test\WebTools'; |
| 18 | + |
| 19 | + $I->amOnPage('/webtools.php/scaffold/generate'); |
| 20 | + $I->selectOption('form select[name=templateEngine]', 'PHP'); |
| 21 | + |
| 22 | + Fixtures::add('tablename', 'customers'); |
| 23 | + |
| 24 | + $I->selectOption('form select[name=tableName]', Fixtures::get('tablename')); |
| 25 | + |
| 26 | + $basePath = $I->grabValueFrom('#basePath'); |
| 27 | + Fixtures::add('base_path', $basePath); |
| 28 | + |
| 29 | + $I->fillField('modelsNamespace', $namespace); |
| 30 | + $I->checkOption('#force'); |
| 31 | + $I->click('input[type=submit]'); |
| 32 | + $I->see('Migrations'); |
| 33 | + $I->see('All migrations that we managed to find'); |
| 34 | + |
| 35 | + //add namespace in loader file |
| 36 | + $loaderFile = $basePath . |
| 37 | + DIRECTORY_SEPARATOR . 'app' . |
| 38 | + DIRECTORY_SEPARATOR . 'config' . |
| 39 | + DIRECTORY_SEPARATOR . 'loader.php'; |
| 40 | + |
| 41 | + $content = file_get_contents($loaderFile); |
| 42 | + |
| 43 | + //Add namespace |
| 44 | + $returnLine = "\r\n"; |
| 45 | + |
| 46 | + $content .= $returnLine . |
| 47 | + '$loader->registerNamespaces(' . |
| 48 | + $returnLine . '[ '. |
| 49 | + '"'.$namespace.'" => $config->application->modelsDir' . |
| 50 | + $returnLine . ' ]' . |
| 51 | + $returnLine . ');'; |
| 52 | + |
| 53 | + file_put_contents($loaderFile, $content); |
| 54 | + } |
| 55 | + |
| 56 | + /** |
| 57 | + * @group mysql |
| 58 | + */ |
| 59 | + public function testGenScaffoldFileExist(AcceptanceTester $I): void |
| 60 | + { |
| 61 | + $basePath = Fixtures::get('base_path'); |
| 62 | + |
| 63 | + Fixtures::add('controller', $basePath . |
| 64 | + DIRECTORY_SEPARATOR . 'app' . |
| 65 | + DIRECTORY_SEPARATOR . 'controllers' . |
| 66 | + DIRECTORY_SEPARATOR . 'CustomersController.php'); |
| 67 | + |
| 68 | + Fixtures::add('model', $basePath . |
| 69 | + DIRECTORY_SEPARATOR . 'app' . |
| 70 | + DIRECTORY_SEPARATOR . 'models' . |
| 71 | + DIRECTORY_SEPARATOR . 'Customers.php'); |
| 72 | + |
| 73 | + Fixtures::add('layout', $basePath . |
| 74 | + DIRECTORY_SEPARATOR . 'app' . |
| 75 | + DIRECTORY_SEPARATOR . 'views' . |
| 76 | + DIRECTORY_SEPARATOR . 'layouts' . |
| 77 | + DIRECTORY_SEPARATOR . 'customers.phtml'); |
| 78 | + |
| 79 | + Fixtures::add('views', $basePath . |
| 80 | + DIRECTORY_SEPARATOR . 'app' . |
| 81 | + DIRECTORY_SEPARATOR . 'views' . |
| 82 | + DIRECTORY_SEPARATOR . 'customers'); |
| 83 | + |
| 84 | + Fixtures::add('views_edit', $basePath . |
| 85 | + DIRECTORY_SEPARATOR . 'app' . |
| 86 | + DIRECTORY_SEPARATOR . 'views' . |
| 87 | + DIRECTORY_SEPARATOR . 'customers' . |
| 88 | + DIRECTORY_SEPARATOR . 'edit.phtml'); |
| 89 | + |
| 90 | + Fixtures::add('views_index', $basePath . |
| 91 | + DIRECTORY_SEPARATOR . 'app' . |
| 92 | + DIRECTORY_SEPARATOR . 'views' . |
| 93 | + DIRECTORY_SEPARATOR . 'customers' . |
| 94 | + DIRECTORY_SEPARATOR . 'index.phtml'); |
| 95 | + |
| 96 | + Fixtures::add('views_new', $basePath . |
| 97 | + DIRECTORY_SEPARATOR . 'app' . |
| 98 | + DIRECTORY_SEPARATOR . 'views' . |
| 99 | + DIRECTORY_SEPARATOR . 'customers' . |
| 100 | + DIRECTORY_SEPARATOR . 'new.phtml'); |
| 101 | + |
| 102 | + Fixtures::add('views_search', $basePath . |
| 103 | + DIRECTORY_SEPARATOR . 'app' . |
| 104 | + DIRECTORY_SEPARATOR . 'views' . |
| 105 | + DIRECTORY_SEPARATOR . 'customers' . |
| 106 | + DIRECTORY_SEPARATOR . 'search.phtml'); |
| 107 | + |
| 108 | + $I->seeFileFound(Fixtures::get('controller')); |
| 109 | + $I->seeFileFound(Fixtures::get('model')); |
| 110 | + $I->seeFileFound(Fixtures::get('layout')); |
| 111 | + $I->seeFileFound(Fixtures::get('views_edit')); |
| 112 | + $I->seeFileFound(Fixtures::get('views_index')); |
| 113 | + $I->seeFileFound(Fixtures::get('views_search')); |
| 114 | + } |
| 115 | + |
| 116 | + /** |
| 117 | + * @group mysql |
| 118 | + */ |
| 119 | + public function testSearchAction(AcceptanceTester $I): void |
| 120 | + { |
| 121 | + $I->amOnPage('/'.Fixtures::get('tablename')); |
| 122 | + $I->see(Fixtures::get('tablename')); |
| 123 | + $I->see('Search '.Fixtures::get('tablename')); |
| 124 | + $I->see('Dateofbirth'); |
| 125 | + $I->fillField('dateofbirth', '2019-04-17'); |
| 126 | + $I->click('input[type=submit]'); |
| 127 | + |
| 128 | + $I->see('Brandon'); |
| 129 | + } |
| 130 | + |
| 131 | + /** |
| 132 | + * @group mysql |
| 133 | + */ |
| 134 | + public function testSearchButtonAction(AcceptanceTester $I): void |
| 135 | + { |
| 136 | + $I->amOnPage('/'.Fixtures::get('tablename').'/search'); |
| 137 | + $I->see('Search result'); |
| 138 | + |
| 139 | + $I->click("#next"); |
| 140 | + |
| 141 | + $I->see("K1S6X"); |
| 142 | + |
| 143 | + $I->click("#previous"); |
| 144 | + |
| 145 | + $I->see("U7B0Q"); |
| 146 | + |
| 147 | + $I->click("#last"); |
| 148 | + |
| 149 | + $I->see("N2Z7T"); |
| 150 | + |
| 151 | + $I->click("#first"); |
| 152 | + |
| 153 | + $I->see("U7B0Q"); |
| 154 | + } |
| 155 | + |
| 156 | + |
| 157 | + /** |
| 158 | + * @group mysql |
| 159 | + */ |
| 160 | + public function testNewAction(AcceptanceTester $I): void |
| 161 | + { |
| 162 | + $I->amOnPage('/'.Fixtures::get('tablename').'/new'); |
| 163 | + $I->see('Create '.Fixtures::get('tablename')); |
| 164 | + $I->fillField('firstname', 'jeremy'); |
| 165 | + $I->fillField('surname', 'jenovateurs'); |
| 166 | + $I->fillField('membertype', 'aaa'); |
| 167 | + $I->fillField('dateofbirth', '2019-04-17'); |
| 168 | + $I->click('input[type=submit]'); |
| 169 | + } |
| 170 | + |
| 171 | + /** |
| 172 | + * @group mysql |
| 173 | + */ |
| 174 | + public function testEditAction(AcceptanceTester $I): void |
| 175 | + { |
| 176 | + $I->amOnPage('/'.Fixtures::get('tablename'). |
| 177 | + '/search'); |
| 178 | + $I->see('Search result'); |
| 179 | + $I->click(['link' => 'Edit']); |
| 180 | + $I->seeInField('firstname', 'Hedley'); |
| 181 | + $I->fillField('firstname', 'samedi'); |
| 182 | + $I->click('input[type=submit]'); |
| 183 | + $I->amOnPage('/'.Fixtures::get('tablename'). |
| 184 | + '/search'); |
| 185 | + $I->see('Search result'); |
| 186 | + //Check if edit work |
| 187 | + // $I->see('samedi'); |
| 188 | + } |
| 189 | + |
| 190 | + /** |
| 191 | + * @group mysql |
| 192 | + */ |
| 193 | + public function testDeleteAction(AcceptanceTester $I): void |
| 194 | + { |
| 195 | + $I->amOnPage('/'.Fixtures::get('tablename'). |
| 196 | + '/search'); |
| 197 | + $I->see('Search result'); |
| 198 | + $I->click(['link' => 'Delete']); |
| 199 | + $I->see('customer was deleted successfully'); |
| 200 | + |
| 201 | + $I->amOnPage('/'.Fixtures::get('tablename'). |
| 202 | + '/search'); |
| 203 | + $I->cantSee('Hedley'); |
| 204 | + } |
| 205 | + |
| 206 | + /** |
| 207 | + * @group mysql |
| 208 | + */ |
| 209 | + public function after(AcceptanceTester $I): void |
| 210 | + { |
| 211 | + $I->deleteFile(Fixtures::get('controller')); |
| 212 | + $I->deleteFile(Fixtures::get('model')); |
| 213 | + $I->deleteFile(Fixtures::get('layout')); |
| 214 | + $I->deleteDir(Fixtures::get('views')); |
| 215 | + } |
| 216 | +} |
0 commit comments