fixture = new t3lib_PageRenderer();
$this->fixture->setCharSet($GLOBALS['LANG']->charSet);
}
public function tearDown() {
unset(
$this->fixture
);
}
//////////////////////////////////////
// Tests for the basic functionality
//////////////////////////////////////
/**
* @test
*/
public function fixtureCanBeCreated() {
$this->assertTrue(
$this->fixture instanceof t3lib_PageRenderer
);
}
//////////////////////
// test functions
//////////////////////
/**
* test set xml prolog and doctype
*
*/
public function testSetXmlPrologAndDocType() {
$expectedReturnValue = '';
$this->fixture->setXmlPrologAndDocType('');
$out = $this->fixture->render();
$this->assertContains(
$expectedReturnValue,
$out
);
}
/**
* test set title
*
*/
public function testSetTitle() {
$expectedReturnValue = '
This is the title';
$this->fixture->setTitle('This is the title');
$out = $this->fixture->render();
$this->assertContains(
$expectedReturnValue,
$out
);
}
/**
* test set charset
*
*/
public function testSetCharset() {
$expectedReturnValue = '';
$this->fixture->setCharset('utf-8');
$out = $this->fixture->render();
$this->assertContains(
$expectedReturnValue,
$out
);
}
/**
* test set favicon
*
*/
public function testSetFavIcon() {
$expectedReturnValue1 = '';
$expectedReturnValue2 = '';
$this->fixture->setFavIcon('http://google.com/favicon.ico');
$out = $this->fixture->render();
$this->assertContains(
$expectedReturnValue1,
$out
);
$this->assertContains(
$expectedReturnValue2,
$out
);
}
/**
* test set baseUrl
*
*/
public function testSetBaseUrl() {
$expectedReturnValue = '';
$this->fixture->setBaseUrl('http://ggogle.com/');
$out = $this->fixture->render();
$this->assertContains(
$expectedReturnValue,
$out
);
}
/**
* test add meta tag
*
*/
public function testAddMetaTag() {
$expectedReturnValue = '';
$this->fixture->addMetaTag('');
$out = $this->fixture->render();
$this->assertContains(
$expectedReturnValue,
$out
);
}
/**
* test add inline comment
*
*/
public function testAddInlineComment() {
$expectedReturnValue = 'this is an inline comment written by unit test';
$this->fixture->addInlineComment('this is an inline comment written by unit test');
$out = $this->fixture->render();
$this->assertContains(
$expectedReturnValue,
$out
);
}
/**
* test add header data
*
*/
public function testAddHeaderData() {
$expectedReturnValue = '';
$this->fixture->addHeaderData('');
$out = $this->fixture->render();
$this->assertContains(
$expectedReturnValue,
$out
);
}
/**
* test add footer data
*
*/
public function testAddFooterData() {
$expectedReturnValue = '';
$this->fixture->addFooterData('');
$out = $this->fixture->render(t3lib_PageRenderer::PART_FOOTER);
$this->assertContains(
$expectedReturnValue,
$out
);
}
/**
* test add JS library file
*
*/
public function testAddJsLibrary() {
$expectedRegExp = '##';
$this->fixture->addJsLibrary('test', 'fileadmin/test.js');
$out = $this->fixture->render();
$this->assertRegExp(
$expectedRegExp,
$out
);
}
/**
* test add JS footer library file
*
*/
public function testAddJsFooterLibrary() {
$expectedRegExp = '##';
$this->fixture->addJsFooterLibrary('test', 'fileadmin/test.js');
$out = $this->fixture->render(t3lib_PageRenderer::PART_FOOTER);
$this->assertRegExp(
$expectedRegExp,
$out
);
}
/**
* test add JS file
*
*/
public function testAddJsFile() {
$expectedRegExp = '##';
$this->fixture->addJsFile('fileadmin/test.js');
$out = $this->fixture->render();
$this->assertRegExp(
$expectedRegExp,
$out
);
}
/**
* test add JS file for footer
*
*/
public function testAddJsFooterFile() {
$expectedRegExp = '##';
$this->fixture->addJsFooterFile('fileadmin/test.js');
$out = $this->fixture->render(t3lib_PageRenderer::PART_FOOTER);
$this->assertRegExp(
$expectedRegExp,
$out
);
}
/**
* test add JS inline
*
*/
public function testAddJsInlineCode() {
$expectedReturnValue = 'var x = "testvar"';
$this->fixture->addJsInlineCode('test', 'var x = "testvar"');
$out = $this->fixture->render();
$this->assertContains(
$expectedReturnValue,
$out
);
}
/**
* test add JS inline for footer
*
*/
public function testAddJsFooterInlineCode() {
$expectedReturnValue = 'var x = "testvar"';
$this->fixture->addJsFooterInlineCode('test', 'var x = "testvar"');
$out = $this->fixture->render(t3lib_PageRenderer::PART_FOOTER);
$this->assertContains(
$expectedReturnValue,
$out
);
}
/**
* test add JS handler
*
*/
public function testAddExtOnReadyCode() {
$expectedReturnValue1 = 'Ext.onReady(function() {';
$expectedReturnValue2 = 'var x = "testvar";';
$this->fixture->loadExtJS();
$this->fixture->addExtOnReadyCode('var x = "testvar";');
$out = $this->fixture->render();
$this->assertContains(
$expectedReturnValue1,
$out
);
$this->assertContains(
$expectedReturnValue2,
$out
);
}
/**
* test add CSS file
*
*/
public function testAddCssFile() {
$expectedReturnValue = '';
$this->fixture->addCssFile('fileadmin/test.css');
$out = $this->fixture->render();
$this->assertContains(
$expectedReturnValue,
$out
);
}
/**
* test add CSS inline
*
*/
public function testAddCssInlineBlock() {
$expectedReturnValue = 'body {margin:20px;}';
$this->fixture->addCssInlineBlock('general', 'body {margin:20px;}');
$out = $this->fixture->render();
$this->assertContains(
$expectedReturnValue,
$out
);
}
/**
* test add CSS inline and force on top
*
*/
public function testAddCssInlineBlockForceOnTop() {
$expectedReturnValue = '/*general1*/' . LF . 'h1 {margin:20px;}' . LF . '/*general*/' . LF . 'body {margin:20px;}';
$this->fixture->addCssInlineBlock('general', 'body {margin:20px;}');
$this->fixture->addCssInlineBlock('general1', 'h1 {margin:20px;}', NULL, TRUE);
$out = $this->fixture->render();
$this->assertContains(
$expectedReturnValue,
$out
);
}
/**
* test load prototype
*
*/
public function testLoadPrototype() {
$expectedRegExp = '##';
$this->fixture->loadPrototype();
$out = $this->fixture->render();
$this->assertRegExp(
$expectedRegExp,
$out
);
}
/**
* test load Scriptaculous
*
*/
public function testLoadScriptaculous() {
$this->fixture->loadScriptaculous('slider,controls');
$out = $this->fixture->render();
$this->assertContains(
'',
$out
);
$this->assertContains(
'',
$out
);
$this->assertContains(
'',
$out
);
$this->assertContains(
'',
$out
);
}
/**
* Tests whether scriptaculous is loaded correctly when compression is enabled.
*
* @test
*/
public function isScriptaculousLoadedCompressedIfConfiguredAndClientIsCapable() {
$_SERVER['HTTP_ACCEPT_ENCODING'] = 'gzip,deflate';
$GLOBALS['TYPO3_CONF_VARS']['BE']['compressionLevel'] = '5';
$this->fixture->loadScriptaculous('slider,controls');
$this->fixture->enableCompressJavascript();
$out = $this->fixture->render();
$this->assertRegExp(
'##',
$out
);
$this->assertRegExp(
'##',
$out
);
$this->assertRegExp(
'##',
$out
);
$this->assertRegExp(
'##',
$out
);
}
/**
* Tests whether scriptaculous is correctly loaded, but without compression
* if the browser did not send the appropriate headers.
*
* @test
*/
public function isScriptaculousNotLoadedCompressedIfClientCannotHandleCompression() {
$_SERVER['HTTP_ACCEPT_ENCODING'] = '';
$GLOBALS['TYPO3_CONF_VARS']['BE']['compressionLevel'] = '5';
$this->fixture->loadScriptaculous('slider,controls');
$this->fixture->enableCompressJavascript();
$out = $this->fixture->render();
$this->assertRegExp(
'##',
$out
);
$this->assertRegExp(
'##',
$out
);
$this->assertRegExp(
'##',
$out
);
$this->assertRegExp(
'##',
$out
);
}
/**
* Tests whether scriptaculous is correctly loaded, but without compression
* if no compression is configured.
*
* @test
*/
public function isScriptaculousNotLoadedCompressedIfCompressionIsNotConfigured() {
$_SERVER['HTTP_ACCEPT_ENCODING'] = 'gzip,deflate';
$GLOBALS['TYPO3_CONF_VARS']['BE']['compressionLevel'] = '';
$this->fixture->loadScriptaculous('slider,controls');
$this->fixture->enableCompressJavascript();
$out = $this->fixture->render();
$this->assertRegExp(
'##',
$out
);
$this->assertRegExp(
'##',
$out
);
$this->assertRegExp(
'##',
$out
);
$this->assertRegExp(
'##',
$out
);
}
/**
* test load ExtJS
*
*/
public function testLoadExtJS() {
$expectedRegExp = '#' . LF . '#m';
$this->fixture->loadExtJS(TRUE, TRUE, 'jquery');
$out = $this->fixture->render();
$this->assertRegExp(
$expectedRegExp,
$out
);
}
/**
* test load ExtCore
*
*/
public function testLoadExtCore() {
$expectedRegExp = '##';
$this->fixture->loadExtCore();
$out = $this->fixture->render();
$this->assertRegExp(
$expectedRegExp,
$out
);
}
/**
* test enable ExtJsDebug
*
*/
public function testEnableExtJsDebug() {
$expectedRegExp = '##';
$this->fixture->loadExtJS(TRUE, TRUE, 'jquery');
$this->fixture->enableExtJsDebug();
$out = $this->fixture->render();
$this->assertRegExp(
$expectedRegExp,
$out
);
}
/**
* test enable ExtCoreDebug
*
*/
public function testEnableExtCoreDebug() {
$expectedRegExp = '##';
$this->fixture->loadExtCore();
$this->fixture->enableExtCoreDebug();
$out = $this->fixture->render();
$this->assertRegExp(
$expectedRegExp,
$out
);
}
/**
* test inline language label
*
*/
public function testAddInlineLanguageLabel() {
$expectedReturnValue = 'TYPO3.lang = {"myKey":"myValue"}';
$this->fixture->loadExtJS();
$this->fixture->addInlineLanguageLabel('myKey', 'myValue');
$out = $this->fixture->enableMoveJsFromHeaderToFooter();
$out = $this->fixture->render(t3lib_PageRenderer::PART_FOOTER);
$this->assertContains(
$expectedReturnValue,
$out
);
}
/**
* test inline language label as array
*
*/
public function testAddInlineLanguageLabelArray() {
$expectedReturnValue = 'TYPO3.lang = {"myKey1":"myValue1","myKey2":"myValue2"}';
$this->fixture->loadExtJS();
$this->fixture->addInlineLanguageLabelArray(array('myKey1' => 'myValue1', 'myKey2' => 'myValue2',));
$out = $this->fixture->enableMoveJsFromHeaderToFooter();
$out = $this->fixture->render(t3lib_PageRenderer::PART_FOOTER);
$this->assertContains(
$expectedReturnValue,
$out
);
}
/**
* test inline language label as array get merged
*
*/
public function testAddInlineLanguageLabelArrayMerged() {
$expectedReturnValue = 'TYPO3.lang = {"myKey1":"myValue1","myKey2":"myValue2"}';
$this->fixture->loadExtJS();
$this->fixture->addInlineLanguageLabelArray(array('myKey1' => 'myValue1',));
$this->fixture->addInlineLanguageLabelArray(array('myKey2' => 'myValue2',));
$out = $this->fixture->enableMoveJsFromHeaderToFooter();
$out = $this->fixture->render(t3lib_PageRenderer::PART_FOOTER);
$this->assertContains(
$expectedReturnValue,
$out
);
}
/**
* test inline setting
*
*/
public function testAddInlineSetting() {
$expectedReturnValue = 'TYPO3.settings = {"myApp":{"myKey":"myValue"}};';
$this->fixture->loadExtJS();
$this->fixture->addInlineSetting('myApp', 'myKey', 'myValue');
$out = $this->fixture->enableMoveJsFromHeaderToFooter();
$out = $this->fixture->render(t3lib_PageRenderer::PART_FOOTER);
$this->assertContains(
$expectedReturnValue,
$out
);
}
/**
* test inline settings with array
*
*/
public function testAddInlineSettingArray() {
$expectedReturnValue = 'TYPO3.settings = {"myApp":{"myKey1":"myValue1","myKey2":"myValue2"}};';
$this->fixture->loadExtJS();
$this->fixture->addInlineSettingArray('myApp', array('myKey1' => 'myValue1', 'myKey2' => 'myValue2',));
$out = $this->fixture->enableMoveJsFromHeaderToFooter();
$out = $this->fixture->render(t3lib_PageRenderer::PART_FOOTER);
$this->assertContains(
$expectedReturnValue,
$out
);
}
/**
* test inline settings with array get merged
*
*/
public function testAddInlineSettingArrayMerged() {
$expectedReturnValue = 'TYPO3.settings = {"myApp":{"myKey1":"myValue1","myKey2":"myValue2"}};';
$this->fixture->loadExtJS();
$this->fixture->addInlineSettingArray('myApp', array('myKey1' => 'myValue1',));
$this->fixture->addInlineSettingArray('myApp', array('myKey2' => 'myValue2',));
$out = $this->fixture->enableMoveJsFromHeaderToFooter();
$out = $this->fixture->render(t3lib_PageRenderer::PART_FOOTER);
$this->assertContains(
$expectedReturnValue,
$out
);
}
/**
* test add body content
*
*/
public function testAddBodyContent() {
$expectedReturnValue = 'ABCDE';
$this->fixture->addBodyContent('A');
$this->fixture->addBodyContent('B');
$this->fixture->addBodyContent('C');
$this->fixture->addBodyContent('D');
$this->fixture->addBodyContent('E');
$out = $this->fixture->getBodyContent();
$this->assertEquals(
$expectedReturnValue,
$out
);
}
/**
* test set body content
*
*/
public function testSetBodyContent() {
$expectedReturnValue = 'ABCDE';
$this->fixture->setBodyContent('ABCDE');
$out = $this->fixture->getBodyContent();
$this->assertEquals(
$expectedReturnValue,
$out
);
$out = $this->fixture->render();
$this->assertContains(
$expectedReturnValue,
$out
);
}
/**
* Tests whether labels are delivered in a non-UTF-8 context.
* (background: json_encode() requires UTF-8 to work properly)
*
* @test
*/
public function isInlineLanguageLabelDeliveredWithNonUTF8() {
$testPrefix = uniqid('test');
$this->fixture->loadExtCore();
$this->fixture->setCharSet('iso-8859-1');
$this->fixture->addInlineLanguageLabel($testPrefix, $testPrefix . "_\xd8");
$out = $this->fixture->render();
$this->assertContains($testPrefix . '_\\u00d8', $out);
}
/**
* Tests the addInlineLanguageLabelFile() method.
*
* @test
* @expectedException RuntimeException
*/
public function areInlineLanguageLabelsNotProcessable() {
$this->fixture->setLanguage(NULL);
$this->fixture->addInlineLanguageLabelFile(
'EXT:lang/locallang_core.xml'
);
$out = $this->fixture->render();
}
/**
* Tests the addInlineLanguageLabelFile() method.
*
* @test
*/
public function areInlineLanguageLabelsPassed() {
$this->fixture->setLanguage($GLOBALS['LANG']->lang);
$this->fixture->addInlineLanguageLabelFile(
'EXT:lang/locallang_core.xml'
);
$out = $this->fixture->render();
$this->assertContains('labels.beUser', $out);
$this->assertContains('labels.feUser', $out);
}
/**
* Tests the addInlineLanguageLabelFile() method.
*
* @test
*/
public function areInlineLanguageLabelsEmptyOnNonExistingFile() {
$this->fixture->addInlineLanguageLabelFile(
''
);
$inlineLanguageLabelFiles = $this->fixture->getInlineLanguageLabelFiles();
$this->assertEquals(array(), $inlineLanguageLabelFiles);
}
/**
* Tests the addInlineLanguageLabelFile() method.
*
* @test
*/
public function areInlineLanguageLabelsSelected() {
$this->fixture->setLanguage($GLOBALS['LANG']->lang);
$this->fixture->addInlineLanguageLabelFile(
'EXT:lang/locallang_core.xml',
'labels.'
);
$out = $this->fixture->render();
$this->assertContains('labels.beUser', $out);
$this->assertContains('labels.feUser', $out);
}
/**
* Tests the addInlineLanguageLabelFile() method.
*
* @test
*/
public function areInlineLanguageLabelsSelectedAndStripped() {
$this->fixture->setLanguage($GLOBALS['LANG']->lang);
$this->fixture->addInlineLanguageLabelFile(
'EXT:lang/locallang_core.xml',
'labels.',
'lock'
);
$out = $this->fixture->render();
$this->assertContains('edRecord', $out);
$this->assertContains('edRecord_content', $out);
$this->assertContains('edRecordUser', $out);
}
}
?>