|
| 1 | +<?php |
| 2 | + |
| 3 | +/** |
| 4 | + * Test: ApplicationExtension |
| 5 | + */ |
| 6 | + |
| 7 | +use Nette\DI, |
| 8 | + Nette\Bridges\ApplicationDI\ApplicationExtension, |
| 9 | + Nette\Application\UI\Presenter, |
| 10 | + Tester\Assert; |
| 11 | + |
| 12 | + |
| 13 | +require __DIR__ . '/../bootstrap.php'; |
| 14 | +require __DIR__ . '/files/MyPresenter.php'; |
| 15 | + |
| 16 | + |
| 17 | +function createCompiler($config) |
| 18 | +{ |
| 19 | + $compiler = new DI\Compiler; |
| 20 | + $compiler->loadConfig(Tester\FileMock::create($config, 'neon')); |
| 21 | + $builder = $compiler->getContainerBuilder(); |
| 22 | + $builder->addDefinition('myRouter')->setClass('Nette\Application\Routers\SimpleRouter'); |
| 23 | + $builder->addDefinition('myHttpRequest')->setFactory('Nette\Http\Request', array(new DI\Statement('Nette\Http\UrlScript'))); |
| 24 | + $builder->addDefinition('myHttpResponse')->setClass('Nette\Http\Response'); |
| 25 | + return $compiler; |
| 26 | +} |
| 27 | + |
| 28 | + |
| 29 | +test(function() { |
| 30 | + $compiler = createCompiler(' |
| 31 | + application: |
| 32 | + debugger: no |
| 33 | + silentLinks: yes |
| 34 | +
|
| 35 | + services: |
| 36 | + presenter: Presenter1 |
| 37 | + '); |
| 38 | + $compiler->addExtension('application', new ApplicationExtension(TRUE)); |
| 39 | + $code = $compiler->compile(NULL, 'Container4'); |
| 40 | + eval($code); |
| 41 | + |
| 42 | + $container = new Container4; |
| 43 | + Assert::same( |
| 44 | + Presenter::INVALID_LINK_TEXTUAL, |
| 45 | + $container->getService('presenter')->invalidLinkMode |
| 46 | + ); |
| 47 | +}); |
| 48 | + |
| 49 | + |
| 50 | +test(function() { |
| 51 | + $compiler = createCompiler(' |
| 52 | + application: |
| 53 | + debugger: no |
| 54 | + silentLinks: no |
| 55 | +
|
| 56 | + services: |
| 57 | + presenter: Presenter1 |
| 58 | + '); |
| 59 | + $compiler->addExtension('application', new ApplicationExtension(TRUE)); |
| 60 | + $code = $compiler->compile(NULL, 'Container5'); |
| 61 | + eval($code); |
| 62 | + |
| 63 | + $container = new Container5; |
| 64 | + Assert::same( |
| 65 | + Presenter::INVALID_LINK_WARNING | Presenter::INVALID_LINK_TEXTUAL, |
| 66 | + $container->getService('presenter')->invalidLinkMode |
| 67 | + ); |
| 68 | +}); |
| 69 | + |
| 70 | + |
| 71 | +test(function() { |
| 72 | + $compiler = createCompiler(' |
| 73 | + application: |
| 74 | + debugger: no |
| 75 | + silentLinks: yes |
| 76 | +
|
| 77 | + services: |
| 78 | + presenter: Presenter1 |
| 79 | + '); |
| 80 | + $compiler->addExtension('application', new ApplicationExtension(FALSE)); |
| 81 | + $code = $compiler->compile(NULL, 'Container6'); |
| 82 | + eval($code); |
| 83 | + |
| 84 | + $container = new Container6; |
| 85 | + Assert::same( |
| 86 | + Presenter::INVALID_LINK_WARNING, |
| 87 | + $container->getService('presenter')->invalidLinkMode |
| 88 | + ); |
| 89 | +}); |
| 90 | + |
| 91 | + |
| 92 | +test(function() { |
| 93 | + $compiler = createCompiler(' |
| 94 | + application: |
| 95 | + debugger: no |
| 96 | + silentLinks: no |
| 97 | +
|
| 98 | + services: |
| 99 | + presenter: Presenter1 |
| 100 | + '); |
| 101 | + $compiler->addExtension('application', new ApplicationExtension(FALSE)); |
| 102 | + $code = $compiler->compile(NULL, 'Container7'); |
| 103 | + eval($code); |
| 104 | + |
| 105 | + $container = new Container7; |
| 106 | + Assert::same( |
| 107 | + Presenter::INVALID_LINK_WARNING, |
| 108 | + $container->getService('presenter')->invalidLinkMode |
| 109 | + ); |
| 110 | +}); |
0 commit comments