|
2 | 2 |
|
3 | 3 | namespace Pug\Tests; |
4 | 4 |
|
| 5 | +use Composer\Composer; |
| 6 | +use Composer\Script\Event; |
5 | 7 | use Jade\Compiler; |
6 | 8 | use Jade\Filter\AbstractFilter; |
7 | 9 | use Jade\Nodes\Filter; |
|
10 | 12 | use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; |
11 | 13 | use Symfony\Bundle\SecurityBundle\Templating\Helper\LogoutUrlHelper as BaseLogoutUrlHelper; |
12 | 14 | use Symfony\Component\Filesystem\Filesystem; |
13 | | -use Symfony\Component\HttpKernel\Kernel; |
14 | 15 | use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage as BaseTokenStorage; |
15 | 16 | use Symfony\Component\Security\Http\Logout\LogoutUrlGenerator as BaseLogoutUrlGenerator; |
16 | 17 |
|
@@ -306,4 +307,184 @@ public function testIssue11BackgroundImage() |
306 | 307 |
|
307 | 308 | self::assertSame('<div style="background-image: url(foo);" class="slide"></div>', $html); |
308 | 309 | } |
| 310 | + |
| 311 | + /** |
| 312 | + * @group install |
| 313 | + */ |
| 314 | + public function testInstall() |
| 315 | + { |
| 316 | + include_once __DIR__ . '/CaptureIO.php'; |
| 317 | + $io = new CaptureIO(); |
| 318 | + $composer = new Composer(); |
| 319 | + $installedFile = __DIR__ . '/../../installed'; |
| 320 | + touch($installedFile); |
| 321 | + |
| 322 | + self::assertTrue(PugSymfonyEngine::install(new Event('install', $composer, $io))); |
| 323 | + |
| 324 | + unlink($installedFile); |
| 325 | + $io->setInteractive(true); |
| 326 | + |
| 327 | + self::assertTrue(PugSymfonyEngine::install(new Event('install', $composer, $io))); |
| 328 | + self::assertTrue(file_exists($installedFile)); |
| 329 | + |
| 330 | + unlink($installedFile); |
| 331 | + $io->setPermissive(true); |
| 332 | + $io->reset(); |
| 333 | + $dir = sys_get_temp_dir() . '/pug-temp'; |
| 334 | + $fs = new Filesystem(); |
| 335 | + $fs->remove($dir); |
| 336 | + |
| 337 | + self::assertTrue(PugSymfonyEngine::install(new Event('install', $composer, $io), $dir)); |
| 338 | + self::assertSame([ |
| 339 | + 'framework entry not found in config.yml.', |
| 340 | + 'Sorry, AppKernel.php has a format we can\'t handle automatically.', |
| 341 | + ], $io->getLastOutput()); |
| 342 | + clearstatcache(); |
| 343 | + self::assertFalse(file_exists($installedFile)); |
| 344 | + |
| 345 | + foreach (['/app/config/config.yml', '/app/AppKernel.php'] as $file) { |
| 346 | + $fs->copy(__DIR__ . '/../project' . $file, $dir . $file); |
| 347 | + } |
| 348 | + $io->reset(); |
| 349 | + |
| 350 | + self::assertTrue(PugSymfonyEngine::install(new Event('install', $composer, $io), $dir)); |
| 351 | + self::assertSame([ |
| 352 | + 'templating.engine.pug setting in config.yml already exists.', |
| 353 | + 'Pug engine already exist in framework.templating.engines in config.yml.', |
| 354 | + 'The bundle already exists in AppKernel.php', |
| 355 | + ], $io->getLastOutput()); |
| 356 | + clearstatcache(); |
| 357 | + self::assertTrue(file_exists($installedFile)); |
| 358 | + |
| 359 | + unlink($installedFile); |
| 360 | + file_put_contents($dir . '/app/config/config.yml', str_replace( |
| 361 | + ['pug', 'services:'], |
| 362 | + ['x', 'x:'], |
| 363 | + file_get_contents($dir . '/app/config/config.yml') |
| 364 | + )); |
| 365 | + file_put_contents($dir . '/app/AppKernel.php', str_replace( |
| 366 | + 'Pug', |
| 367 | + 'X', |
| 368 | + file_get_contents($dir . '/app/AppKernel.php') |
| 369 | + )); |
| 370 | + $io->reset(); |
| 371 | + |
| 372 | + self::assertTrue(PugSymfonyEngine::install(new Event('install', $composer, $io), $dir)); |
| 373 | + self::assertSame([ |
| 374 | + 'Engine service added in config.yml', |
| 375 | + 'Engine added to framework.templating.engines in config.yml', |
| 376 | + 'Bundle added to AppKernel.php', |
| 377 | + ], $io->getLastOutput()); |
| 378 | + self::assertContains( |
| 379 | + 'Pug\PugSymfonyBundle\PugSymfonyBundle()', |
| 380 | + file_get_contents($dir . '/app/AppKernel.php') |
| 381 | + ); |
| 382 | + self::assertContains( |
| 383 | + 'templating.engine.pug', |
| 384 | + file_get_contents($dir . '/app/config/config.yml') |
| 385 | + ); |
| 386 | + clearstatcache(); |
| 387 | + self::assertTrue(file_exists($installedFile)); |
| 388 | + |
| 389 | + $io->reset(); |
| 390 | + unlink($installedFile); |
| 391 | + file_put_contents($dir . '/app/config/config.yml', implode("\n", [ |
| 392 | + 'foo:', |
| 393 | + ' bar: biz', |
| 394 | + 'framework:', |
| 395 | + ' bar1: biz', |
| 396 | + ' templating:', |
| 397 | + ' bar2: biz', |
| 398 | + ' engines:', |
| 399 | + ' - pug', |
| 400 | + ' - php', |
| 401 | + ' bar3: biz', |
| 402 | + ' bar4: biz', |
| 403 | + 'bar: biz', |
| 404 | + ])); |
| 405 | + self::assertTrue(PugSymfonyEngine::install(new Event('install', $composer, $io), $dir)); |
| 406 | + self::assertSame([ |
| 407 | + 'Engine service added in config.yml', |
| 408 | + 'Automatic engine adding is only possible if framework.templating.engines is a '. |
| 409 | + 'one-line setting in config.yml.', |
| 410 | + 'The bundle already exists in AppKernel.php', |
| 411 | + ], $io->getLastOutput()); |
| 412 | + clearstatcache(); |
| 413 | + self::assertFalse(file_exists($installedFile)); |
| 414 | + |
| 415 | + file_put_contents($dir . '/app/config/config.yml', implode("\n", [ |
| 416 | + 'foo:', |
| 417 | + ' bar: biz', |
| 418 | + 'framework:', |
| 419 | + ' bar1: biz', |
| 420 | + ' templating:', |
| 421 | + ' bar2: biz', |
| 422 | + ' templating:', |
| 423 | + ' bar2: biz', |
| 424 | + ' engines: ["twig","php"]', |
| 425 | + ' bar3: biz', |
| 426 | + ' engines: ["twig","php"]', |
| 427 | + ' bar4: biz', |
| 428 | + 'bar: biz', |
| 429 | + ])); |
| 430 | + PugSymfonyEngine::install(new Event('install', $composer, $io), $dir); |
| 431 | + self::assertSame(implode("\n", [ |
| 432 | + 'foo:', |
| 433 | + ' bar: biz', |
| 434 | + 'services:', |
| 435 | + ' templating.engine.pug:', |
| 436 | + ' class: Pug\PugSymfonyEngine', |
| 437 | + ' arguments: ["@kernel"]', |
| 438 | + '', |
| 439 | + 'framework:', |
| 440 | + ' bar1: biz', |
| 441 | + ' templating:', |
| 442 | + ' bar2: biz', |
| 443 | + ' templating:', |
| 444 | + ' bar2: biz', |
| 445 | + ' engines: ["pug","twig","php"]', |
| 446 | + ' bar3: biz', |
| 447 | + ' engines: ["twig","php"]', |
| 448 | + ' bar4: biz', |
| 449 | + 'bar: biz', |
| 450 | + ]), file_get_contents($dir . '/app/config/config.yml')); |
| 451 | + self::assertTrue(file_exists($installedFile)); |
| 452 | + unlink($installedFile); |
| 453 | + |
| 454 | + file_put_contents($dir . '/app/config/config.yml', implode("\n", [ |
| 455 | + 'foo:', |
| 456 | + ' bar: biz', |
| 457 | + 'framework:', |
| 458 | + ' bar1: biz', |
| 459 | + ' templating:', |
| 460 | + ' bar2: biz', |
| 461 | + ' templating:', |
| 462 | + ' bar2: biz', |
| 463 | + ' bar3: biz', |
| 464 | + 'bar:', |
| 465 | + ' engines: ["twig","php"]', |
| 466 | + ' bar4: biz', |
| 467 | + ])); |
| 468 | + PugSymfonyEngine::install(new Event('install', $composer, $io), $dir); |
| 469 | + self::assertSame(implode("\n", [ |
| 470 | + 'foo:', |
| 471 | + ' bar: biz', |
| 472 | + 'services:', |
| 473 | + ' templating.engine.pug:', |
| 474 | + ' class: Pug\PugSymfonyEngine', |
| 475 | + ' arguments: ["@kernel"]', |
| 476 | + '', |
| 477 | + 'framework:', |
| 478 | + ' bar1: biz', |
| 479 | + ' templating:', |
| 480 | + ' bar2: biz', |
| 481 | + ' templating:', |
| 482 | + ' bar2: biz', |
| 483 | + ' bar3: biz', |
| 484 | + 'bar:', |
| 485 | + ' engines: ["twig","php"]', |
| 486 | + ' bar4: biz', |
| 487 | + ]), file_get_contents($dir . '/app/config/config.yml')); |
| 488 | + self::assertFalse(file_exists($installedFile)); |
| 489 | + } |
309 | 490 | } |
0 commit comments