|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace WebCMS\Tests; |
|
4
|
|
|
|
|
5
|
|
|
abstract class PresenterTestCase extends EntityTestCase |
|
6
|
|
|
{ |
|
7
|
|
|
protected $presenter = null; |
|
8
|
|
|
|
|
9
|
|
|
protected $presenterName; |
|
10
|
|
|
|
|
11
|
|
|
protected $language; |
|
12
|
|
|
|
|
13
|
|
|
protected $role; |
|
14
|
|
|
|
|
15
|
|
|
public $user; |
|
16
|
|
|
|
|
17
|
|
|
public function setUp() |
|
18
|
|
|
{ |
|
19
|
|
|
parent::setUp(); |
|
20
|
|
|
|
|
21
|
|
|
// init system minimal |
|
22
|
|
|
$this->language = new \WebCMS\Entity\Language(); |
|
23
|
|
|
$this->language->setName('English'); |
|
24
|
|
|
$this->language->setAbbr('en'); |
|
25
|
|
|
$this->language->setDefaultBackend(true); |
|
26
|
|
|
$this->language->setDefaultFrontend(true); |
|
27
|
|
|
$this->language->setLocale('en_US.utf8'); |
|
28
|
|
|
|
|
29
|
|
|
$this->role = new \WebCMS\Entity\Role(); |
|
30
|
|
|
$this->role->setName('superadmin'); |
|
31
|
|
|
$this->role->setAutomaticEnable(false); |
|
32
|
|
|
|
|
33
|
|
|
$this->em->persist($this->role); |
|
34
|
|
|
$this->em->flush(); |
|
35
|
|
|
|
|
36
|
|
|
$this->user = new \WebCMS\Entity\User(); |
|
37
|
|
|
$this->user->setUsername('test'); |
|
38
|
|
|
$this->user->setPassword($this->container->authenticator->calculateHash('test')); |
|
39
|
|
|
$this->user->setEmail('[email protected]'); |
|
40
|
|
|
$this->user->setName('test'); |
|
41
|
|
|
$this->user->setRole($this->role); |
|
42
|
|
|
|
|
43
|
|
|
$this->em->persist($this->language); |
|
44
|
|
|
$this->em->persist($this->user); |
|
45
|
|
|
$this->em->flush(); |
|
46
|
|
|
|
|
47
|
|
|
// login |
|
48
|
|
|
$user = new \Nette\Security\User($this->container->getService('nette.userStorage'), $this->container); |
|
49
|
|
|
$user->login('test', 'test'); |
|
50
|
|
|
|
|
51
|
|
|
// set APP_DIR to tests/app directory |
|
52
|
|
|
define("APP_DIR", __DIR__ . '/app'); |
|
53
|
|
|
|
|
54
|
|
|
// create app dir and templates dir |
|
55
|
|
|
system('mkdir ' . APP_DIR . '; mkdir ' . APP_DIR . '/templates'); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
public function tearDown() |
|
59
|
|
|
{ |
|
60
|
|
|
parent::tearDown(); |
|
61
|
|
|
|
|
62
|
|
|
system('rm -rf tests/temp/cache/* tests/temp/btfj.dat upload/* thumbnails/* tests/app'); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* @param string $name |
|
67
|
|
|
*/ |
|
68
|
|
|
protected function createPresenter($name) |
|
69
|
|
|
{ |
|
70
|
|
|
$this->presenterName = $name; |
|
71
|
|
|
|
|
72
|
|
|
$this->presenter = $this->container |
|
73
|
|
|
->getByType('Nette\Application\IPresenterFactory') |
|
74
|
|
|
->createPresenter($name); |
|
75
|
|
|
|
|
76
|
|
|
$this->presenter->autoCanonicalize = false; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
public function getResponse($response) |
|
80
|
|
|
{ |
|
81
|
|
|
$template = $response->getSource(); |
|
82
|
|
|
$template->registerHelperLoader('\WebCMS\Helpers\SystemHelper::loader'); |
|
83
|
|
|
$template->setTranslator($this->presenter->translator); |
|
84
|
|
|
$template->settings = $this->presenter->settings; |
|
85
|
|
|
|
|
86
|
|
|
$template->save(__DIR__.'/temp/cache/presenter.test'); |
|
87
|
|
|
|
|
88
|
|
|
return file_get_contents(__DIR__.'/temp/cache/presenter.test'); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
public function makeRequest($action = 'default', $method = 'GET', $params = array(), $post = array(), $do = '', $files = array()) |
|
92
|
|
|
{ |
|
93
|
|
|
$params['action'] = $action; |
|
94
|
|
|
$params['do'] = $do; |
|
95
|
|
|
|
|
96
|
|
|
$request = new \Nette\Application\Request($this->presenterName, $method, $params, $post, $files); |
|
97
|
|
|
|
|
98
|
|
|
return $this->presenter->run($request); |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
protected function createPage($module) |
|
102
|
|
|
{ |
|
103
|
|
|
$this->pageMain = new \WebCMS\Entity\Page(); |
|
|
|
|
|
|
104
|
|
|
$this->pageMain->setParent(null); |
|
105
|
|
|
$this->pageMain->setLanguage($this->language); |
|
106
|
|
|
$this->pageMain->setModule(null); |
|
107
|
|
|
$this->pageMain->setModuleName(''); |
|
108
|
|
|
$this->pageMain->setMetaTitle('meta title'); |
|
109
|
|
|
$this->pageMain->setMetaDescription('meta description'); |
|
110
|
|
|
$this->pageMain->setMetaKeywords('meta keywords'); |
|
111
|
|
|
$this->pageMain->setTitle('Main'); |
|
112
|
|
|
$this->pageMain->setPresenter('Presenter'); |
|
113
|
|
|
$this->pageMain->setVisible(true); |
|
114
|
|
|
$this->pageMain->setRedirect(false); |
|
115
|
|
|
$this->pageMain->setPath('path/to/page'); |
|
116
|
|
|
$this->pageMain->setDefault(true); |
|
117
|
|
|
$this->pageMain->setClass(''); |
|
118
|
|
|
|
|
119
|
|
|
$this->em->persist($this->pageMain); |
|
120
|
|
|
|
|
121
|
|
|
$this->page = new \WebCMS\Entity\Page(); |
|
|
|
|
|
|
122
|
|
|
$this->page->setParent($this->pageMain); |
|
123
|
|
|
$this->page->setLanguage($this->language); |
|
124
|
|
|
$this->page->setModule(null); |
|
125
|
|
|
$this->page->setModuleName($module); |
|
126
|
|
|
$this->page->setMetaTitle('meta title'); |
|
127
|
|
|
$this->page->setMetaDescription('meta description'); |
|
128
|
|
|
$this->page->setMetaKeywords('meta keywords'); |
|
129
|
|
|
$this->page->setTitle('Home'); |
|
130
|
|
|
$this->page->setPresenter('Presenter'); |
|
131
|
|
|
$this->page->setVisible(true); |
|
132
|
|
|
$this->page->setRedirect(false); |
|
133
|
|
|
$this->page->setPath('path/to/home'); |
|
134
|
|
|
$this->page->setDefault(true); |
|
135
|
|
|
$this->page->setClass('class'); |
|
136
|
|
|
|
|
137
|
|
|
$this->em->persist($this->page); |
|
138
|
|
|
} |
|
139
|
|
|
} |
|
140
|
|
|
|
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: