-
Notifications
You must be signed in to change notification settings - Fork 234
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[FEATURE] Context view helpers #735
Merged
NamelessCoder
merged 1 commit into
FluidTYPO3:development
from
BenjaminBeck:FEATURE_Context_view_helpers
Dec 12, 2014
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
64 changes: 64 additions & 0 deletions
64
Classes/ViewHelpers/Condition/Context/IsDevelopmentViewHelper.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?php | ||
namespace FluidTYPO3\Vhs\ViewHelpers\Condition\Context; | ||
|
||
/*************************************************************** | ||
* Copyright notice | ||
* (c) 2014 Benjamin Beck <[email protected]> | ||
* All rights reserved | ||
* This script is part of the TYPO3 project. The TYPO3 project is | ||
* free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 2 of the License, or | ||
* (at your option) any later version. | ||
* The GNU General Public License can be found at | ||
* http://www.gnu.org/copyleft/gpl.html. | ||
* This script is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* This copyright notice MUST APPEAR in all copies of the script! | ||
* ************************************************************* */ | ||
|
||
use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractConditionViewHelper; | ||
use TYPO3\CMS\Core\Utility\GeneralUtility; | ||
|
||
/** | ||
* ### Context: IsDevelopment | ||
* | ||
* Returns true if current root application context is development otherwise false. | ||
* If no application context has been set, then the default context is production. | ||
* | ||
* #### Note about how to set the application context | ||
* | ||
* The context TYPO3 CMS runs in is specified through the environment variable TYPO3_CONTEXT. | ||
* It can be set by .htaccess or in the server configuration | ||
* | ||
* See: http://docs.typo3.org/typo3cms/CoreApiReference/ApiOverview/Bootstrapping/Index.html#bootstrapping-context | ||
* | ||
* @author Benjamin Beck <[email protected]> | ||
* @package Vhs | ||
* @subpackage ViewHelpers\Condition\Context | ||
*/ | ||
class IsDevelopmentViewHelper extends AbstractConditionViewHelper { | ||
|
||
/** | ||
* Render method | ||
* | ||
* @return string | ||
*/ | ||
public function render () { | ||
if (TRUE === $this->isDevelopmentContext()) { | ||
return $this->renderThenChild(); | ||
} | ||
|
||
return $this->renderElseChild(); | ||
} | ||
|
||
|
||
/** | ||
* @return boolean | ||
*/ | ||
protected function isDevelopmentContext () { | ||
return GeneralUtility::getApplicationContext()->isDevelopment(); | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
Classes/ViewHelpers/Condition/Context/IsProductionViewHelper.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?php | ||
namespace FluidTYPO3\Vhs\ViewHelpers\Condition\Context; | ||
|
||
/*************************************************************** | ||
* Copyright notice | ||
* (c) 2014 Benjamin Beck <[email protected]> | ||
* All rights reserved | ||
* This script is part of the TYPO3 project. The TYPO3 project is | ||
* free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 2 of the License, or | ||
* (at your option) any later version. | ||
* The GNU General Public License can be found at | ||
* http://www.gnu.org/copyleft/gpl.html. | ||
* This script is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* This copyright notice MUST APPEAR in all copies of the script! | ||
* ************************************************************* */ | ||
|
||
use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractConditionViewHelper; | ||
use TYPO3\CMS\Core\Utility\GeneralUtility; | ||
|
||
/** | ||
* ### Context: IsProduction | ||
* | ||
* Returns true if current root application context is production otherwise false. | ||
* If no application context has been set, then this is the default context. | ||
* | ||
* #### Note about how to set the application context | ||
* | ||
* The context TYPO3 CMS runs in is specified through the environment variable TYPO3_CONTEXT. | ||
* It can be set by .htaccess or in the server configuration | ||
* | ||
* See: http://docs.typo3.org/typo3cms/CoreApiReference/ApiOverview/Bootstrapping/Index.html#bootstrapping-context | ||
* | ||
* @author Benjamin Beck <[email protected]> | ||
* @package Vhs | ||
* @subpackage ViewHelpers\Condition\Context | ||
*/ | ||
class IsProductionViewHelper extends AbstractConditionViewHelper { | ||
|
||
/** | ||
* Render method | ||
* | ||
* @return string | ||
*/ | ||
public function render () { | ||
if (TRUE === $this->isProductionContext()) { | ||
return $this->renderThenChild(); | ||
} | ||
|
||
return $this->renderElseChild(); | ||
} | ||
|
||
|
||
/** | ||
* @return boolean | ||
*/ | ||
protected function isProductionContext () { | ||
return GeneralUtility::getApplicationContext()->isProduction(); | ||
} | ||
|
||
} |
65 changes: 65 additions & 0 deletions
65
Classes/ViewHelpers/Condition/Context/IsTestingViewHelper.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?php | ||
namespace FluidTYPO3\Vhs\ViewHelpers\Condition\Context; | ||
|
||
/*************************************************************** | ||
* Copyright notice | ||
* (c) 2014 Benjamin Beck <[email protected]> | ||
* All rights reserved | ||
* This script is part of the TYPO3 project. The TYPO3 project is | ||
* free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 2 of the License, or | ||
* (at your option) any later version. | ||
* The GNU General Public License can be found at | ||
* http://www.gnu.org/copyleft/gpl.html. | ||
* This script is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* This copyright notice MUST APPEAR in all copies of the script! | ||
* ************************************************************* */ | ||
|
||
use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractConditionViewHelper; | ||
use TYPO3\CMS\Core\Utility\GeneralUtility; | ||
|
||
/** | ||
* ### Context: IsProduction | ||
* | ||
* Returns true if current root application context is testing otherwise false. | ||
* If no application context has been set, then the default context is production. | ||
* | ||
* #### Note about how to set the application context | ||
* | ||
* The context TYPO3 CMS runs in is specified through the environment variable TYPO3_CONTEXT. | ||
* It can be set by .htaccess or in the server configuration | ||
* | ||
* See: http://docs.typo3.org/typo3cms/CoreApiReference/ApiOverview/Bootstrapping/Index.html#bootstrapping-context | ||
* | ||
* @author Benjamin Beck <[email protected]> | ||
* @package Vhs | ||
* @subpackage ViewHelpers\Condition\Context | ||
*/ | ||
class IsTestingViewHelper extends AbstractConditionViewHelper { | ||
|
||
/** | ||
* Render method | ||
* | ||
* @return string | ||
*/ | ||
public function render () { | ||
if (TRUE === $this->isTestingContext()) { | ||
return $this->renderThenChild(); | ||
} | ||
|
||
return $this->renderElseChild(); | ||
} | ||
|
||
|
||
/** | ||
* @return boolean | ||
*/ | ||
protected function isTestingContext () { | ||
return GeneralUtility::getApplicationContext()->isTesting(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
namespace FluidTYPO3\Vhs\ViewHelpers\Context; | ||
|
||
/*************************************************************** | ||
* Copyright notice | ||
* (c) 2014 Benjamin Beck <[email protected]> | ||
* All rights reserved | ||
* This script is part of the TYPO3 project. The TYPO3 project is | ||
* free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 2 of the License, or | ||
* (at your option) any later version. | ||
* The GNU General Public License can be found at | ||
* http://www.gnu.org/copyleft/gpl.html. | ||
* This script is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* This copyright notice MUST APPEAR in all copies of the script! | ||
* ************************************************************* */ | ||
|
||
use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper; | ||
use TYPO3\CMS\Core\Utility\GeneralUtility; | ||
|
||
/** | ||
* ### Context: Get | ||
* | ||
* Returns the current application context which may include possible sub-contexts. | ||
* The application context can be 'Production', 'Development' or 'Testing'. | ||
* Additionally each context can be extended with custom sub-contexts like: 'Production/Staging' or ' Production/Staging/Server1'. | ||
* If no application context has been set by the configuration, then the default context is 'Production'. | ||
* | ||
* #### Note about how to set the application context | ||
* | ||
* The context TYPO3 CMS runs in is specified through the environment variable TYPO3_CONTEXT. | ||
* It can be set by .htaccess or in the server configuration | ||
* | ||
* See: http://docs.typo3.org/typo3cms/CoreApiReference/ApiOverview/Bootstrapping/Index.html#bootstrapping-context | ||
* | ||
* @author Benjamin Beck <[email protected]> | ||
* @package Vhs | ||
* @subpackage ViewHelpers\Context | ||
*/ | ||
class GetViewHelper extends AbstractViewHelper { | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function render () { | ||
return (string) GeneralUtility::getApplicationContext(); | ||
} | ||
|
||
} |
65 changes: 65 additions & 0 deletions
65
Tests/Unit/ViewHelpers/Condition/Context/IsDevelopmentViewHelperTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?php | ||
namespace FluidTYPO3\Vhs\ViewHelpers\Condition\Context; | ||
|
||
/*************************************************************** | ||
* Copyright notice | ||
* (c) 2014 Benjamin Beck <[email protected]> | ||
* All rights reserved | ||
* This script is part of the TYPO3 project. The TYPO3 project is | ||
* free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 2 of the License, or | ||
* (at your option) any later version. | ||
* The GNU General Public License can be found at | ||
* http://www.gnu.org/copyleft/gpl.html. | ||
* This script is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* This copyright notice MUST APPEAR in all copies of the script! | ||
* ************************************************************* */ | ||
|
||
use FluidTYPO3\Vhs\ViewHelpers\AbstractViewHelperTest; | ||
|
||
/** | ||
* @protection off | ||
* @author Benjamin Beck <[email protected]> | ||
* @package Vhs | ||
*/ | ||
class IsDevelopmentViewHelperTest extends AbstractViewHelperTest { | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function testIsDevelopmentContext() { | ||
$instance = $this->createInstance(); | ||
$result = $this->callInaccessibleMethod($instance, 'isDevelopmentContext'); | ||
$this->assertThat($result, new \PHPUnit_Framework_Constraint_IsType(\PHPUnit_Framework_Constraint_IsType::TYPE_BOOL)); | ||
} | ||
|
||
/** | ||
* @test | ||
* @dataProvider getRenderTestValues | ||
* @param boolean $verdict | ||
* @param boolean $expected | ||
*/ | ||
public function testRender($verdict, $expected) { | ||
$instance = $this->getMock(substr(get_class($this), 0, -4), array('isDevelopmentContext')); | ||
$instance->expects($this->once())->method('isDevelopmentContext')->will($this->returnValue($verdict)); | ||
$arguments = array('then' => TRUE, 'else' => FALSE); | ||
$instance->setArguments($arguments); | ||
$result = $instance->render(); | ||
$this->assertEquals($expected, $result); | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function getRenderTestValues() { | ||
return array( | ||
array(FALSE, FALSE), | ||
array(TRUE, TRUE), | ||
); | ||
} | ||
|
||
} |
65 changes: 65 additions & 0 deletions
65
Tests/Unit/ViewHelpers/Condition/Context/IsProductionViewHelperTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?php | ||
namespace FluidTYPO3\Vhs\ViewHelpers\Condition\Context; | ||
|
||
/*************************************************************** | ||
* Copyright notice | ||
* (c) 2014 Benjamin Beck <[email protected]> | ||
* All rights reserved | ||
* This script is part of the TYPO3 project. The TYPO3 project is | ||
* free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 2 of the License, or | ||
* (at your option) any later version. | ||
* The GNU General Public License can be found at | ||
* http://www.gnu.org/copyleft/gpl.html. | ||
* This script is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* This copyright notice MUST APPEAR in all copies of the script! | ||
* ************************************************************* */ | ||
|
||
use FluidTYPO3\Vhs\ViewHelpers\AbstractViewHelperTest; | ||
|
||
/** | ||
* @protection off | ||
* @author Benjamin Beck <[email protected]> | ||
* @package Vhs | ||
*/ | ||
class IsProductionViewHelperTest extends AbstractViewHelperTest { | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function testIsProductionContext() { | ||
$instance = $this->createInstance(); | ||
$result = $this->callInaccessibleMethod($instance, 'isProductionContext'); | ||
$this->assertThat($result, new \PHPUnit_Framework_Constraint_IsType(\PHPUnit_Framework_Constraint_IsType::TYPE_BOOL)); | ||
} | ||
|
||
/** | ||
* @test | ||
* @dataProvider getRenderTestValues | ||
* @param boolean $verdict | ||
* @param boolean $expected | ||
*/ | ||
public function testRender($verdict, $expected) { | ||
$instance = $this->getMock(substr(get_class($this), 0, -4), array('isProductionContext')); | ||
$instance->expects($this->once())->method('isProductionContext')->will($this->returnValue($verdict)); | ||
$arguments = array('then' => TRUE, 'else' => FALSE); | ||
$instance->setArguments($arguments); | ||
$result = $instance->render(); | ||
$this->assertEquals($expected, $result); | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function getRenderTestValues() { | ||
return array( | ||
array(FALSE, FALSE), | ||
array(TRUE, TRUE), | ||
); | ||
} | ||
|
||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing line break here between file header and imports; here and in following classes. Note to self: needs a php code sniffer sniff!