Skip to content

Commit 39d0226

Browse files
author
Raymond Kolbe
committed
Bootstrap now supports loading modules. Wrote a couple of new tests.
1 parent 8425495 commit 39d0226

File tree

5 files changed

+119
-30
lines changed

5 files changed

+119
-30
lines changed

.travis/application.config.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
return array(
3+
'modules' => array(
4+
'Application',
5+
'DOMPDFModule',
6+
),
7+
'module_listener_options' => array(
8+
'config_glob_paths' => array(
9+
'config/autoload/{,*.}{global,local}.php',
10+
),
11+
'config_cache_enabled' => false,
12+
'cache_dir' => 'data/cache',
13+
'module_paths' => array(
14+
'./module',
15+
'./vendor',
16+
),
17+
),
18+
'service_manager' => array(
19+
'use_defaults' => true,
20+
'factories' => array(
21+
),
22+
),
23+
);

tests/Bootstrap.php

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,37 @@
11
<?php
22

3-
use Zend\Loader\AutoloaderFactory;
3+
use Zend\ServiceManager\ServiceManager;
4+
use Zend\Mvc\Service\ServiceManagerConfiguration;
45

56
error_reporting( E_ALL | E_STRICT );
67

7-
$zfCoreLibrary = realpath(dirname(__DIR__)) . "/../../zendframework/zendframework/library";
8-
$coreTests = realpath(dirname(__DIR__)) . "/tests";
9-
10-
$path = array(
11-
$zfCoreLibrary,
12-
$coreTests,
13-
get_include_path(),
14-
);
15-
16-
set_include_path(implode(PATH_SEPARATOR, $path));
8+
chdir(__DIR__);
9+
10+
$previousDir = '.';
11+
while (!file_exists('config/application.config.php')) {
12+
$dir = dirname(getcwd());
13+
if($previousDir === $dir) {
14+
throw new RuntimeException(
15+
'Unable to locate "config/application.config.php": ' .
16+
'is DOMPDFModule in a subdir of your application skeleton?'
17+
);
18+
}
19+
$previousDir = $dir;
20+
chdir($dir);
21+
}
1722

18-
/**
19-
* Setup autoloading - Based on PHP Composer autoload.
20-
*/
23+
if (is_readable(__DIR__ . '/TestConfiguration.php')) {
24+
$configuration = include_once __DIR__ . '/TestConfiguration.php';
25+
} else {
26+
$configuration = include_once __DIR__ . '/TestConfiguration.php.dist';
27+
}
2128

22-
chdir(dirname(__DIR__));
29+
// Assumes PHP Composer autoloader w/compiled classmaps, etc.
30+
require_once('vendor/autoload.php');
2331

24-
if (file_exists(dirname(__DIR__) . '/../../autoload.php')) {
25-
$loader = include dirname(__DIR__) . '/../../autoload.php';
26-
}
32+
$serviceManager = new ServiceManager(new ServiceManagerConfiguration($configuration['service_manager']));
33+
$serviceManager->setService('ApplicationConfiguration', $configuration);
34+
$serviceManager->setAllowOverride(true);
2735

28-
/*
29-
* Load the user-defined test configuration file, if it exists; otherwise, load
30-
* the default configuration.
31-
*/
32-
//if (is_readable($zfCoreTests . DIRECTORY_SEPARATOR . 'TestConfiguration.php')) {
33-
// require_once $zfCoreTests . DIRECTORY_SEPARATOR . 'TestConfiguration.php';
34-
//} else {
35-
// require_once $zfCoreTests . DIRECTORY_SEPARATOR . 'TestConfiguration.php.dist';
36-
//}
37-
38-
unset($coreTests, $zfCoreLibrary, $path);
36+
$moduleManager = $serviceManager->get('ModuleManager');
37+
$moduleManager->loadModules();

tests/DOMPDFModuleTest/View/Strategy/PdfStrategyTest.php

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
namespace DOMPDFModuleTest\View\Strategy;
44

5+
use Zend\Filter\RealPath;
6+
7+
use Zend\View\Resolver\TemplatePathStack;
8+
59
use PHPUnit_Framework_TestCase as TestCase;
610
use Zend\EventManager\EventManager;
711
use Zend\Http\Request as HttpRequest;
@@ -20,6 +24,11 @@ public function setUp()
2024
$this->strategy = new PdfStrategy($this->renderer);
2125
$this->event = new ViewEvent();
2226
$this->response = new HttpResponse();
27+
28+
$this->resolver = new TemplatePathStack();
29+
$this->resolver->addPath(dirname(__DIR__) . '/_templates');
30+
31+
$this->renderer->setResolver($this->resolver);
2332
}
2433

2534
public function testPdfModelSelectsPdfStrategy()
@@ -28,4 +37,43 @@ public function testPdfModelSelectsPdfStrategy()
2837
$result = $this->strategy->selectRenderer($this->event);
2938
$this->assertSame($this->renderer, $result);
3039
}
31-
}
40+
41+
public function testContentTypeResponseHeader()
42+
{
43+
$model = new PdfModel();
44+
$model->setTemplate('basic.phtml');
45+
46+
$this->event->setModel($model);
47+
$this->event->setResponse($this->response);
48+
$this->event->setRenderer($this->renderer);
49+
$this->event->setResult($this->renderer->render($model));
50+
51+
$this->strategy->injectResponse($this->event);
52+
53+
$headers = $this->event->getResponse()->headers();
54+
$contentTypeHeader = $headers->get('content-type');
55+
56+
$this->assertInstanceof('Zend\Http\Header\ContentType', $contentTypeHeader);
57+
$this->assertEquals($contentTypeHeader->getFieldValue(), 'application/pdf');
58+
}
59+
60+
public function testResponseHeadersWithFileName()
61+
{
62+
$model = new PdfModel();
63+
$model->setTemplate('basic.phtml');
64+
$model->setOption('filename', 'testPdfFileName.pdf');
65+
66+
$this->event->setModel($model);
67+
$this->event->setResponse($this->response);
68+
$this->event->setRenderer($this->renderer);
69+
$this->event->setResult($this->renderer->render($model));
70+
71+
$this->strategy->injectResponse($this->event);
72+
73+
$headers = $this->event->getResponse()->headers();
74+
$contentDispositionHeader = $headers->get('Content-Disposition');
75+
76+
$this->assertInstanceof('Zend\Http\Header\ContentDisposition', $contentDispositionHeader);
77+
$this->assertEquals($contentDispositionHeader->getFieldValue(), 'attachment; filename=testPdfFileName.pdf');
78+
}
79+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<p>
2+
Hello World!
3+
</p>

tests/TestConfiguration.php.dist

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
return array(
3+
'modules' => array(
4+
'DOMPDFModule',
5+
),
6+
'module_listener_options' => array(
7+
'config_cache_enabled' => false,
8+
'cache_dir' => 'data/cache',
9+
'module_paths' => array(
10+
'./vendor',
11+
),
12+
),
13+
'service_manager' => array(
14+
'use_defaults' => true,
15+
),
16+
);

0 commit comments

Comments
 (0)