mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 11:28:25 +00:00
Updating HtmlHelper test to use request object.
Removing reference operators.
This commit is contained in:
parent
3983bf318d
commit
0eebda9ee1
2 changed files with 25 additions and 29 deletions
|
@ -235,7 +235,7 @@ class HtmlHelper extends AppHelper {
|
|||
if ($inline) {
|
||||
return $out;
|
||||
} else {
|
||||
$view =& ClassRegistry::getObject('view');
|
||||
$view = ClassRegistry::getObject('view');
|
||||
$view->addScript($out);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
* @since CakePHP(tm) v 1.2.0.4206
|
||||
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
|
||||
*/
|
||||
App::import('Core', array('Helper', 'AppHelper', 'ClassRegistry', 'Controller', 'Model'));
|
||||
App::import('Core', array('Helper', 'AppHelper', 'ClassRegistry', 'Controller'));
|
||||
App::import('Helper', array('Html', 'Form'));
|
||||
|
||||
if (!defined('FULL_BASE_URL')) {
|
||||
|
@ -110,8 +110,11 @@ class HtmlHelperTest extends CakeTestCase {
|
|||
* @return void
|
||||
*/
|
||||
function startTest() {
|
||||
$this->Html =& new HtmlHelper();
|
||||
$view =& new View(new TheHtmlTestController());
|
||||
$this->Html = new HtmlHelper();
|
||||
$this->Html->request = new CakeRequest(null, false);
|
||||
$this->Html->request->webroot = '';
|
||||
|
||||
$view = new View(new TheHtmlTestController());
|
||||
ClassRegistry::addObject('view', $view);
|
||||
$this->_appEncoding = Configure::read('App.encoding');
|
||||
$this->_asset = Configure::read('Asset');
|
||||
|
@ -157,6 +160,8 @@ class HtmlHelperTest extends CakeTestCase {
|
|||
* @return void
|
||||
*/
|
||||
function testLink() {
|
||||
$this->Html->request->webroot = '';
|
||||
|
||||
$result = $this->Html->link('/home');
|
||||
$expected = array('a' => array('href' => '/home'), 'preg:/\/home/', '/a');
|
||||
$this->assertTags($result, $expected);
|
||||
|
@ -289,6 +294,7 @@ class HtmlHelperTest extends CakeTestCase {
|
|||
* @return void
|
||||
*/
|
||||
function testImageTag() {
|
||||
$this->Html->request->webroot = '';
|
||||
Configure::write('Asset.timestamp', false);
|
||||
|
||||
$result = $this->Html->image('test.gif');
|
||||
|
@ -312,7 +318,7 @@ class HtmlHelperTest extends CakeTestCase {
|
|||
function testImageWithTimestampping() {
|
||||
Configure::write('Asset.timestamp', 'force');
|
||||
|
||||
$this->Html->webroot = '/';
|
||||
$this->Html->request->webroot = '/';
|
||||
$result = $this->Html->image('cake.icon.png');
|
||||
$this->assertTags($result, array('img' => array('src' => 'preg:/\/img\/cake\.icon\.png\?\d+/', 'alt' => '')));
|
||||
|
||||
|
@ -322,14 +328,12 @@ class HtmlHelperTest extends CakeTestCase {
|
|||
$result = $this->Html->image('cake.icon.png');
|
||||
$this->assertTags($result, array('img' => array('src' => 'preg:/\/img\/cake\.icon\.png\?\d+/', 'alt' => '')));
|
||||
|
||||
$webroot = $this->Html->webroot;
|
||||
$this->Html->webroot = '/testing/longer/';
|
||||
$this->Html->request->webroot = '/testing/longer/';
|
||||
$result = $this->Html->image('cake.icon.png');
|
||||
$expected = array(
|
||||
'img' => array('src' => 'preg:/\/testing\/longer\/img\/cake\.icon\.png\?[0-9]+/', 'alt' => '')
|
||||
);
|
||||
$this->assertTags($result, $expected);
|
||||
$this->Html->webroot = $webroot;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -346,7 +350,7 @@ class HtmlHelperTest extends CakeTestCase {
|
|||
App::import('Core', 'File');
|
||||
|
||||
$testfile = WWW_ROOT . 'theme' . DS . 'test_theme' . DS . 'img' . DS . '__cake_test_image.gif';
|
||||
$file =& new File($testfile, true);
|
||||
$file = new File($testfile, true);
|
||||
|
||||
App::build(array(
|
||||
'views' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views'. DS)
|
||||
|
@ -354,7 +358,7 @@ class HtmlHelperTest extends CakeTestCase {
|
|||
Configure::write('Asset.timestamp', true);
|
||||
Configure::write('debug', 1);
|
||||
|
||||
$this->Html->webroot = '/';
|
||||
$this->Html->request->webroot = '/';
|
||||
$this->Html->theme = 'test_theme';
|
||||
$result = $this->Html->image('__cake_test_image.gif');
|
||||
$this->assertTags($result, array(
|
||||
|
@ -363,8 +367,7 @@ class HtmlHelperTest extends CakeTestCase {
|
|||
'alt' => ''
|
||||
)));
|
||||
|
||||
$webroot = $this->Html->webroot;
|
||||
$this->Html->webroot = '/testing/';
|
||||
$this->Html->request->webroot = '/testing/';
|
||||
$result = $this->Html->image('__cake_test_image.gif');
|
||||
|
||||
$this->assertTags($result, array(
|
||||
|
@ -372,9 +375,8 @@ class HtmlHelperTest extends CakeTestCase {
|
|||
'src' => 'preg:/\/testing\/theme\/test_theme\/img\/__cake_test_image\.gif\?\d+/',
|
||||
'alt' => ''
|
||||
)));
|
||||
$this->Html->webroot = $webroot;
|
||||
|
||||
$dir =& new Folder(WWW_ROOT . 'theme' . DS . 'test_theme');
|
||||
$dir = new Folder(WWW_ROOT . 'theme' . DS . 'test_theme');
|
||||
$dir->delete();
|
||||
}
|
||||
|
||||
|
@ -392,7 +394,6 @@ class HtmlHelperTest extends CakeTestCase {
|
|||
$webRoot = Configure::read('App.www_root');
|
||||
Configure::write('App.www_root', TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'webroot' . DS);
|
||||
|
||||
$webroot = $this->Html->webroot;
|
||||
$this->Html->theme = 'test_theme';
|
||||
$result = $this->Html->css('webroot_test');
|
||||
$expected = array(
|
||||
|
@ -400,7 +401,6 @@ class HtmlHelperTest extends CakeTestCase {
|
|||
);
|
||||
$this->assertTags($result, $expected);
|
||||
|
||||
$webroot = $this->Html->webroot;
|
||||
$this->Html->theme = 'test_theme';
|
||||
$result = $this->Html->css('theme_webroot');
|
||||
$expected = array(
|
||||
|
@ -474,13 +474,13 @@ class HtmlHelperTest extends CakeTestCase {
|
|||
$this->assertEqual(count($result), 2);
|
||||
|
||||
ClassRegistry::removeObject('view');
|
||||
$view =& new HtmlHelperMockView();
|
||||
$view = new HtmlHelperMockView();
|
||||
ClassRegistry::addObject('view', $view);
|
||||
$view->expectAt(0, 'addScript', array(new PatternExpectation('/css_in_head.css/')));
|
||||
$result = $this->Html->css('css_in_head', null, array('inline' => false));
|
||||
$this->assertNull($result);
|
||||
|
||||
$view =& ClassRegistry::getObject('view');
|
||||
$view = ClassRegistry::getObject('view');
|
||||
$view->expectAt(1, 'addScript', array(new NoPatternExpectation('/inline=""/')));
|
||||
$result = $this->Html->css('more_css_in_head', null, array('inline' => false));
|
||||
$this->assertNull($result);
|
||||
|
@ -515,19 +515,15 @@ class HtmlHelperTest extends CakeTestCase {
|
|||
$expected['link']['href'] = 'preg:/.*css\/cake\.generic\.css\?[0-9]+/';
|
||||
$this->assertTags($result, $expected);
|
||||
|
||||
$webroot = $this->Html->webroot;
|
||||
$this->Html->webroot = '/testing/';
|
||||
$this->Html->request->webroot = '/testing/';
|
||||
$result = $this->Html->css('cake.generic');
|
||||
$expected['link']['href'] = 'preg:/\/testing\/css\/cake\.generic\.css\?[0-9]+/';
|
||||
$this->assertTags($result, $expected);
|
||||
$this->Html->webroot = $webroot;
|
||||
|
||||
$webroot = $this->Html->webroot;
|
||||
$this->Html->webroot = '/testing/longer/';
|
||||
$this->Html->request->webroot = '/testing/longer/';
|
||||
$result = $this->Html->css('cake.generic');
|
||||
$expected['link']['href'] = 'preg:/\/testing\/longer\/css\/cake\.generic\.css\?[0-9]+/';
|
||||
$this->assertTags($result, $expected);
|
||||
$this->Html->webroot = $webroot;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -607,8 +603,8 @@ class HtmlHelperTest extends CakeTestCase {
|
|||
);
|
||||
$this->assertTags($result, $expected);
|
||||
|
||||
$view =& ClassRegistry::getObject('view');
|
||||
$view =& new HtmlHelperMockView();
|
||||
$view = ClassRegistry::getObject('view');
|
||||
$view = new HtmlHelperMockView();
|
||||
$view->expectAt(0, 'addScript', array(new PatternExpectation('/script_in_head.js/')));
|
||||
$result = $this->Html->script('script_in_head', array('inline' => false));
|
||||
$this->assertNull($result);
|
||||
|
@ -648,8 +644,8 @@ class HtmlHelperTest extends CakeTestCase {
|
|||
);
|
||||
$this->assertTags($result, $expected);
|
||||
|
||||
$view =& ClassRegistry::getObject('view');
|
||||
$view =& new HtmlHelperMockView();
|
||||
$view = ClassRegistry::getObject('view');
|
||||
$view = new HtmlHelperMockView();
|
||||
$view->expectAt(0, 'addScript', array(new PatternExpectation('/window\.foo\s\=\s2;/')));
|
||||
|
||||
$result = $this->Html->scriptBlock('window.foo = 2;', array('inline' => false));
|
||||
|
@ -698,7 +694,7 @@ class HtmlHelperTest extends CakeTestCase {
|
|||
$this->assertTags($result, $expected);
|
||||
|
||||
ClassRegistry::removeObject('view');
|
||||
$View =& new HtmlHelperMockView();
|
||||
$View = new HtmlHelperMockView();
|
||||
|
||||
$View->expectOnce('addScript');
|
||||
ClassRegistry::addObject('view', $View);
|
||||
|
|
Loading…
Reference in a new issue