+2010-12-01 Sebastian Kurfuerst <sebastian@typo3.org>
+
+ * Updated Extbase and Fluid to 1.3.0beta2. See their ChangeLogs for details.
+
2010-12-01 Stanislas Rolland <typo3@sjbr.ca>
* Fixed bug #16058: htmlArea RTE: Overlay to choose a color exceeds the viewport if many colors are defined
ChangeLog for Extbase
=====================
+Changes for 1.3.0 Beta 2:
+==========================
+included in TYPO3 4.5.0 Beta 2.
+
+This release includes a whole bunch of bugfixes and refactorings, the most important ones listed below.
+Because the FlashMessages now use t3lib_FlashMessage, TYPO3 4.5 is MANDATORY!
+
+The main changes are:
+
+* Tx_Extbase_MVC_Controller_FlashMessages now internally uses the
+ t3lib_FlashMessageQueue that has been introduced with TYPO3 4.3.
+ This results in following changes:
+ - flashmessages are now treated globally, not in a per-extension-scope. As soon as you output the messages first, the session will be flushed
+ - a flashmessage is not a simple strings anymore, but consists of
+ message body and (optionally) title & severity.
+ You can specify title and severity like this:
+ $this->flashMessages->add('Your message', 'some title', t3lib_FlashMessage::WARNING);
+ - you can now output flashmessages in backend that were set from other TYPO3 classes
+ - a revised flashmessage ViewHelper allows you to render flashmessages in the style
+ of core flashmessages now (see Fluid changelog)
+ - Resolves #10821
+* Configuration Manager can now deal with recurring FlexForm Sections (#6067)
+* Fixed Tx_Extbase_Domain_Model_FrontendUser (and marked the old API as deprecated)
+* Bugfixes related to Lazy Loading
+
+Full Changes for 1.3.0 Beta 2:
+==============================
+[+BUGFIX] Extbase (Persistence): Persistence_Backend::getIdentifierByObject should work with LazyLoadingProxy
+ getIdentifierByObject should check if object is an instance of Tx_Extbase_Persistence_LazyLoadingProxy and should return the
+ identifier of the real object.
+[+BUGFIX] Extbase (Configuration): slightly tweaked FrontendConfigurationManager (basically replaced explode() by t3lib_div::trimExplode() call)
+[+TASK] Extbase (Tests): Added some unit tests for Backend- and FrontendConfigurationManager. To be continued
+[+BUGFIX] Extbase (DomainObject): added default __toString method to Tx_Extbase_DomainObject_AbstractDomainObject. Thanks to Marco Huber. Resolves #8083
+[+BUGFIX] Extbase (MVC): Fixed UriBuilder for handling LazyLoadingProxy objects as arguments. Resolves #10705
+[+TASK] Extbase (Object): re-added Tx_Extbase_Object_Manager to gain more backwards compatibility. This class is marked deprecated and will be removed in Extbase 1.5
+[+BUGFIX] Extbase (Tests): tweaked ObjectContainer tests. Tests are failing deliberately for now
+ The DI implementation has to be rewritten, as discussed.
+ This relates to: #11160
+[+BUGFIX] Extbase (Domain): fixed (non-breaking) method name for getting usergroup in Tx_Extbase_Domain_Model_FrontendUser. Resolves #11019
+[+TASK] extbase (ConfigurationManager): Made FrontendConfigurationManager parse recurring sections in flexforms right. Thanks to Franz Koch (resolves #6067)
+[+BUGFIX] Extbase (Configuration): Slightly tweaked AbstractConfigurationManager
+[+TASK] Extbase (Tests): Added unit tests for AbstractConfigurationManager
+ Note: the ConfigurationManager now always overrides switchableControllerActions
+ when retrieving configuration for the current plugin. Before that only happened
+ when no extensionName/pluginName was specified.
+ Additionally: It's not possible anymore to specify new controllers in
+ switchableControllerAction configuration. That was the intended behavior.
+[+TASK] Extbase (Tests): Renamed test files from "*_testcase.php" to "*Test.php"
+[+TASK] Extbase (Tests): Moving all Tests in "Unit" directory.
+[+FEATURE] Extbase (MVC): add possibility to output FlashMessageQueue (Resolves #10821)
+[+TASK] Extbase (Persistence): counting query results does not work with limit constraints (resolves #10956) Tx_Extbase_Persistence_Storage_Typo3DbBackend::getObjectCountByQuery() replaces the SELECT part
+ of a query by COUNT(*) before executing a statement.
+ This did not work as expected in some cases, e.g. the LIMIT constraint was ignored by the count query.
+[+TASK] Extbase (Persistence): findOneBy*() methods should return NULL if no item was found (Resolves #10958)
+[+TASK] Extbase (Core): Slightly improved error handling in bootstrap (Resolves #11055)
+[~TASK] Extbase (Utility): Changed Tx_Extbase_Utility_TypoScript:convertPlainArrayToTypoScriptArray to self::convertPlainArrayToTypoScriptArray. Resolves #10538.
+[+BUGFIX] Extbase (MVC): UriBuilder: use current plugin if no pluginName has been specified
+ If multiple plugins are found, that are configured to handle the specified action, Extbase
+ will throw an Exception. Now, this only happens if the *current* plugin does not contain
+ the action.
+
Changes for 1.3.0 Beta 1a:
==========================
included in TYPO3 4.5.0 Beta 1.
$frameworkConfiguration['persistence']['storagePid'] = self::DEFAULT_BACKEND_STORAGE_PID;
}
- if ($extensionName !== NULL) {
- $pluginConfiguration = $this->getPluginConfiguration($extensionName, $pluginName);
- $pluginConfiguration['controllerConfiguration'] = $this->getSwitchableControllerActions($extensionName, $pluginName);
- } else {
+ // only merge $this->configuration and override switchableControllerActions when retrieving configuration of the current plugin
+ if ($extensionName === NULL || ($extensionName === $this->extensionName && $pluginName === $this->pluginName)) {
$pluginConfiguration = $this->getPluginConfiguration($this->extensionName, $this->pluginName);
$pluginConfiguration = t3lib_div::array_merge_recursive_overrule($pluginConfiguration, $this->configuration);
$pluginConfiguration['controllerConfiguration'] = $this->getSwitchableControllerActions($this->extensionName, $this->pluginName);
if (isset($this->configuration['switchableControllerActions'])) {
$this->overrideSwitchableControllerActions($pluginConfiguration, $this->configuration['switchableControllerActions']);
}
+ } else {
+ $pluginConfiguration = $this->getPluginConfiguration($extensionName, $pluginName);
+ $pluginConfiguration['controllerConfiguration'] = $this->getSwitchableControllerActions($extensionName, $pluginName);
}
$frameworkConfiguration = t3lib_div::array_merge_recursive_overrule($frameworkConfiguration, $pluginConfiguration);
protected function overrideSwitchableControllerActions(array &$frameworkConfiguration, array $switchableControllerActions) {
$overriddenSwitchableControllerActions = array();
foreach ($switchableControllerActions as $controllerName => $actions) {
+ if (!isset($frameworkConfiguration['controllerConfiguration'][$controllerName])) {
+ continue;
+ }
$overriddenSwitchableControllerActions[$controllerName] = array('actions' => $actions);
$nonCacheableActions = $frameworkConfiguration['controllerConfiguration'][$controllerName]['nonCacheableActions'];
$overriddenNonCacheableActions = array_intersect($nonCacheableActions, $actions);
}
/**
- * Parses the FlexForm content recursivly and converts it to an array
+ * Parses the FlexForm content and converts it to an array
* The resulting array will be multi-dimensional, as a value "bla.blubb"
* results in two levels, and a value "bla.blubb.bla" results in three levels.
*
if (!is_array($languages[$languagePointer])) {
continue;
}
+
foreach($languages[$languagePointer] as $valueKey => $valueDefinition) {
if (strpos($valueKey, '.') === false) {
- $settings[$valueKey] = $valueDefinition[$valuePointer];
+ $settings[$valueKey] = $this->walkFlexformNode($valueDefinition, $valuePointer);
} else {
$valueKeyParts = explode('.', $valueKey);
$currentNode =& $settings;
foreach ($valueKeyParts as $valueKeyPart) {
$currentNode =& $currentNode[$valueKeyPart];
}
- $currentNode = $valueDefinition[$valuePointer];
+ if (is_array($valueDefinition)) {
+ if (array_key_exists($valuePointer, $valueDefinition)) {
+ $currentNode = $valueDefinition[$valuePointer];
+ } else {
+ $currentNode = $this->walkFlexformNode($valueDefinition, $valuePointer);
+ }
+ } else {
+ $currentNode = $valueDefinition;
+ }
}
}
}
return $settings;
}
+ /**
+ * Parses a flexform node recursively and takes care of sections etc
+ * @param array $nodeArray The flexform node to parse
+ * @param string $valuePointer The valuePointer to use for value retrieval
+ */
+ protected function walkFlexformNode($nodeArray, $valuePointer = 'vDEF') {
+ if (is_array($nodeArray)) {
+ $return = array();
+
+ foreach ($nodeArray as $nodeKey => $nodeValue) {
+ if (in_array($nodeKey, array('el', '_arrayContainer'))) {
+ return $this->walkFlexformNode($nodeValue, $valuePointer);
+ }
+
+ if (substr($nodeKey, 0, 1) === '_') {
+ continue;
+ }
+
+ if (strpos($nodeKey, '.')) {
+ $nodeKeyParts = explode('.', $nodeKey);
+ $currentNode =& $return;
+ for ($i = 0; $i < count($nodeKeyParts) - 1; $i++) {
+ $currentNode =& $currentNode[$nodeKeyParts[$i]];
+ }
+ $newNode = array(next($nodeKeyParts) => $nodeValue);
+ $currentNode = $this->walkFlexformNode($newNode, $valuePointer);
+ } else if (is_array($nodeValue)) {
+ if (array_key_exists($valuePointer, $nodeValue)) {
+ $return[$nodeKey] = $nodeValue[$valuePointer];
+ } else {
+ $return[$nodeKey] = $this->walkFlexformNode($nodeValue, $valuePointer);
+ }
+ } else {
+ $return[$nodeKey] = $nodeValue;
+ }
+ }
+ return $return;
+ }
+
+ return $nodeArray;
+ }
+
/**
* Merge a configuration into the framework configuration.
*
return $frameworkConfiguration;
}
-
/**
* Overrides the switchable controller actions from the flexform.
*
* @param array $frameworkConfiguration The original framework configuration
* @param array $flexformConfiguration The full flexform configuration
* @return array the modified framework configuration, if needed
- * @todo: Check that the controller has been before inside the switchableControllerActions.
*/
protected function overrideSwitchableControllerActionsFromFlexform(array $frameworkConfiguration, array $flexformConfiguration) {
if (!isset($flexformConfiguration['switchableControllerActions']) || is_array($flexformConfiguration['switchableControllerActions'])) {
return $frameworkConfiguration;
}
- // As "," is the flexform field value delimiter, we need to use ";" as in-field delimiter. That's why we need to replace ; by , first.
+ // As "," is the flexform field value delimiter, we need to use ";" as in-field delimiter. That's why we need to replace ; by , first.
+ // The expected format is: "Controller1->action2;Controller2->action3;Controller2->action1"
$switchableControllerActionPartsFromFlexform = t3lib_div::trimExplode(',', str_replace(';', ',', $flexformConfiguration['switchableControllerActions']), TRUE);
$newSwitchableControllerActionsFromFlexform = array();
foreach ($switchableControllerActionPartsFromFlexform as $switchableControllerActionPartFromFlexform) {
- list($controller, $action) = explode('->', $switchableControllerActionPartFromFlexform);
+ list($controller, $action) = t3lib_div::trimExplode('->', $switchableControllerActionPartFromFlexform);
if (empty($controller) || empty($action)) {
throw new Tx_Extbase_Configuration_Exception_ParseError('Controller or action were empty when overriding switchableControllerActions from flexform.', 1257146403);
}
$newSwitchableControllerActionsFromFlexform[$controller][] = $action;
}
-
- if (count($newSwitchableControllerActionsFromFlexform)) {
+ if (count($newSwitchableControllerActionsFromFlexform) > 0) {
$this->overrideSwitchableControllerActions($frameworkConfiguration, $newSwitchableControllerActionsFromFlexform);
}
return $frameworkConfiguration;
* @api
*/
public function initialize($configuration) {
+ if (!isset($configuration['extensionName']) || strlen($configuration['extensionName']) === 0) {
+ throw new RuntimeException('Invalid configuration: "extensionName" is not set', 1290623020);
+ }
+ if (!isset($configuration['pluginName']) || strlen($configuration['pluginName']) === 0) {
+ throw new RuntimeException('Invalid configuration: "pluginName" is not set', 1290623027);
+ }
$this->initializeClassLoader();
$this->initializeObjectManager();
$this->initializeConfiguration($configuration);
*/
public function configureObjectManager() {
$typoScriptSetup = $this->configurationManager->getConfiguration(Tx_Extbase_Configuration_ConfigurationManagerInterface::CONFIGURATION_TYPE_FULL_TYPOSCRIPT);
- if (isset($typoScriptSetup['config.']['tx_extbase.']['objects.']) && is_array($typoScriptSetup['config.']['tx_extbase.']['objects.'])) {
- $objectConfiguration = $typoScriptSetup['config.']['tx_extbase.']['objects.'];
-
- foreach ($objectConfiguration as $classNameWithDot => $classConfiguration) {
- if (isset($classConfiguration['className'])) {
- $originalClassName = substr($classNameWithDot, 0, -1);
- Tx_Extbase_Object_Container_Container::getContainer()->registerImplementation($originalClassName, $classConfiguration['className']);
- }
+ if (!is_array($typoScriptSetup['config.']['tx_extbase.']['objects.'])) {
+ throw new RuntimeException('Object configuration was not found in "config.tx_extbase.objects". Please make sure, that the TypoScript setup is loaded', 1290623010);
+ }
+ foreach ($typoScriptSetup['config.']['tx_extbase.']['objects.'] as $classNameWithDot => $classConfiguration) {
+ if (isset($classConfiguration['className'])) {
+ $originalClassName = rtrim($classNameWithDot, '.');
+ Tx_Extbase_Object_Container_Container::getContainer()->registerImplementation($originalClassName, $classConfiguration['className']);
}
}
}
*/
protected function resetSingletons() {
$this->persistenceManager->persistAll();
- $this->objectManager->get('Tx_Extbase_MVC_Controller_FlashMessages')->persist();
$this->reflectionService->shutdown();
}
*
* @return Tx_Extbase_Persistence_ObjectStorage An object storage containing the usergroup
* @api
+ * @deprecated since Extbase 1.3.0; will be removed in Extbase 1.5.0 - use Tx_Extbase_Domain_Model_FrontendUser::getUsergroup() instead
*/
public function getUsergroups() {
+ t3lib_div::logDeprecatedFunction();
+ return $this->usergroup;
+ }
+
+ /**
+ * Returns the usergroups. Keep in mind that the property is called "usergroup"
+ * although it can hold several usergroups.
+ *
+ * @return Tx_Extbase_Persistence_ObjectStorage An object storage containing the usergroup
+ * @api
+ */
+ public function getUsergroup() {
return $this->usergroup;
}
* @api
*/
public function getSubgroup() {
- return $this->subgroups;
+ return $this->subgroup;
}
}
return NULL;
}
}
-
+
/**
* Reconstitutes a property. Only for internal use.
*
}
return $properties;
}
-
+
/**
* Returns the property value of the given property name. Only for internal use.
*
*/
public function _memorizeCleanState() {
}
-
+
/**
* Returns TRUE if the properties were modified after reconstitution. However, value objects can be never updated.
*
$this->_isClone = TRUE;
}
+ /**
+ * Returns the class name and the uid of the object as string
+ *
+ * @return string
+ */
+ public function __toString() {
+ return get_class($this) . ':' . (string)$this->uid;
+ }
+
}
?>
\ No newline at end of file
* @api
*/
class Tx_Extbase_MVC_Controller_ActionController extends Tx_Extbase_MVC_Controller_AbstractController {
+
/**
* @var Tx_Extbase_Reflection_Service
*/
$errorFlashMessage = $this->getErrorFlashMessage();
if ($errorFlashMessage !== FALSE) {
- $this->flashMessages->add($errorFlashMessage);
+ $this->flashMessages->add($errorFlashMessage, '', t3lib_FlashMessage::ERROR);
}
if ($this->request->hasArgument('__referrer')) {
}
}
-?>
\ No newline at end of file
+?>
}
/**
- * @param Tx_Extbase_Reflection_Service $reflectionService
+ * @param Tx_Extbase_Reflection_Service $reflectionService
* @return void
*/
public function injectReflectionService(Tx_Extbase_Reflection_Service $reflectionService) {
* Finds an object from the repository by searching for its technical UID.
*
* @param int $uid The object's uid
- * @return mixed Either the object matching the uid or, if none or more than one object was found, FALSE
+ * @return object Either the object matching the uid or, if none or more than one object was found, NULL
*/
protected function findObjectByUid($uid) {
$query = $this->queryFactory->create($this->dataType);
*/
class Tx_Extbase_MVC_Controller_FlashMessages implements t3lib_Singleton {
- /**
- * The array of flash messages
- * @var array<string>
- */
- protected $flashMessages = array();
-
- /**
- * If FALSE, flash message container still needs to be initialized.
- * @var boolean
- */
- protected $initialized = FALSE;
-
- /**
- * The key from which the flash messages should be retrieved.
- * We have to incorporate the PluginKey and the Extension Key in here, to make
- * it working when multiple plugins are on the same page.
- * @var string
- */
- protected $flashMessageStorageKey = NULL;
-
- /**
- * @var Tx_Extbase_Configuration_ConfigurationManager
- */
- protected $configurationManager;
-
- /**
- * @param Tx_Extbase_Configuration_ConfigurationManagerInterface $configurationManager
- * @return void
- */
- public function injectConfigurationManager(Tx_Extbase_Configuration_ConfigurationManagerInterface $configurationManager) {
- $this->configurationManager = $configurationManager;
- }
-
/**
* Add another flash message.
+ * Severity can be specified and must be one of
+ * t3lib_FlashMessage::NOTICE,
+ * t3lib_FlashMessage::INFO,
+ * t3lib_FlashMessage::OK,
+ * t3lib_FlashMessage::WARNING,
+ * t3lib_FlashMessage::ERROR
*
* @param string $message
+ * @param string $title optional message title
+ * @param integer $severity optional severity code. One of the t3lib_FlashMessage constants
* @return void
* @api
*/
- public function add($message) {
+ public function add($message, $title = '', $severity = t3lib_FlashMessage::OK) {
if (!is_string($message)) {
throw new InvalidArgumentException('The flash message must be string, ' . gettype($message) . ' given.', 1243258395);
}
- $this->initialize();
- $this->flashMessages[] = $message;
+ $flashMessage = t3lib_div::makeInstance(
+ 't3lib_FlashMessage',
+ $message,
+ $title,
+ $severity,
+ TRUE
+ );
+ t3lib_FlashMessageQueue::addMessage($flashMessage);
}
/**
* Get all flash messages currently available.
*
* @return array<string> An array of flash messages
- * @api
+ * @deprecated since Extbase 1.3.0; will be removed in Extbase 1.5.0. Use Use getAllMessages() instead
*/
public function getAll() {
- $this->initialize();
- return $this->flashMessages;
+ t3lib_div::logDeprecatedFunction();
+ $flashMessages = t3lib_FlashMessageQueue::getAllMessages();
+ $messages = array();
+ foreach ($flashMessages as $flashMessage) {
+ $messages[] = $flashMessage->getMessage();
+ }
+ return $messages;
+ }
+
+ /**
+ * Get all flash messages currently available.
+ *
+ * @return array<t3lib_FlashMessage> An array of flash messages
+ * @api
+ * @see t3lib_FlashMessage
+ */
+ public function getAllMessages() {
+ return t3lib_FlashMessageQueue::getAllMessages();
}
/**
* @api
*/
public function flush() {
- $this->initialize();
- $this->flashMessages = array();
+ t3lib_FlashMessageQueue::getAllMessagesAndFlush();
}
/**
* Get all flash messages currently available and delete them afterwards.
*
* @return array<string>
- * @api
+ * @deprecated since Extbase 1.3.0; will be removed in Extbase 1.5.0. Use getAllMessagesAndFlush() instead
*/
public function getAllAndFlush() {
- $this->initialize();
- $flashMessages = $this->flashMessages;
- $this->flashMessages = array();
- return $flashMessages;
- }
-
- /**
- * Initialize the flash message
- */
- protected function initialize() {
- if ($this->initialized) return;
-
- $frameworkConfiguration = $this->configurationManager->getConfiguration(Tx_Extbase_Configuration_ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK);
- $this->flashMessageStorageKey = 'Tx_Extbase_MVC_Controller_FlashMessages_messages_' . $frameworkConfiguration['extensionName'];
-
- $flashMessages = $this->loadFlashMessagesFromSession();
- if (is_array($flashMessages)) {
- $this->flashMessages = $flashMessages;
+ t3lib_div::logDeprecatedFunction();
+ $flashMessages = t3lib_FlashMessageQueue::getAllMessagesAndFlush();
+ $messages = array();
+ foreach ($flashMessages as $flashMessage) {
+ $messages[] = $flashMessage->getMessage();
}
-
- $this->initialized = TRUE;
+ return $messages;
}
/**
- * Loads the flash messages from the current user session.
- */
- protected function loadFlashMessagesFromSession() {
- if (TYPO3_MODE === 'FE') {
- $flashMessages = $GLOBALS['TSFE']->fe_user->getKey('ses', $this->flashMessageStorageKey);
- } else {
- $flashMessages = $GLOBALS['BE_USER']->uc[$this->flashMessageStorageKey];
- $GLOBALS['BE_USER']->writeUC();
- }
- return $flashMessages;
- }
-
- /**
- * Reset the flash messages. Needs to be called at the beginning of a new rendering,
- * to account when multiple plugins appear on the same page.
+ * Get all flash messages currently available. And removes them from the session.
+ *
+ * @return array<t3lib_FlashMessage> An array of flash messages
+ * @see t3lib_FlashMessage
+ * @api
*/
- public function reset() {
- $this->flashMessages = array();
- $this->initialized = FALSE;
- $this->flashMessageStorageKey = NULL;
+ public function getAllMessagesAndFlush() {
+ return t3lib_FlashMessageQueue::getAllMessagesAndFlush();
}
- /**
- * Persist the flash messages in the session.
- */
- public function persist() {
- if (!$this->initialized) {
- return;
- }
- if (TYPO3_MODE === 'FE') {
- $GLOBALS['TSFE']->fe_user->setKey(
- 'ses',
- $this->flashMessageStorageKey,
- $this->flashMessages
- );
- $GLOBALS['TSFE']->fe_user->storeSessionData();
- } else {
- $GLOBALS['BE_USER']->uc[$this->flashMessageStorageKey] = $this->flashMessages;
- $GLOBALS['BE_USER']->writeUc();
- }
- }
}
?>
\ No newline at end of file
*/
public function handleRequest() {
$request = $this->requestBuilder->build();
+
+ // Request hash service
+ $requestHashService = $this->objectManager->get('Tx_Extbase_Security_Channel_RequestHashService'); // singleton
+ $requestHashService->verifyRequest($request);
+
$response = $this->objectManager->create('Tx_Extbase_MVC_Web_Response');
$this->dispatcher->dispatch($request, $response);
*/
protected function convertDomainObjectsToIdentityArrays(array $arguments) {
foreach ($arguments as $argumentKey => $argumentValue) {
+ // if we have a LazyLoadingProxy here, make sure to get the real instance for further processing
+ if ($argumentValue instanceof Tx_Extbase_Persistence_LazyLoadingProxy) {
+ $argumentValue = $argumentValue->_loadRealInstance();
+ // also update the value in the arguments array, because the lazyLoaded object could be
+ // hidden and thus the $argumentValue would be NULL.
+ $arguments[$argumentKey] = $argumentValue;
+ }
if ($argumentValue instanceof Tx_Extbase_DomainObject_AbstractDomainObject) {
if ($argumentValue->getUid() !== NULL) {
$arguments[$argumentKey] = $argumentValue->getUid();
--- /dev/null
+<?php\r
+/***************************************************************\r
+* Copyright notice\r
+*\r
+* (c) 2009 Jochen Rau <jochen.rau@typoplanet.de>\r
+* All rights reserved\r
+*\r
+* This class is a backport of the corresponding class of FLOW3.\r
+* All credits go to the v5 team.\r
+*\r
+* This script is part of the TYPO3 project. The TYPO3 project is\r
+* free software; you can redistribute it and/or modify\r
+* it under the terms of the GNU General Public License as published by\r
+* the Free Software Foundation; either version 2 of the License, or\r
+* (at your option) any later version.\r
+*\r
+* The GNU General Public License can be found at\r
+* http://www.gnu.org/copyleft/gpl.html.\r
+*\r
+* This script is distributed in the hope that it will be useful,\r
+* but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+* GNU General Public License for more details.\r
+*\r
+* This copyright notice MUST APPEAR in all copies of the script!\r
+***************************************************************/\r
+\r
+/**\r
+ * Implementation of the default Extbase Object Manager\r
+ *\r
+ * @package Extbase\r
+ * @subpackage Object\r
+ * @deprecated since Extbase 1.3.0; will be removed in Extbase 1.5.0\r
+ * @see Tx_Extbase_Object_ObjectManagerInterface, Tx_Extbase_Object_ObjectManager\r
+ */\r
+class Tx_Extbase_Object_Manager extends Tx_Extbase_Object_ObjectManager {\r
+\r
+ /**\r
+ * Returns a fresh or existing instance of the object specified by $objectName.\r
+ *\r
+ * Important:\r
+ *\r
+ * If possible, instances of Prototype objects should always be created with the\r
+ * Object Factory's create() method and Singleton objects should rather be\r
+ * injected by some type of Dependency Injection.\r
+ *\r
+ * @param string $objectName The name of the object to return an instance of\r
+ * @return object The object instance\r
+ * @deprecated since Extbase 1.3.0; will be removed in Extbase 1.5.0. Please use Tx_Extbase_Object_ObjectManager instead\r
+ */\r
+ public function getObject($objectName) {\r
+ t3lib_div::logDeprecatedFunction();\r
+ $arguments = array_slice(func_get_args(), 1);\r
+ if (in_array('t3lib_Singleton', class_implements($objectName))) {\r
+ $object = $this->get($objectName, $arguments);\r
+ } else {\r
+ $object = $this->create($objectName, $arguments);\r
+ }\r
+ return $object;\r
+ }\r
+\r
+}\r
+\r
+?>
\ No newline at end of file
* @return string The identifier for the object if it is known, or NULL
*/
public function getIdentifierByObject($object) {
+ if ($object instanceof Tx_Extbase_Persistence_LazyLoadingProxy) {
+ $object = $object->_loadRealInstance();
+ if (!is_object($object)) {
+ return NULL;
+ }
+ }
if ($this->identityMap->hasObject($object)) {
return $this->identityMap->getIdentifierByObject($object);
} else {
} elseif (strpos($propertyMetaData['type'], '_') !== FALSE) {
if (is_object($result) && $result instanceof Tx_Extbase_Persistence_QueryResultInterface) {
$propertyValue = $result->getFirst();
- if ($propertyValue === FALSE) {
- $propertyValue = NULL;
- }
} else {
$propertyValue = $result;
}
if (is_array($this->queryResult)) {\r
$queryResult = $this->queryResult;\r
reset($queryResult);\r
- return current($queryResult);\r
} else {\r
$query = clone $this->query;\r
$query->setLimit(1);\r
$queryResult = $this->dataMapper->map($this->query->getType(), $this->persistenceManager->getObjectDataByQuery($this->query));\r
- return current($queryResult);\r
}\r
+ $firstResult = current($queryResult);\r
+ if ($firstResult === FALSE) {\r
+ $firstResult = NULL;\r
+ }\r
+ return $firstResult;\r
}\r
\r
/**\r
$object = $query->matching($query->equals('uid', $uid))
->execute()
->getFirst();
- if ($object !== FALSE) {
+ if ($object !== NULL) {
$this->identityMap->registerObject($object, $uid);
}
}
* Returns the number of tuples matching the query.
*
* @param Tx_Extbase_Persistence_QOM_QueryObjectModelInterface $query
- * @return int The number of matching tuples
+ * @return integer The number of matching tuples
*/
public function getObjectCountByQuery(Tx_Extbase_Persistence_QueryInterface $query) {
$constraint = $query->getConstraint();
- if($constraint instanceof Tx_Extbase_Persistence_QOM_StatementInterface) throw new Tx_Extbase_Persistence_Storage_Exception_BadConstraint('Could not execute count on queries with a constraint of type Tx_Extbase_Persistence_QOM_StatementInterface', 1256661045);
+ if($constraint instanceof Tx_Extbase_Persistence_QOM_StatementInterface) {
+ throw new Tx_Extbase_Persistence_Storage_Exception_BadConstraint('Could not execute count on queries with a constraint of type Tx_Extbase_Persistence_QOM_StatementInterface', 1256661045);
+ }
$parameters = array();
$statementParts = $this->parseQuery($query, $parameters);
- $statementParts['fields'] = array('COUNT(*)');
- $statement = $this->buildQuery($statementParts, $parameters);
- $this->replacePlaceholders($statement, $parameters);
- // debug($statement,-2);
- $result = $this->databaseHandle->sql_query($statement);
- $this->checkSqlErrors($statement);
- $rows = $this->getRowsFromResult($query->getSource(), $result);
- return current(current($rows));
+ // if limit is set, we need to count the rows "manually" as COUNT(*) ignores LIMIT constraints
+ if (!empty($statementParts['limit'])) {
+ $statement = $this->buildQuery($statementParts, $parameters);
+ $this->replacePlaceholders($statement, $parameters);
+ $result = $this->databaseHandle->sql_query($statement);
+ $this->checkSqlErrors($statement);
+ return $this->databaseHandle->sql_num_rows($result);
+ } else {
+ $statementParts['fields'] = array('COUNT(*)');
+ $statement = $this->buildQuery($statementParts, $parameters);
+ $this->replacePlaceholders($statement, $parameters);
+ $result = $this->databaseHandle->sql_query($statement);
+ $this->checkSqlErrors($statement);
+ $rows = $this->getRowsFromResult($query->getSource(), $result);
+ return current(current($rows));
+ }
}
/**
protected $queryFactory;
/**
- * @param Tx_Extbase_Validation_ValidatorResolver $validatorResolver
+ * @param Tx_Extbase_Validation_ValidatorResolver $validatorResolver
* @return void
*/
public function injectValidatorResolver(Tx_Extbase_Validation_ValidatorResolver $validatorResolver) {
*
* @param string $dataType the data type to fetch
* @param int $uid The object's uid
- * @return mixed Either the object matching the uid or, if none or more than one object was found, FALSE
+ * @return object Either the object matching the uid or, if none or more than one object was found, NULL
*/
// TODO This is duplicated code; see Argument class
protected function findObjectByUid($dataType, $uid) {
* Iterates through the global TypoScript configuration and returns the name of the plugin
* that matches specified extensionName, controllerName and actionName.
* If no matching plugin was found, NULL is returned.
- * If more than one plugin matches, an Exception will be thrown
+ * If more than one plugin matches and the current plugin is not configured to handle the action,
+ * an Exception will be thrown
*
* @param string $extensionName name of the target extension (UpperCamelCase)
* @param string $controllerName name of the target controller (UpperCamelCase)
* @return string name of the target plugin (UpperCamelCase) or NULL if no matching plugin configuration was found
*/
static public function getPluginNameByAction($extensionName, $controllerName, $actionName) {
- // TODO use ConfigurationManager to retrieve controllerConfiguration
+ $objectManager = t3lib_div::makeInstance('Tx_Extbase_Object_ObjectManager');
+ $configurationManager = $objectManager->get('Tx_Extbase_Configuration_ConfigurationManagerInterface');
+ $frameworkConfiguration = $configurationManager->getConfiguration(Tx_Extbase_Configuration_ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK);
+ // check, whether the current plugin is configured to handle the action
+ if ($extensionName === $frameworkConfiguration['extensionName']) {
+ if (isset($frameworkConfiguration['controllerConfiguration'][$controllerName])
+ && in_array($actionName, $frameworkConfiguration['controllerConfiguration'][$controllerName]['actions'])) {
+ return $frameworkConfiguration['pluginName'];
+ }
+ }
if (!is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['extensions'][$extensionName]['plugins'])) {
return NULL;
}
$typoScriptArray[$key] = $value['_typoScriptNodeValue'];
unset($value['_typoScriptNodeValue']);
}
- $typoScriptArray[$key.'.'] = Tx_Extbase_Utility_TypoScript::convertPlainArrayToTypoScriptArray($value);
+ $typoScriptArray[$key.'.'] = self::convertPlainArrayToTypoScriptArray($value);
} else {
$typoScriptArray[$key] = $value;
}
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
-require_once(t3lib_extMgm::extPath('phpunit') . 'class.tx_phpunit_testcase.php');
+
/**
* Base testcase for the Extbase extension.
+ * @deprecated use Tx_Extbase_Tests_Unit_BaseTestCase instead
*/
-abstract class Tx_Extbase_BaseTestCase extends tx_phpunit_testcase {
-
- /**
- * @var Tx_Extbase_Object_ObjectManagerInterface The object manager
- */
- protected $objectManager;
-
- /**
- * Constructs a test case with the given name.
- *
- * @param string $name
- * @param array $data
- * @param string $dataName
- */
- public function __construct($name = NULL, array $data = array(), $dataName = '') {
- parent::__construct($name, $data, $dataName);
- if (!class_exists('Tx_Extbase_Utility_ClassLoader')) {
- require(t3lib_extmgm::extPath('extbase') . 'Classes/Utility/ClassLoader.php');
- }
- spl_autoload_register(array('Tx_Extbase_Utility_ClassLoader', 'loadClass'));
- }
-
- /**
- * Injects an untainted clone of the object manager and all its referencing
- * objects for every test.
- *
- * @return void
- */
- public function runBare() {
- $objectManager = t3lib_div::makeInstance('Tx_Extbase_Object_ObjectManager');
- $this->objectManager = clone $objectManager;
- parent::runBare();
- }
-
- /**
- * Returns a mock object which allows for calling protected methods and access
- * of protected properties.
- *
- * @param string $className Full qualified name of the original class
- * @param array $methods
- * @param array $arguments
- * @param string $mockClassName
- * @param boolean $callOriginalConstructor
- * @param boolean $callOriginalClone
- * @param boolean $callAutoload
- * @return object
- * @author Robert Lemke <robert@typo3.org>
- * @api
- */
- protected function getAccessibleMock($originalClassName, $methods = array(), array $arguments = array(), $mockClassName = '', $callOriginalConstructor = TRUE, $callOriginalClone = TRUE, $callAutoload = TRUE) {
- return $this->getMock($this->buildAccessibleProxy($originalClassName), $methods, $arguments, $mockClassName, $callOriginalConstructor, $callOriginalClone, $callAutoload);
- }
-
-
- /**
- * Creates a proxy class of the specified class which allows
- * for calling even protected methods and access of protected properties.
- *
- * @param protected $className Full qualified name of the original class
- * @return string Full qualified name of the built class
- */
- protected function buildAccessibleProxy($className) {
- $accessibleClassName = uniqid('AccessibleTestProxy');
- $class = new ReflectionClass($className);
- $abstractModifier = $class->isAbstract() ? 'abstract ' : '';
- eval('
- ' . $abstractModifier . 'class ' . $accessibleClassName . ' extends ' . $className . ' {
- public function _call($methodName) {
- $args = func_get_args();
- return call_user_func_array(array($this, $methodName), array_slice($args, 1));
- }
- public function _callRef($methodName, &$arg1 = NULL, &$arg2 = NULL, &$arg3 = NULL, &$arg4 = NULL, &$arg5= NULL, &$arg6 = NULL, &$arg7 = NULL, &$arg8 = NULL, &$arg9 = NULL) {
- switch (func_num_args()) {
- case 0 : return $this->$methodName();
- case 1 : return $this->$methodName($arg1);
- case 2 : return $this->$methodName($arg1, $arg2);
- case 3 : return $this->$methodName($arg1, $arg2, $arg3);
- case 4 : return $this->$methodName($arg1, $arg2, $arg3, $arg4);
- case 5 : return $this->$methodName($arg1, $arg2, $arg3, $arg4, $arg5);
- case 6 : return $this->$methodName($arg1, $arg2, $arg3, $arg4, $arg5, $arg6);
- case 7 : return $this->$methodName($arg1, $arg2, $arg3, $arg4, $arg5, $arg6, $arg7);
- case 8 : return $this->$methodName($arg1, $arg2, $arg3, $arg4, $arg5, $arg6, $arg7, $arg8);
- case 9 : return $this->$methodName($arg1, $arg2, $arg3, $arg4, $arg5, $arg6, $arg7, $arg8, $arg9);
- }
- }
- public function _set($propertyName, $value) {
- $this->$propertyName = $value;
- }
- public function _setRef($propertyName, &$value) {
- $this->$propertyName = $value;
- }
- public function _get($propertyName) {
- return $this->$propertyName;
- }
- }
- ');
- return $accessibleClassName;
- }
+abstract class Tx_Extbase_BaseTestCase extends Tx_Extbase_Tests_Unit_BaseTestCase {
}
?>
\ No newline at end of file
+++ /dev/null
-<?php
-/***************************************************************
-* Copyright notice
-*
-* (c) 2009 Jochen Rau <jochen.rau@typoplanet.de>
-* All rights reserved
-*
-* This class is a backport of the corresponding class of FLOW3.
-* All credits go to the v5 team.
-*
-* 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!
-***************************************************************/
-
-class Tx_Extbase_Configuration_BackendConfigurationManager_testcase extends Tx_Extbase_BaseTestCase {
-
- /**
- * @var array
- */
- protected $getBackup;
-
- /**
- * @var array
- */
- protected $postBackup;
-
- /**
- * @var t3lib_DB
- */
- protected $typo3DbBackup;
-
- /**
- * @var Tx_Extbase_Configuration_BackendConfigurationManager
- */
- protected $backendConfigurationManager;
-
- /**
- * Sets up this testcase
- */
- public function setUp() {
- $this->getBackup = t3lib_div::_GET();
- $this->postBackup = t3lib_div::_POST();
-
- $this->typo3DbBackup = $GLOBALS['TYPO3_DB'];
- $GLOBALS['TYPO3_DB'] = $this->getMock('t3lib_DB', array());
-
- $this->backendConfigurationManager = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_Configuration_BackendConfigurationManager'), array('dummy'));
- }
-
- /**
- * Tears down this testcase
- */
- public function tearDown() {
- t3lib_div::_GETset($this->getBackup);
- $_POST = $this->postBackup;
- }
-
- /**
- * @test
- */
- public function getTypoScriptSetupCanBeTested() {
- $this->markTestIncomplete('This method can\'t be tested with the current TYPO3 version, because we can\'t mock objects returned from t3lib_div::makeInstance().');
- }
-
- /**
- * @test
- */
- public function getCurrentPageIdReturnsPageIdFromGet() {
- t3lib_div::_GETset(array('id' => 123));
-
- $expectedResult = 123;
- $actualResult = $this->backendConfigurationManager->_call('getCurrentPageId');
-
- $this->assertEquals($expectedResult, $actualResult);
- }
-
- /**
- * @test
- */
- public function getCurrentPageIdReturnsPageIdFromPost() {
- t3lib_div::_GETset(array('id' => 123));
- $_POST['id'] = 321;
-
- $expectedResult = 321;
- $actualResult = $this->backendConfigurationManager->_call('getCurrentPageId');
-
- $this->assertEquals($expectedResult, $actualResult);
- }
-
- /**
- * @test
- */
- public function getCurrentPageIdReturnsPidFromFirstRootTemplateIfIdIsNotSet() {
- $GLOBALS['TYPO3_DB']->expects($this->once())
- ->method('exec_SELECTgetRows')
- ->with('pid', 'sys_template', 'deleted=0 AND hidden=0 AND root=1', '', '', '1')
- ->will(
- $this->returnValue(
- array(
- array('pid' => 123)
- )
- )
- );
-
- $expectedResult = 123;
- $actualResult = $this->backendConfigurationManager->_call('getCurrentPageId');
-
- $this->assertEquals($expectedResult, $actualResult);
- }
-
- /**
- * @test
- */
- public function getCurrentPageIdReturnsUidFromFirstRootPageIfIdIsNotSetAndNoRootTemplateWasFound() {
- $GLOBALS['TYPO3_DB']->expects($this->at(0))
- ->method('exec_SELECTgetRows')
- ->with('pid', 'sys_template', 'deleted=0 AND hidden=0 AND root=1', '', '', '1')
- ->will($this->returnValue(array()));
-
- $GLOBALS['TYPO3_DB']->expects($this->at(1))
- ->method('exec_SELECTgetRows')
- ->with('uid', 'pages', 'deleted=0 AND hidden=0 AND is_siteroot=1', '', '', '1')
- ->will(
- $this->returnValue(
- array(
- array('uid' => 321)
- )
- )
- );
-
- $expectedResult = 321;
- $actualResult = $this->backendConfigurationManager->_call('getCurrentPageId');
-
- $this->assertEquals($expectedResult, $actualResult);
- }
-
- /**
- * @test
- */
- public function getCurrentPageIdReturnsDefaultStoragePidIfIdIsNotSetNoRootTemplateAndRootPageWasFound() {
- $GLOBALS['TYPO3_DB']->expects($this->at(0))
- ->method('exec_SELECTgetRows')
- ->with('pid', 'sys_template', 'deleted=0 AND hidden=0 AND root=1', '', '', '1')
- ->will($this->returnValue(array()));
-
- $GLOBALS['TYPO3_DB']->expects($this->at(1))
- ->method('exec_SELECTgetRows')
- ->with('uid', 'pages', 'deleted=0 AND hidden=0 AND is_siteroot=1', '', '', '1')
- ->will($this->returnValue(array()));
-
- $expectedResult = 0;
- $actualResult = $this->backendConfigurationManager->_call('getCurrentPageId');
-
- $this->assertEquals($expectedResult, $actualResult);
- }
-}
-?>
\ No newline at end of file
+++ /dev/null
-<?php
-/***************************************************************
-* Copyright notice
-*
-* (c) 2009 Jochen Rau <jochen.rau@typoplanet.de>
-* All rights reserved
-*
-* This class is a backport of the corresponding class of FLOW3.
-* All credits go to the v5 team.
-*
-* 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!
-***************************************************************/
-
-class Tx_Extbase_Configuration_FrontendConfigurationManager_testcase extends Tx_Extbase_BaseTestCase {
-
- /**
- * @var tslib_fe
- */
- protected $tsfeBackup;
-
- /**
- * @var Tx_Extbase_Configuration_FrontendConfigurationManager
- */
- protected $frontendConfigurationManager;
- /**
- * Sets up this testcase
- */
- public function setUp() {
- $this->tsfeBackup = $GLOBALS['TSFE'];
- $this->frontendConfigurationManager = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_Configuration_FrontendConfigurationManager'), array('dummy'));
- }
-
- /**
- * Tears down this testcase
- */
- public function tearDown() {
- $GLOBALS['TSFE']->tmpl->setup;
- }
-
- /**
- * @test
- */
- public function getTypoScriptSetupReturnsSetupFromTSFE() {
- $GLOBALS['TSFE']->tmpl->setup = array('foo' => 'bar');
- $this->assertEquals(array('foo' => 'bar'), $this->frontendConfigurationManager->_callRef('getTypoScriptSetup'));
- }
-
- /**
- * @test
- */
- public function overrideSwitchableControllerActionsFromFlexformMergesNonCacheableActions() {
- $frameworkConfiguration = array(
- 'userFunc' => 'tx_extbase_dispatcher->dispatch',
- 'pluginName' => 'Pi1',
- 'extensionName' => 'SomeExtension',
- 'switchableControllerActions' => array(
- 'Controller1' => array(
- 'controller' => 'Controller1',
- 'actions' => 'action1 , action2'
- ),
- 'Controller2' => array(
- 'controller' => 'Controller2',
- 'actions' => 'action2 , action1,action3',
- 'nonCacheableActions' => 'action2, action3'
- )
- )
- );
- $flexformConfiguration = array(
- 'switchableControllerActions' => 'Controller1->action2;Controller2->action3;Controller2->action1'
- );
- $expectedResult = array(
- 'userFunc' => 'tx_extbase_dispatcher->dispatch',
- 'pluginName' => 'Pi1',
- 'extensionName' => 'SomeExtension',
- 'switchableControllerActions' => array(
- 'Controller1' => array(
- 'controller' => 'Controller1',
- 'actions' => 'action2'
- ),
- 'Controller2' => array(
- 'controller' => 'Controller2',
- 'actions' => 'action3,action1',
- 'nonCacheableActions' => 'action3'
- )
- )
- );
- $actualResult = $this->frontendConfigurationManager->_callRef('overrideSwitchableControllerActionsFromFlexform', $frameworkConfiguration, $flexformConfiguration);
- $this->assertEquals($expectedResult, $actualResult);
- }
-}
-?>
\ No newline at end of file
+++ /dev/null
-<?php
-/***************************************************************
-* Copyright notice
-*
-* (c) 2009 Sebastian Kurfürst <sebastian@typo3.org>
-* 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!
-***************************************************************/
-
-class Tx_Extbase_DomainObject_AbstractEntity_testcase extends Tx_Extbase_BaseTestCase {
-
- /**
- * @test
- */
- public function objectIsNotDirtyAfterCallingMemorizeCleanStateWithSimpleProperties() {
- $domainObjectName = uniqid('DomainObject_');
- eval('class ' . $domainObjectName . ' extends Tx_Extbase_DomainObject_AbstractEntity {
- public $foo;
- public $bar;
- }');
- $domainObject = new $domainObjectName();
- $domainObject->foo = 'Test';
- $domainObject->bar = 'It is raining outside';
- $domainObject->_memorizeCleanState();
-
- $this->assertFalse($domainObject->_isDirty());
- }
-
- /**
- * @test
- */
- public function objectIsDirtyAfterCallingMemorizeCleanStateWithSimplePropertiesAndModifyingThePropertiesAfterwards() {
- $domainObjectName = uniqid('DomainObject_');
- eval('class ' . $domainObjectName . ' extends Tx_Extbase_DomainObject_AbstractEntity {
- public $foo;
- public $bar;
- }');
- $domainObject = new $domainObjectName();
- $domainObject->foo = 'Test';
- $domainObject->bar = 'It is raining outside';
-
- $domainObject->_memorizeCleanState();
- $domainObject->bar = 'Now it is sunny.';
-
- $this->assertTrue($domainObject->_isDirty());
- }
-
- /**
- * @test
- */
- public function objectIsNotDirtyAfterCallingMemorizeCleanStateWithObjectProperties() {
- $domainObjectName = uniqid('DomainObject_');
- eval('class ' . $domainObjectName . ' extends Tx_Extbase_DomainObject_AbstractEntity {
- public $foo;
- public $bar;
- }');
- $domainObject = new $domainObjectName();
- $domainObject->foo = new DateTime();
- $domainObject->bar = 'It is raining outside';
- $domainObject->_memorizeCleanState();
-
- $this->assertFalse($domainObject->_isDirty());
- }
-
- /**
- * @test
- */
- public function objectIsNotDirtyAfterCallingMemorizeCleanStateWithOtherDomainObjectsAsProperties() {
- $domainObjectName = uniqid('DomainObject_');
- eval('class ' . $domainObjectName . ' extends Tx_Extbase_DomainObject_AbstractEntity {
- public $foo;
- public $bar;
- }');
-
- $secondDomainObjectName = uniqid('DomainObject_');
- eval('class ' . $secondDomainObjectName . ' extends Tx_Extbase_DomainObject_AbstractEntity {
- public $foo;
- public $bar;
- }');
- $secondDomainObject = new $secondDomainObjectName;
- $secondDomainObject->_memorizeCleanState();
-
-
- $domainObject = new $domainObjectName();
- $domainObject->foo = $secondDomainObject;
- $domainObject->bar = 'It is raining outside';
- $domainObject->_memorizeCleanState();
-
- $this->assertFalse($domainObject->_isDirty());
- }
-}
-?>
\ No newline at end of file
+++ /dev/null
-<?php
-/***************************************************************
-* Copyright notice
-*
-* (c) 2009 Jochen Rau <jochen.rau@typoplanet.de>
-* All rights reserved
-*
-* This class is a backport of the corresponding class of FLOW3.
-* All credits go to the v5 team.
-*
-* 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!
-***************************************************************/
-
-/**
- * An entity
- *
- * @package Extbase
- * @subpackage extbase
- * @version $ID:$
- * @entity
- */
-class Tx_Extbase_Tests_Fixtures_Entity extends Tx_Extbase_DomainObject_AbstractEntity {
-
- /**
- * The entity's name
- *
- * @var string
- */
- protected $name;
-
-
- /**
- * Constructs this entity
- *
- * @param string $name Name of this blog
- * @return void
- */
- public function __construct($name) {
- $this->setName($name);
- }
-
- /**
- * Sets this entity's name
- *
- * @param string $name The entity's name
- * @return void
- */
- public function setName($name) {
- $this->name = $name;
- }
-
- /**
- * Returns the entity's name
- *
- * @return string The entity's name
- */
- public function getName() {
- return $this->name;
- }
-
-}
-?>
\ No newline at end of file
+++ /dev/null
-<?php
-/***************************************************************
-* Copyright notice
-*
-* (c) 2009 Jochen Rau <jochen.rau@typoplanet.de>
-* All rights reserved
-*
-* This class is a backport of the corresponding class of FLOW3.
-* All credits go to the v5 team.
-*
-* 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!
-***************************************************************/
-
-class Tx_Extbase_MVC_Controller_AbstractController_testcase extends Tx_Extbase_BaseTestCase {
-
- /**
- * @test
- */
- public function theExtensionNameIsInitialized() {
- $extensionName = uniqid('Test');
- $controller = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_MVC_Controller_AbstractController'), array('initializeObjects'), array(), 'Tx_' . $extensionName . '_Controller');
- $this->assertSame($extensionName, $controller->_get('extensionName'));
- }
-
- /**
- * @test
- * @expectedException Tx_Extbase_MVC_Exception_UnsupportedRequestType
- */
- public function processRequestWillThrowAnExceptionIfTheGivenRequestIsNotSupported() {
- $mockRequest = $this->getMock('Tx_Extbase_MVC_Web_Request');
- $mockResponse = $this->getMock('Tx_Extbase_MVC_Web_Response');
-
- $controller = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_MVC_Controller_AbstractController'), array('mapRequestArgumentsToControllerArguments'), array(), '', FALSE);
- $controller->_set('supportedRequestTypes', array('Tx_Something_Request'));
- $controller->processRequest($mockRequest, $mockResponse);
- }
-
- /**
- * @test
- */
- public function processRequestSetsTheDispatchedFlagOfTheRequest() {
- $mockRequest = $this->getMock('Tx_Extbase_MVC_Web_Request');
- $mockRequest->expects($this->once())->method('setDispatched')->with(TRUE);
-
- $mockResponse = $this->getMock('Tx_Extbase_MVC_Web_Response');
-
- $controller = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_MVC_Controller_AbstractController'), array('initializeArguments', 'initializeControllerArgumentsBaseValidators', 'mapRequestArgumentsToControllerArguments'), array(), '', FALSE);
- $controller->processRequest($mockRequest, $mockResponse);
- }
-
- /**
- * @test
- * @expectedException Tx_Extbase_MVC_Exception_StopAction
- */
- public function forwardThrowsAStopActionException() {
- $mockRequest = $this->getMock('Tx_Extbase_MVC_Web_Request');
- $mockRequest->expects($this->once())->method('setDispatched')->with(FALSE);
- $mockRequest->expects($this->once())->method('setControllerActionName')->with('foo');
-
- $controller = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_MVC_Controller_AbstractController'), array('dummy'), array(), '', FALSE);
- $controller->_set('request', $mockRequest);
- $controller->_call('forward', 'foo');
- }
-
- /**
- * @test
- * @expectedException Tx_Extbase_MVC_Exception_StopAction
- */
- public function forwardSetsControllerAndArgumentsAtTheRequestObjectIfTheyAreSpecified() {
- $arguments = array('foo' => 'bar');
-
- $mockRequest = $this->getMock('Tx_Extbase_MVC_Web_Request');
- $mockRequest->expects($this->once())->method('setControllerActionName')->with('foo');
- $mockRequest->expects($this->once())->method('setControllerName')->with('Bar');
- $mockRequest->expects($this->once())->method('setControllerExtensionName')->with('Baz');
- $mockRequest->expects($this->once())->method('setArguments')->with($arguments);
-
- $controller = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_MVC_Controller_AbstractController'), array('dummy'), array(), '', FALSE);
- $controller->_set('request', $mockRequest);
- $controller->_call('forward', 'foo', 'Bar', 'Baz', $arguments);
- }
-
- /**
- * @test
- */
- public function redirectRedirectsToTheSpecifiedAction() {
- $arguments = array('foo' => 'bar');
-
- $mockRequest = $this->getMock('Tx_Extbase_MVC_Web_Request');
- $mockResponse = $this->getMock('Tx_Extbase_MVC_Web_Response');
-
- $mockUriBuilder = $this->getMock('Tx_Extbase_MVC_Web_Routing_UriBuilder');
- $mockUriBuilder->expects($this->once())->method('reset')->will($this->returnValue($mockUriBuilder));
- $mockUriBuilder->expects($this->once())->method('setTargetPageUid')->with(123)->will($this->returnValue($mockUriBuilder));
- $mockUriBuilder->expects($this->once())->method('uriFor')->with('theActionName', $arguments, 'TheControllerName', 'TheExtensionName')->will($this->returnValue('the uri'));
-
- $controller = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_MVC_Controller_AbstractController'), array('redirectToURI'), array(), '', FALSE);
- $controller->expects($this->once())->method('redirectToURI')->with('the uri');
- $controller->_set('request', $mockRequest);
- $controller->_set('response', $mockResponse);
- $controller->_set('uriBuilder', $mockUriBuilder);
- $controller->_call('redirect', 'theActionName', 'TheControllerName', 'TheExtensionName', $arguments, 123);
- }
-
- /**
- * @test
- */
- public function theBaseUriIsAddedIfNotAlreadyExists() {
- $mockRequest = $this->getMock('Tx_Extbase_MVC_Web_Request');
- $mockRequest->expects($this->any())->method('getBaseURI')->will($this->returnValue('http://www.example.com/foo/'));
-
- $controller = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_MVC_Controller_AbstractController'), array('dummy'), array(), '', FALSE);
- $controller->_set('request', $mockRequest);
- $actualResult = $controller->_call('addBaseUriIfNecessary', 'bar/baz/boom.html');
- $expectedResult = 'http://www.example.com/foo/bar/baz/boom.html';
-
- $this->assertEquals($expectedResult, $actualResult);
- }
-
- /**
- * @test
- */
- public function theBaseUriIsNotAddedIfAlreadyExists() {
- $mockRequest = $this->getMock('Tx_Extbase_MVC_Web_Request');
- $mockRequest->expects($this->any())->method('getBaseURI')->will($this->returnValue('http://www.example.com/foo/'));
-
- $controller = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_MVC_Controller_AbstractController'), array('dummy'), array(), '', FALSE);
- $controller->_set('request', $mockRequest);
- $actualResult = $controller->_call('addBaseUriIfNecessary', 'http://www.example.com/foo/bar/baz/boom.html');
- $expectedResult = 'http://www.example.com/foo/bar/baz/boom.html';
-
- $this->assertEquals($expectedResult, $actualResult);
- }
-
- /**
- * @test
- * @expectedException Tx_Extbase_MVC_Exception_StopAction
- */
- public function throwStatusSetsTheSpecifiedStatusHeaderAndStopsTheCurrentAction() {
- $mockRequest = $this->getMock('Tx_Extbase_MVC_Web_Request');
- $mockResponse = $this->getMock('Tx_Extbase_MVC_Web_Response');
- $mockResponse->expects($this->once())->method('setStatus')->with(404, 'File Really Not Found');
- $mockResponse->expects($this->once())->method('setContent')->with('<h1>All wrong!</h1><p>Sorry, the file does not exist.</p>');
-
- $controller = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_MVC_Controller_AbstractController'), array('dummy'), array(), '', FALSE);
- $controller->_set('request', $mockRequest);
- $controller->_set('response', $mockResponse);
- $controller->_call('throwStatus', 404, 'File Really Not Found', '<h1>All wrong!</h1><p>Sorry, the file does not exist.</p>');
- }
-
- /**
- * @test
- */
- public function initializeControllerArgumentsBaseValidatorsRegistersValidatorsDeclaredInTheArgumentModels() {
- $mockValidators = array(
- 'foo' => $this->getMock('Tx_Extbase_Validation_Validator_ValidatorInterface'),
- );
-
- $mockValidatorResolver = $this->getMock('Tx_Extbase_Validation_ValidatorResolver', array(), array(), '', FALSE);
- $mockValidatorResolver->expects($this->at(0))->method('getBaseValidatorConjunction')->with('FooType')->will($this->returnValue($mockValidators['foo']));
- $mockValidatorResolver->expects($this->at(1))->method('getBaseValidatorConjunction')->with('BarType')->will($this->returnValue(NULL));
-
- $mockArgumentFoo = $this->getMock('Tx_Extbase_MVC_Controller_Argument', array(), array('foo'), '', FALSE);
- $mockArgumentFoo->expects($this->once())->method('getDataType')->will($this->returnValue('FooType'));
- $mockArgumentFoo->expects($this->once())->method('setValidator')->with($mockValidators['foo']);
-
- $mockArgumentBar = $this->getMock('Tx_Extbase_MVC_Controller_Argument', array(), array('bar'), '', FALSE);
- $mockArgumentBar->expects($this->once())->method('getDataType')->will($this->returnValue('BarType'));
- $mockArgumentBar->expects($this->never())->method('setValidator');
-
- $mockArguments = new Tx_Extbase_MVC_Controller_Arguments();
- $mockArguments->addArgument($mockArgumentFoo);
- $mockArguments->addArgument($mockArgumentBar);
-
- $controller = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_MVC_Controller_AbstractController'), array('dummy'), array(), '', FALSE);
- $controller->_set('arguments', $mockArguments);
- $controller->injectValidatorResolver($mockValidatorResolver);
- $controller->_call('initializeControllerArgumentsBaseValidators');
- }
-
- /**
- * @test
- */
- public function mapRequestArgumentsToControllerArgumentsPreparesInformationAndValidatorsAndMapsAndValidates() {
- $mockValidator = new Tx_Extbase_MVC_Controller_ArgumentsValidator(); // FIXME see original FLOW3 code
-
- $mockArgumentFoo = $this->getMock('Tx_Extbase_MVC_Controller_Argument', array(), array('foo'), '', FALSE);
- $mockArgumentFoo->expects($this->any())->method('getName')->will($this->returnValue('foo'));
- $mockArgumentBar = $this->getMock('Tx_Extbase_MVC_Controller_Argument', array(), array('bar'), '', FALSE);
- $mockArgumentBar->expects($this->any())->method('getName')->will($this->returnValue('bar'));
-
- $mockArguments = new Tx_Extbase_MVC_Controller_Arguments();
- $mockArguments->addArgument($mockArgumentFoo);
- $mockArguments->addArgument($mockArgumentBar);
-
- $mockRequest = $this->getMock('Tx_Extbase_MVC_Web_Request');
- $mockRequest->expects($this->once())->method('getArguments')->will($this->returnValue(array('requestFoo', 'requestBar')));
-
- $mockMappingResults = $this->getMock('Tx_Extbase_Property_MappingResults');
-
- $mockPropertyMapper = $this->getMock('Tx_Extbase_Property_Mapper', array(), array(), '', FALSE);
- $mockPropertyMapper->expects($this->once())->method('mapAndValidate')
- ->with(array('foo', 'bar'), array('requestFoo', 'requestBar'), $mockArguments, array(), $mockValidator)
- ->will($this->returnValue(TRUE));
- $mockPropertyMapper->expects($this->once())->method('getMappingResults')->will($this->returnValue($mockMappingResults));
-
- $controller = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_MVC_Controller_AbstractController'), array('dummy'), array(), '', FALSE);
-
- $controller->_set('arguments', $mockArguments);
- $controller->_set('request', $mockRequest);
- $controller->_set('propertyMapper', $mockPropertyMapper);
- $controller->_set('objectManager', $mockObjectManager);
-
- $controller->_call('mapRequestArgumentsToControllerArguments');
-
- $this->assertSame($mockMappingResults, $controller->_get('argumentsMappingResults'));
- // $this->assertTrue(in_array('Tx_Extbase_Validation_Validator_ObjectValidatorInterface', class_implements($controller->_get('argumentsMappingResults'))));
- }
-
-}
-?>
\ No newline at end of file
+++ /dev/null
-<?php
-/***************************************************************
-* Copyright notice
-*
-* (c) 2009 Jochen Rau <jochen.rau@typoplanet.de>
-* All rights reserved
-*
-* This class is a backport of the corresponding class of FLOW3.
-* All credits go to the v5 team.
-*
-* 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!
-***************************************************************/
-
-class Tx_Extbase_MVC_Controller_ActionController_testcase extends Tx_Extbase_BaseTestCase {
-
- /**
- * @test
- * @author Robert Lemke <robert@typo3.org>
- */
- public function processRequestSticksToSpecifiedSequence() {
- $mockRequest = $this->getMock('Tx_Extbase_MVC_Web_Request', array(), array(), '', FALSE);
- $mockRequest->expects($this->once())->method('setDispatched')->with(TRUE);
-
- $mockResponse = $this->getMock('Tx_Extbase_MVC_Web_Response', array(), array(), '', FALSE);
-
- $mockView = $this->getMock('Tx_Extbase_MVC_View_ViewInterface');
-
- $mockController = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_MVC_Controller_ActionController'), array(
- 'initializeFooAction', 'initializeAction', 'resolveActionMethodName', 'initializeActionMethodArguments', 'initializeActionMethodValidators', 'mapRequestArgumentsToControllerArguments', 'resolveView', 'initializeView', 'callActionMethod', 'checkRequestHash'),
- array(), '', FALSE);
- $mockController->_set('objectFactory', $mockObjectFactory);
- $mockController->expects($this->at(0))->method('resolveActionMethodName')->will($this->returnValue('fooAction'));
- $mockController->expects($this->at(1))->method('initializeActionMethodArguments');
- $mockController->expects($this->at(2))->method('initializeActionMethodValidators');
- $mockController->expects($this->at(3))->method('initializeAction');
- $mockController->expects($this->at(4))->method('initializeFooAction');
- $mockController->expects($this->at(5))->method('mapRequestArgumentsToControllerArguments');
- $mockController->expects($this->at(6))->method('checkRequestHash');
- $mockController->expects($this->at(7))->method('resolveView')->will($this->returnValue($mockView));
- $mockController->expects($this->at(8))->method('initializeView');
- $mockController->expects($this->at(9))->method('callActionMethod');
-
- $mockController->processRequest($mockRequest, $mockResponse);
- $this->assertSame($mockRequest, $mockController->_get('request'));
- $this->assertSame($mockResponse, $mockController->_get('response'));
- }
-
- /**
- * @test
- * @author Robert Lemke <robert@typo3.org>
- */
- public function callActionMethodAppendsStringsReturnedByActionMethodToTheResponseObject() {
- $mockRequest = $this->getMock('Tx_Extbase_MVC_RequestInterface', array(), array(), '', FALSE);
-
- $mockResponse = $this->getMock('Tx_Extbase_MVC_ResponseInterface', array(), array(), '', FALSE);
- $mockResponse->expects($this->once())->method('appendContent')->with('the returned string');
-
- $mockArguments = new ArrayObject;
-
- $mockArgumentMappingResults = $this->getMock('Tx_Extbase_Property_MappingResults', array(), array(), '', FALSE);
- $mockArgumentMappingResults->expects($this->once())->method('hasErrors')->will($this->returnValue(FALSE));
-
- $mockController = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_MVC_Controller_ActionController'), array('fooAction', 'initializeAction'), array(), '', FALSE);
- $mockController->expects($this->once())->method('fooAction')->will($this->returnValue('the returned string'));
- $mockController->_set('request', $mockRequest);
- $mockController->_set('response', $mockResponse);
- $mockController->_set('arguments', $mockArguments);
- $mockController->_set('actionMethodName', 'fooAction');
- $mockController->_set('argumentsMappingResults', $mockArgumentMappingResults);
- $mockController->_call('callActionMethod');
- }
-
- /**
- * @test
- * @author Robert Lemke <robert@typo3.org>
- */
- public function callActionMethodRendersTheViewAutomaticallyIfTheActionReturnedNullAndAViewExists() {
- $mockRequest = $this->getMock('Tx_Extbase_MVC_RequestInterface', array(), array(), '', FALSE);
-
- $mockResponse = $this->getMock('Tx_Extbase_MVC_ResponseInterface', array(), array(), '', FALSE);
- $mockResponse->expects($this->once())->method('appendContent')->with('the view output');
-
- $mockView = $this->getMock('Tx_Extbase_MVC_View_ViewInterface');
- $mockView->expects($this->once())->method('render')->will($this->returnValue('the view output'));
-
- $mockArguments = new ArrayObject;
-
- $mockArgumentMappingResults = $this->getMock('Tx_Extbase_Property_MappingResults', array(), array(), '', FALSE);
- $mockArgumentMappingResults->expects($this->once())->method('hasErrors')->will($this->returnValue(FALSE));
-
- $mockController = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_MVC_Controller_ActionController'), array('fooAction', 'initializeAction'), array(), '', FALSE);
- $mockController->expects($this->once())->method('fooAction');
- $mockController->_set('request', $mockRequest);
- $mockController->_set('response', $mockResponse);
- $mockController->_set('arguments', $mockArguments);
- $mockController->_set('actionMethodName', 'fooAction');
- $mockController->_set('argumentsMappingResults', $mockArgumentMappingResults);
- $mockController->_set('view', $mockView);
- $mockController->_call('callActionMethod');
- }
-
- /**
- * @test
- * @author Robert Lemke <robert@typo3.org>
- */
- public function callActionMethodCallsTheErrorActionIfTheMappingResultsHaveErrors() {
- $mockRequest = $this->getMock('Tx_Extbase_MVC_RequestInterface', array(), array(), '', FALSE);
-
- $mockResponse = $this->getMock('Tx_Extbase_MVC_ResponseInterface', array(), array(), '', FALSE);
- $mockResponse->expects($this->once())->method('appendContent')->with('the returned string');
-
- $mockArguments = new ArrayObject;
-
- $mockArgumentMappingResults = $this->getMock('Tx_Extbase_Property_MappingResults', array(), array(), '', FALSE);
- $mockArgumentMappingResults->expects($this->once())->method('hasErrors')->will($this->returnValue(TRUE));
-
- $mockController = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_MVC_Controller_ActionController'), array('barAction', 'initializeAction'), array(), '', FALSE);
- $mockController->expects($this->once())->method('barAction')->will($this->returnValue('the returned string'));
- $mockController->_set('request', $mockRequest);
- $mockController->_set('response', $mockResponse);
- $mockController->_set('arguments', $mockArguments);
- $mockController->_set('actionMethodName', 'fooAction');
- $mockController->_set('errorMethodName', 'barAction');
- $mockController->_set('argumentsMappingResults', $mockArgumentMappingResults);
- $mockController->_call('callActionMethod');
- }
-
- /**
- * @test
- * @author Sebastian Kurfürst <sebastian@typo3.org>
- */
- public function callActionMethodPassesDefaultValuesAsArguments() {
- $mockRequest = $this->getMock('Tx_Extbase_MVC_RequestInterface', array(), array(), '', FALSE);
-
- $mockResponse = $this->getMock('Tx_Extbase_MVC_ResponseInterface', array(), array(), '', FALSE);
-
- $arguments = new ArrayObject();
- $optionalArgument = new Tx_Extbase_MVC_Controller_Argument('name1', 'Text');
- $optionalArgument->setDefaultValue('Default value');
- $arguments[] = $optionalArgument;
-
- $mockArgumentMappingResults = $this->getMock('Tx_Extbase_Property_MappingResults', array(), array(), '', FALSE);
- $mockArgumentMappingResults->expects($this->once())->method('hasErrors')->will($this->returnValue(FALSE));
-
- $mockController = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_MVC_Controller_ActionController'), array('fooAction', 'initializeAction'), array(), '', FALSE);
- $mockController->expects($this->once())->method('fooAction')->with('Default value');
- $mockController->_set('request', $mockRequest);
- $mockController->_set('response', $mockResponse);
- $mockController->_set('arguments', $arguments);
- $mockController->_set('actionMethodName', 'fooAction');
- $mockController->_set('argumentsMappingResults', $mockArgumentMappingResults);
- $mockController->_call('callActionMethod');
- }
-
- /**
- * @test
- * @author Karsten Dambekalns <karsten@typo3.org>
- */
- public function resolveViewUsesFluidTemplateViewIfTemplateIsAvailable() {
- $mockSession = $this->getMock('Tx_Extbase_Session_SessionInterface');
- $mockControllerContext = $this->getMock('Tx_Extbase_MVC_Controller_ControllerContext', array(), array(), '', FALSE);
-
- $mockFluidTemplateView = $this->getMock('Tx_Extbase_MVC_View_ViewInterface', array('setControllerContext', 'getViewHelper', 'assign', 'assignMultiple', 'render', 'hasTemplate', 'initializeView'));
- $mockFluidTemplateView->expects($this->once())->method('setControllerContext')->with($mockControllerContext);
- $mockFluidTemplateView->expects($this->once())->method('hasTemplate')->will($this->returnValue(TRUE));
-
- $mockObjectManager = $this->getMock('Tx_Extbase_Object_ObjectManagerInterface', array(), array(), '', FALSE);
- $mockObjectManager->expects($this->at(0))->method('get')->with('Tx_Fluid_View_TemplateView')->will($this->returnValue($mockFluidTemplateView));
-
- $mockController = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_MVC_Controller_ActionController'), array('buildControllerContext'), array(), '', FALSE);
- $mockController->expects($this->once())->method('buildControllerContext')->will($this->returnValue($mockControllerContext));
- $mockController->_set('session', $mockSession);
- $mockController->_set('objectManager', $mockObjectManager);
-
- $this->assertSame($mockFluidTemplateView, $mockController->_call('resolveView'));
- }
-
- /**
- * @test
- * @author Bastian Waidelich <bastian@typo3.org>
- */
- public function resolveViewObjectNameUsesViewObjectNamePatternToResolveViewObjectName() {
- $mockRequest = $this->getMock('Tx_Extbase_MVC_RequestInterface', array(), array(), '', FALSE);
- $mockRequest->expects($this->once())->method('getControllerExtensionName')->will($this->returnValue('MyPackage'));
- $mockRequest->expects($this->once())->method('getControllerName')->will($this->returnValue('MyController'));
- $mockRequest->expects($this->once())->method('getControllerActionName')->will($this->returnValue('MyAction'));
- $mockRequest->expects($this->once())->method('getFormat')->will($this->returnValue('MyFormat'));
-
- $mockObjectManager = $this->getMock('Tx_Extbase_Object_ObjectManagerInterface', array(), array(), '', FALSE);
-
- $mockController = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_MVC_Controller_ActionController'), array('dummy'), array(), '', FALSE);
- $mockController->_set('request', $mockRequest);
- $mockController->_set('objectManager', $mockObjectManager);
- $mockController->_set('viewObjectNamePattern', 'RandomViewObjectPattern_@package_@controller_@action_@format');
-
- $mockController->_call('resolveViewObjectName');
- }
-
- /**
- * @test
- * @author Robert Lemke <robert@typo3.org>
- */
- public function resolveActionMethodNameReturnsTheCurrentActionMethodNameFromTheRequest() {
- $mockRequest = $this->getMock('Tx_Extbase_MVC_RequestInterface', array(), array(), '', FALSE);
- $mockRequest->expects($this->once())->method('getControllerActionName')->will($this->returnValue('fooBar'));
-
- $mockController = $this->getAccessibleMock('Tx_Extbase_MVC_Controller_ActionController', array('fooBarAction'), array(), '', FALSE);
- $mockController->_set('request', $mockRequest);
-
- $this->assertEquals('fooBarAction', $mockController->_call('resolveActionMethodName'));
- }
-
- /**
- * @test
- * @expectedException Tx_Extbase_MVC_Exception_NoSuchAction
- * @author Robert Lemke <robert@typo3.org>
- */
- public function resolveActionMethodNameThrowsAnExceptionIfTheActionDefinedInTheRequestDoesNotExist() {
- $mockRequest = $this->getMock('Tx_Extbase_MVC_RequestInterface', array(), array(), '', FALSE);
- $mockRequest->expects($this->once())->method('getControllerActionName')->will($this->returnValue('fooBar'));
-
- $mockController = $this->getAccessibleMock('Tx_Extbase_MVC_Controller_ActionController', array('otherBarAction'), array(), '', FALSE);
- $mockController->_set('request', $mockRequest);
-
- $mockController->_call('resolveActionMethodName');
- }
-
- /**
- * @test
- * @author Robert Lemke <robert@typo3.org>
- */
- public function initializeActionMethodArgumentsRegistersArgumentsFoundInTheSignatureOfTheCurrentActionMethod() {
- $mockRequest = $this->getMock('Tx_Extbase_MVC_RequestInterface', array(), array(), '', FALSE);
-
- $mockArguments = $this->getMock('Tx_Extbase_MVC_Controller_Arguments', array('addNewArgument', 'removeAll'), array(), '', FALSE);
- $mockArguments->expects($this->at(0))->method('addNewArgument')->with('stringArgument', 'string', TRUE);
- $mockArguments->expects($this->at(1))->method('addNewArgument')->with('integerArgument', 'integer', TRUE);
- $mockArguments->expects($this->at(2))->method('addNewArgument')->with('objectArgument', 'F3_Foo_Bar', TRUE);
-
- $mockController = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_MVC_Controller_ActionController'), array('fooAction', 'evaluateDontValidateAnnotations'), array(), '', FALSE);
-
- $methodParameters = array(
- 'stringArgument' => array(
- 'position' => 0,
- 'byReference' => FALSE,
- 'array' => FALSE,
- 'optional' => FALSE,
- 'allowsNull' => FALSE,
- 'type' => 'string'
- ),
- 'integerArgument' => array(
- 'position' => 1,
- 'byReference' => FALSE,
- 'array' => FALSE,
- 'optional' => FALSE,
- 'allowsNull' => FALSE,
- 'type' => 'integer'
- ),
- 'objectArgument' => array(
- 'position' => 2,
- 'byReference' => FALSE,
- 'array' => FALSE,
- 'optional' => FALSE,
- 'allowsNull' => FALSE,
- 'type' => 'F3_Foo_Bar'
- )
- );
-
- $mockReflectionService = $this->getMock('Tx_Extbase_Reflection_Service', array(), array(), '', FALSE);
- $mockReflectionService->expects($this->once())->method('getMethodParameters')->with(get_class($mockController), 'fooAction')->will($this->returnValue($methodParameters));
-
- $mockController->injectReflectionService($mockReflectionService);
- $mockController->_set('request', $mockRequest);
- $mockController->_set('arguments', $mockArguments);
- $mockController->_set('actionMethodName', 'fooAction');
- $mockController->_call('initializeActionMethodArguments');
- }
-
- /**
- * @test
- * @author Robert Lemke <robert@typo3.org>
- */
- public function initializeActionMethodArgumentsRegistersOptionalArgumentsAsSuch() {
- $mockRequest = $this->getMock('Tx_Extbase_MVC_RequestInterface', array(), array(), '', FALSE);
-
- $mockArguments = $this->getMock('Tx_Extbase_MVC_Controller_Arguments', array(), array(), '', FALSE);
- $mockArguments->expects($this->at(0))->method('addNewArgument')->with('arg1', 'string', TRUE);
- $mockArguments->expects($this->at(1))->method('addNewArgument')->with('arg2', 'array', FALSE, array(21));
- $mockArguments->expects($this->at(2))->method('addNewArgument')->with('arg3', 'string', FALSE, 42);
-
- $mockController = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_MVC_Controller_ActionController'), array('fooAction', 'evaluateDontValidateAnnotations'), array(), '', FALSE);
-
- $methodParameters = array(
- 'arg1' => array(
- 'position' => 0,
- 'byReference' => FALSE,
- 'array' => FALSE,
- 'optional' => FALSE,
- 'allowsNull' => FALSE,
- 'type' => 'string'
- ),
- 'arg2' => array(
- 'position' => 1,
- 'byReference' => FALSE,
- 'array' => TRUE,
- 'optional' => TRUE,
- 'defaultValue' => array(21),
- 'allowsNull' => FALSE
- ),
- 'arg3' => array(
- 'position' => 2,
- 'byReference' => FALSE,
- 'array' => FALSE,
- 'optional' => TRUE,
- 'defaultValue' => 42,
- 'allowsNull' => FALSE,
- 'type' => 'string'
- )
- );
-
- $mockReflectionService = $this->getMock('Tx_Extbase_Reflection_Service', array(), array(), '', FALSE);
- $mockReflectionService->expects($this->once())->method('getMethodParameters')->with(get_class($mockController), 'fooAction')->will($this->returnValue($methodParameters));
-
- $mockController->injectReflectionService($mockReflectionService);
- $mockController->_set('request', $mockRequest);
- $mockController->_set('arguments', $mockArguments);
- $mockController->_set('actionMethodName', 'fooAction');
- $mockController->_call('initializeActionMethodArguments');
- }
-
- /**
- * @test
- * @author Sebastian Kurfürst <sbastian@typo3.org>
- * @expectedException Tx_Extbase_MVC_Exception_InvalidArgumentType
- */
- public function initializeActionMethodArgumentsThrowsExceptionIfDataTypeWasNotSpecified() {
- $mockRequest = $this->getMock('Tx_Extbase_MVC_RequestInterface', array(), array(), '', FALSE);
-
- $mockArguments = $this->getMock('Tx_Extbase_MVC_Controller_Arguments', array(), array(), '', FALSE);
-
- $mockController = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_MVC_Controller_ActionController'), array('fooAction'), array(), '', FALSE);
-
- $methodParameters = array(
- 'arg1' => array(
- 'position' => 0,
- 'byReference' => FALSE,
- 'array' => FALSE,
- 'optional' => FALSE,
- 'allowsNull' => FALSE,
- )
- );
-
- $mockReflectionService = $this->getMock('Tx_Extbase_Reflection_Service', array(), array(), '', FALSE);
- $mockReflectionService->expects($this->once())->method('getMethodParameters')->with(get_class($mockController), 'fooAction')->will($this->returnValue($methodParameters));
-
- $mockController->injectReflectionService($mockReflectionService);
- $mockController->_set('request', $mockRequest);
- $mockController->_set('arguments', $mockArguments);
- $mockController->_set('actionMethodName', 'fooAction');
- $mockController->_call('initializeActionMethodArguments');
- }
-
- /**
- * @test
- * @author Sebastian Kurfürst <sbastian@typo3.org>
- */
- public function initializeActionMethodValidatorsCorrectlyRegistersValidatorsBasedOnDataType() {
- $mockController = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_MVC_Controller_ActionController'), array('fooAction'), array(), '', FALSE);
-
- $argument = $this->getMock('Tx_Extbase_MVC_Controller_Argument', array('getName'), array(), '', FALSE);
- $argument->expects($this->any())->method('getName')->will($this->returnValue('arg1'));
-
- $arguments = $this->getMock('Tx_Extbase_MVC_Controller_Arguments', array('dummy'), array(), '', FALSE);
- $arguments->addArgument($argument);
-
- $methodTagsValues = array(
-
- );
-
- $methodArgumentsValidatorConjunctions = array();
- $methodArgumentsValidatorConjunctions['arg1'] = $this->getMock('Tx_Extbase_Validation_Validator_ConjunctionValidator', array(), array(), '', FALSE);
-
- $mockReflectionService = $this->getMock('Tx_Extbase_Reflection_Service', array(), array(), '', FALSE);
- $mockReflectionService->expects($this->once())->method('getMethodTagsValues')->with(get_class($mockController), 'fooAction')->will($this->returnValue($methodTagsValues));
-
- $mockValidatorResolver = $this->getMock('Tx_Extbase_Validation_ValidatorResolver', array(), array(), '', FALSE);
- $mockValidatorResolver->expects($this->once())->method('buildMethodArgumentsValidatorConjunctions')->with(get_class($mockController), 'fooAction')->will($this->returnValue($methodArgumentsValidatorConjunctions));
-
- $mockController->injectReflectionService($mockReflectionService);
- $mockController->injectValidatorResolver($mockValidatorResolver);
- $mockController->_set('arguments', $arguments);
- $mockController->_set('actionMethodName', 'fooAction');
- $mockController->_call('initializeActionMethodValidators');
-
- $this->assertEquals($methodArgumentsValidatorConjunctions['arg1'], $arguments['arg1']->getValidator());
- }
-
- /**
- * @test
- * @author Sebastian Kurfürst <sbastian@typo3.org>
- */
- public function initializeActionMethodValidatorsRegistersModelBasedValidators() {
- $mockController = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_MVC_Controller_ActionController'), array('fooAction'), array(), '', FALSE);
-
- $argument = $this->getMock('Tx_Extbase_MVC_Controller_Argument', array('getName', 'getDataType'), array(), '', FALSE);
- $argument->expects($this->any())->method('getName')->will($this->returnValue('arg1'));
- $argument->expects($this->any())->method('getDataType')->will($this->returnValue('F3_Foo_Quux'));
-
- $arguments = $this->getMock('Tx_Extbase_MVC_Controller_Arguments', array('dummy'), array(), '', FALSE);
- $arguments->addArgument($argument);
-
- $methodTagsValues = array(
-
- );
-
- $quuxBaseValidatorConjunction = $this->getMock('Tx_Extbase_Validation_Validator_ConjunctionValidator', array(), array(), '', FALSE);
-
- $methodArgumentsValidatorConjunctions = array();
- $methodArgumentsValidatorConjunctions['arg1'] = $this->getMock('Tx_Extbase_Validation_Validator_ConjunctionValidator', array(), array(), '', FALSE);
- $methodArgumentsValidatorConjunctions['arg1']->expects($this->once())->method('addValidator')->with($quuxBaseValidatorConjunction);
-
- $mockReflectionService = $this->getMock('Tx_Extbase_Reflection_Service', array(), array(), '', FALSE);
- $mockReflectionService->expects($this->once())->method('getMethodTagsValues')->with(get_class($mockController), 'fooAction')->will($this->returnValue($methodTagsValues));
-
- $mockValidatorResolver = $this->getMock('Tx_Extbase_Validation_ValidatorResolver', array(), array(), '', FALSE);
- $mockValidatorResolver->expects($this->once())->method('buildMethodArgumentsValidatorConjunctions')->with(get_class($mockController), 'fooAction')->will($this->returnValue($methodArgumentsValidatorConjunctions));
- $mockValidatorResolver->expects($this->once())->method('getBaseValidatorConjunction')->with('F3_Foo_Quux')->will($this->returnValue($quuxBaseValidatorConjunction));
-
- $mockController->injectReflectionService($mockReflectionService);
- $mockController->injectValidatorResolver($mockValidatorResolver);
- $mockController->_set('arguments', $arguments);
- $mockController->_set('actionMethodName', 'fooAction');
- $mockController->_call('initializeActionMethodValidators');
-
- $this->assertEquals($methodArgumentsValidatorConjunctions['arg1'], $arguments['arg1']->getValidator());
- }
-
- /**
- * @test
- * @author Sebastian Kurfürst <sbastian@typo3.org>
- */
- public function initializeActionMethodValidatorsDoesNotRegisterModelBasedValidatorsIfDontValidateAnnotationIsSet() {
- $mockController = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_MVC_Controller_ActionController'), array('fooAction'), array(), '', FALSE);
-
- $argument = $this->getMock('Tx_Extbase_MVC_Controller_Argument', array('getName', 'getDataType'), array(), '', FALSE);
- $argument->expects($this->any())->method('getName')->will($this->returnValue('arg1'));
- $argument->expects($this->any())->method('getDataType')->will($this->returnValue('F3_Foo_Quux'));
-
- $arguments = $this->getMock('Tx_Extbase_MVC_Controller_Arguments', array('dummy'), array(), '', FALSE);
- $arguments->addArgument($argument);
-
- $methodTagsValues = array(
- 'dontvalidate' => array(
- '$arg1'
- )
- );
-
- $methodArgumentsValidatorConjunctions = array();
- $methodArgumentsValidatorConjunctions['arg1'] = $this->getMock('Tx_Extbase_Validation_Validator_ConjunctionValidator', array(), array(), '', FALSE);
-
- $mockReflectionService = $this->getMock('Tx_Extbase_Reflection_Service', array(), array(), '', FALSE);
- $mockReflectionService->expects($this->once())->method('getMethodTagsValues')->with(get_class($mockController), 'fooAction')->will($this->returnValue($methodTagsValues));
-
- $mockValidatorResolver = $this->getMock('Tx_Extbase_Validation_ValidatorResolver', array(), array(), '', FALSE);
- $mockValidatorResolver->expects($this->once())->method('buildMethodArgumentsValidatorConjunctions')->with(get_class($mockController), 'fooAction')->will($this->returnValue($methodArgumentsValidatorConjunctions));
- $mockValidatorResolver->expects($this->any())->method('getBaseValidatorConjunction')->will($this->throwException(new Exception("This should not be called because the dontvalidate annotation is set.")));
-
- $mockController->injectReflectionService($mockReflectionService);
- $mockController->injectValidatorResolver($mockValidatorResolver);
- $mockController->_set('arguments', $arguments);
- $mockController->_set('actionMethodName', 'fooAction');
- $mockController->_call('initializeActionMethodValidators');
-
- $this->assertEquals($methodArgumentsValidatorConjunctions['arg1'], $arguments['arg1']->getValidator());
- }
-
- /**
- * @test
- * @author Christopher Hlubek <hlubek@networkteam.com>
- */
- public function defaultErrorActionSetsArgumentMappingResultsErrorsInRequest() {
- $mockRequest = $this->getMock('Tx_Extbase_MVC_RequestInterface', array(), array(), '', FALSE);
- $mockFlashMessages = $this->getMock('Tx_Extbase_MVC_Controller_FlashMessages', array(), array(), '', FALSE);
-
- $mockError = $this->getMock('Tx_Extbase_Error_Error', array('getMessage'), array(), '', FALSE);
- $mockArgumentsMappingResults = $this->getMock('Tx_Extbase_Property_MappingResults', array('getErrors', 'getWarnings'), array(), '', FALSE);
- $mockArgumentsMappingResults->expects($this->atLeastOnce())->method('getErrors')->will($this->returnValue(array($mockError)));
- $mockArgumentsMappingResults->expects($this->any())->method('getWarnings')->will($this->returnValue(array()));
-
- $mockController = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_MVC_Controller_ActionController'), array('pushFlashMessage'), array(), '', FALSE);
- $mockController->_set('request', $mockRequest);
- $mockController->_set('flashMessages', $mockFlashMessages);
- $mockController->_set('argumentsMappingResults', $mockArgumentsMappingResults);
-
- $mockRequest->expects($this->once())->method('setErrors')->with(array($mockError));
-
- $mockController->_call('errorAction');
- }
-
- /**
- * @test
- * @author Christopher Hlubek <hlubek@networkteam.com>
- */
- public function defaultErrorActionCallsGetErrorFlashMessageAndPutsFlashMessage() {
- $this->markTestIncomplete('To be implemented');
- }
-
- /**
- * Data Provider for checkRequestHashDoesNotThrowExceptionInNormalOperations
- */
- public function checkRequestHashInNormalOperation() {
- return array(
- // HMAC is verified
- array(TRUE),
- // HMAC not verified, but objects are directly fetched from persistence layer
- array(FALSE, FALSE, Tx_Extbase_MVC_Controller_Argument::ORIGIN_PERSISTENCE, Tx_Extbase_MVC_Controller_Argument::ORIGIN_PERSISTENCE),
- // HMAC not verified, objects new and modified, but dontverifyrequesthash-annotation set
- array(FALSE, TRUE, Tx_Extbase_MVC_Controller_Argument::ORIGIN_PERSISTENCE, Tx_Extbase_MVC_Controller_Argument::ORIGIN_PERSISTENCE_AND_MODIFIED, array('dontverifyrequesthash' => ''))
- );
- }
-
- /**
- * @test
- * @author Sebastian Kurfürst <sebastian@typo3.org>
- * @dataProvider checkRequestHashInNormalOperation
- */
- public function checkRequestHashDoesNotThrowExceptionInNormalOperations($hmacVerified, $reflectionServiceNeedsInitialization = FALSE, $argument1Origin = 3, $argument2Origin = 3, $methodTagsValues = array()) {
- $mockRequest = $this->getMock('Tx_Extbase_MVC_Web_Request', array('isHmacVerified'), array(), '', FALSE);
- $mockRequest->expects($this->once())->method('isHmacVerified')->will($this->returnValue($hmacVerified));
-
- $argument1 = $this->getMock('Tx_Extbase_MVC_Controller_Argument', array('getOrigin'), array(), '', FALSE);
- $argument1->expects($this->any())->method('getOrigin')->will($this->returnValue($argument1Origin));
- $argument2 = $this->getMock('Tx_Extbase_MVC_Controller_Argument', array('getOrigin'), array(), '', FALSE);
- $argument2->expects($this->any())->method('getOrigin')->will($this->returnValue($argument2Origin));
-
- $mockController = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_MVC_Controller_ActionController'), array('dummy'), array(), '', FALSE);
-
- $mockReflectionService = $this->getMock('Tx_Extbase_Reflection_Service', array('getMethodTagsValues'), array(), '', FALSE);
- if ($reflectionServiceNeedsInitialization) {
- // Somehow this is needed, else I get "Mocked method does not exist."
- $mockReflectionService->expects($this->any())->method('getMethodTagsValues')->with(get_class($mockController), 'fooAction')->will($this->returnValue($methodTagsValues));
- }
- $mockController->_set('arguments', array($argument1, $argument2));
- $mockController->_set('request', $mockRequest);
- $mockController->_set('actionMethodName', 'fooAction');
- $mockController->injectReflectionService($mockReflectionService);
-
- $mockController->_call('checkRequestHash');
- }
-
- /**
- * @test
- * @expectedException Tx_Extbase_MVC_Exception_InvalidOrNoRequestHash
- * @author Sebastian Kurfürst <sebastian@typo3.org>
- */
- public function checkRequestHashThrowsExceptionIfNeeded() {
- // $this->markTestIncomplete('To be implemented');
- $hmacVerified = FALSE;
- $argument1Origin = Tx_Extbase_MVC_Controller_Argument::ORIGIN_PERSISTENCE_AND_MODIFIED;
- $argument2Origin = Tx_Extbase_MVC_Controller_Argument::ORIGIN_PERSISTENCE;
- $methodTagsValues = array();
-
- $mockRequest = $this->getMock('Tx_Extbase_MVC_Web_Request', array('isHmacVerified'), array(), '', FALSE);
- $mockRequest->expects($this->once())->method('isHmacVerified')->will($this->returnValue($hmacVerified));
-
- $argument1 = $this->getMock('Tx_Extbase_MVC_Controller_Argument', array('getOrigin'), array(), '', FALSE);
- $argument1->expects($this->any())->method('getOrigin')->will($this->returnValue($argument1Origin));
- $argument2 = $this->getMock('Tx_Extbase_MVC_Controller_Argument', array('getOrigin'), array(), '', FALSE);
- $argument2->expects($this->any())->method('getOrigin')->will($this->returnValue($argument2Origin));
-
- $mockController = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_MVC_Controller_ActionController'), array('dummy'), array(), '', FALSE);
-
- $mockReflectionService = $this->getMock('Tx_Extbase_Reflection_Service', array('getMethodTagsValues'), array(), '', FALSE);
- $mockReflectionService->expects($this->any())->method('getMethodTagsValues')->with(get_class($mockController), 'fooAction')->will($this->returnValue($methodTagsValues));
-
- $mockController->_set('arguments', array($argument1, $argument2));
- $mockController->_set('request', $mockRequest);
- $mockController->_set('actionMethodName', 'fooAction');
- $mockController->injectReflectionService($mockReflectionService);
-
- $mockController->_call('checkRequestHash');
- }
-
-}
-?>
\ No newline at end of file
+++ /dev/null
-<?php
-/***************************************************************
-* Copyright notice
-*
-* (c) 2009 Jochen Rau <jochen.rau@typoplanet.de>
-* All rights reserved
-*
-* This class is a backport of the corresponding class of FLOW3.
-* All credits go to the v5 team.
-*
-* 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!
-***************************************************************/
-
-class Tx_Extbase_MVC_Controller_Argument_testcase extends Tx_Extbase_BaseTestCase {
-
- /**
- * @test
- * @expectedException InvalidArgumentException
- */
- public function constructingArgumentWithoutNameThrowsException() {
- new Tx_Extbase_MVC_Controller_Argument(NULL, 'Text');
- }
-
- /**
- * @test
- * @expectedException InvalidArgumentException
- */
- public function constructingArgumentWithInvalidNameThrowsException() {
- new Tx_Extbase_MVC_Controller_Argument(new ArrayObject(), 'Text');
- }
-
- /**
- * @test
- */
- public function passingDataTypeToConstructorReallySetsTheDataType() {
- $argument = new Tx_Extbase_MVC_Controller_Argument('dummy', 'Number');
- $this->assertEquals('Number', $argument->getDataType(), 'The specified data type has not been set correctly.');
- }
-
- /**
- * @test
- */
- public function setShortNameProvidesFluentInterface() {
- $argument = new Tx_Extbase_MVC_Controller_Argument('dummy', 'Text');
- $returnedArgument = $argument->setShortName('x');
- $this->assertSame($argument, $returnedArgument, 'The returned argument is not the original argument.');
- }
-
- /**
- * @test
- */
- public function setValueProvidesFluentInterface() {
- $argument = new Tx_Extbase_MVC_Controller_Argument('dummy', 'Text');
- $returnedArgument = $argument->setValue('x');
- $this->assertSame($argument, $returnedArgument, 'The returned argument is not the original argument.');
- }
-
- /**
- * @test
- */
- public function setValueTriesToConvertAnUidIntoTheRealObjectIfTheDataTypeClassSchemaIsSet() {
- $object = new StdClass();
-
- $argument = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_MVC_Controller_Argument'), array('findObjectByUid'), array(), '', FALSE);
- $argument->expects($this->once())->method('findObjectByUid')->with('42')->will($this->returnValue($object));
- $argument->_set('dataTypeClassSchema', 'stdClass');
- $argument->_set('dataType', 'stdClass');
- // $argument->_set('queryFactory', $mockQueryFactory);
- $argument->setValue('42');
-
- $this->assertSame($object, $argument->_get('value'));
- $this->assertSame(Tx_Extbase_MVC_Controller_Argument::ORIGIN_PERSISTENCE, $argument->getOrigin());
- }
-
-
- /**
- * @test
- */
- public function toStringReturnsTheStringVersionOfTheArgumentsValue() {
- $argument = new Tx_Extbase_MVC_Controller_Argument('dummy', 'Text');
- $argument->setValue(123);
-
- $this->assertSame((string)$argument, '123', 'The returned argument is not a string.');
- $this->assertNotSame((string)$argument, 123, 'The returned argument is identical to the set value.');
- }
-
- /**
- * @test
- */
- public function dataTypeValidatorCanBeAFullClassName() {
- $this->markTestIncomplete();
-
- $this->mockObjectManager->expects($this->once())->method('isObjectRegistered')->with('Tx_Extbase_Validation_Validator_TextValidator')->will($this->returnValue(TRUE));
- $this->mockObjectManager->expects($this->any())->method('get')->with('Tx_Extbase_Validation_Validator_TextValidator')->will($this->returnValue($this->getMock('Tx_Extbase_Validation_Validator_TextValidator')));
-
- $argument = new Tx_Extbase_MVC_Controller_Argument('SomeArgument', 'Tx_Extbase_Validation_Validator_TextValidator');
- $argument->injectObjectManager($this->mockObjectManager);
-
- $this->assertType('Tx_Extbase_Validation_Validator_TextValidator', $argument->getDatatypeValidator(), 'The returned datatype validator is not a text validator as expected.');
- }
-
- /**
- * @test
- */
- public function dataTypeValidatorCanBeAShortName() {
- $this->markTestIncomplete();
-
- $this->mockObjectManager->expects($this->once())->method('isObjectRegistered')->with('Tx_Extbase_Validation_Validator_TextValidator')->will($this->returnValue(TRUE));
- $this->mockObjectManager->expects($this->any())->method('get')->with('Tx_Extbase_Validation_Validator_TextValidator')->will($this->returnValue($this->getMock('Tx_Extbase_Validation_Validator_TextValidator')));
-
- $argument = new Tx_Extbase_MVC_Controller_Argument('SomeArgument', 'Text');
- $argument->injectObjectManager($this->mockObjectManager);
-
- $this->assertType('Tx_Extbase_Validation_Validator_TextValidator', $argument->getDatatypeValidator(), 'The returned datatype validator is not a text validator as expected.');
- }
-
- /**
- * @test
- */
- public function setNewValidatorConjunctionCreatesANewValidatorConjunctionObject() {
- $argument = new Tx_Extbase_MVC_Controller_Argument('dummy', 'Text');
- $argument->setNewValidatorConjunction(array());
-
- $this->assertType('Tx_Extbase_Validation_Validator_ConjunctionValidator', $argument->getValidator(), 'The returned validator is not a conjunction as expected.');
- }
-
- /**
- * @test
- */
- public function setNewValidatorConjunctionAddsThePassedValidatorsToTheCreatedValidatorChain() {
- eval('class Validator1 implements Tx_Extbase_Validation_Validator_ValidatorInterface {
- public function isValid($value) {}
- public function setOptions(array $validationOptions) {}
- public function getErrors() {}
- }');
- eval('class Validator2 implements Tx_Extbase_Validation_Validator_ValidatorInterface {
- public function isValid($value) {}
- public function setOptions(array $validationOptions) {}
- public function getErrors() {}
- }');
-
- $validator1 = new Validator1;
- $validator2 = new Validator2;
-
- $mockValidatorConjunction = $this->getMock('Tx_Extbase_Validation_Validator_ConjunctionValidator');
- $mockValidatorConjunction->expects($this->at(0))->method('addValidator')->with($validator1);
- $mockValidatorConjunction->expects($this->at(1))->method('addValidator')->with($validator2);
-
- $argument = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_MVC_Controller_Argument'), array('dummy'), array(), '', FALSE);
- $argument->_set('validator', $mockValidatorConjunction);
- $argument->setNewValidatorConjunction(array('Validator1', 'Validator2'));
- }
-
- /**
- * @test
- */
- public function settingDefaultValueReallySetsDefaultValue() {
- $argument = new Tx_Extbase_MVC_Controller_Argument('dummy', 'Text');
- $argument->setDefaultValue(42);
-
- $this->assertEquals(42, $argument->getValue(), 'The default value was not stored in the Argument.');
- }
-
-}
-?>
\ No newline at end of file
+++ /dev/null
-<?php
-/***************************************************************
-* Copyright notice
-*
-* (c) 2009 Jochen Rau <jochen.rau@typoplanet.de>
-* All rights reserved
-*
-* This class is a backport of the corresponding class of FLOW3.
-* All credits go to the v5 team.
-*
-* 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!
-***************************************************************/
-
-class Tx_Extbase_MVC_Controller_Arguments_testcase extends Tx_Extbase_BaseTestCase {
-
- /**
- * @test
- */
- public function argumentsObjectIsOfScopePrototype() {
- $arguments1 = $this->objectManager->get('Tx_Extbase_MVC_Controller_Arguments');
- $arguments2 = $this->objectManager->get('Tx_Extbase_MVC_Controller_Arguments');
- $this->assertNotSame($arguments1, $arguments2, 'The arguments object is not of scope prototype!');
- }
-
- /**
- * @test
- */
- public function addingAnArgumentManuallyWorks() {
- $arguments = $this->objectManager->get('Tx_Extbase_MVC_Controller_Arguments');
- $newArgument = $this->objectManager->get('Tx_Extbase_MVC_Controller_Argument', 'argumentName1234', 'dummyValue');
-
- $arguments->addArgument($newArgument);
- $this->assertSame($newArgument, $arguments->getArgument('argumentName1234'), 'The added and retrieved argument is not the same.');
- }
-
- /**
- * @test
- */
- public function addingAnArgumentReplacesArgumentWithSameName() {
- $arguments = new Tx_Extbase_MVC_Controller_Arguments;
-
- $mockFirstArgument = $this->getMock('Tx_Extbase_MVC_Controller_Argument', array('getName'), array(), '', FALSE);
- $mockFirstArgument->expects($this->any())->method('getName')->will($this->returnValue('argumentName1234'));
- $arguments->addArgument($mockFirstArgument);
-
- $mockSecondArgument = $this->getMock('Tx_Extbase_MVC_Controller_Argument', array('getName'), array(), '', FALSE);
- $mockSecondArgument->expects($this->any())->method('getName')->will($this->returnValue('argumentName1234'));
- $arguments->addArgument($mockSecondArgument);
-
- $this->assertSame($mockSecondArgument, $arguments->getArgument('argumentName1234'), 'The added and retrieved argument is not the same.');
- }
-
- /**
- * @test
- */
- public function addNewArgumentProvidesFluentInterface() {
- $mockArgument = $this->getMock('Tx_Extbase_MVC_Controller_Argument', array(), array(), '', FALSE);
- $mockArguments = $this->getMock('Tx_Extbase_MVC_Controller_Arguments', array('createArgument'));
- $mockArguments->expects($this->any())->method('createArgument')->will($this->returnValue($mockArgument));
-
- $newArgument = $mockArguments->addNewArgument('someArgument');
- $this->assertType('Tx_Extbase_MVC_Controller_Argument', $newArgument, 'addNewArgument() did not return an argument object.');
- }
-
- /**
- * @test
- */
- public function addingArgumentThroughArrayAccessWorks() {
- $mockArgument = $this->getMock('Tx_Extbase_MVC_Controller_Argument', array('getName'), array(), '', FALSE);
- $mockArgument->expects($this->any())->method('getName')->will($this->returnValue('argumentName1234'));
- $arguments = new Tx_Extbase_MVC_Controller_Arguments;
-
- $arguments[] = $mockArgument;
- $this->assertTrue($arguments->hasArgument('argumentName1234'), 'Added argument does not exist.');
- $this->assertSame($mockArgument, $arguments->getArgument('argumentName1234'), 'Added and retrieved arguments are not the same.');
- }
-
- /**
- * @test
- */
- public function retrievingArgumentThroughArrayAccessWorks() {
- $mockArgument = $this->getMock('Tx_Extbase_MVC_Controller_Argument', array('getName'), array(), '', FALSE);
- $mockArgument->expects($this->any())->method('getName')->will($this->returnValue('argumentName1234'));
- $arguments = new Tx_Extbase_MVC_Controller_Arguments;
-
- $arguments[] = $mockArgument;
- $this->assertSame($mockArgument, $arguments['argumentName1234'], 'Argument retrieved by array access is not the one we added.');
- }
-
- /**
- * @test
- */
- public function getArgumentWithNonExistingArgumentNameThrowsException() {
- $arguments = $this->objectManager->get('Tx_Extbase_MVC_Controller_Arguments');
- try {
- $arguments->getArgument('someArgument');
- $this->fail('getArgument() did not throw an exception although the specified argument does not exist.');
- } catch (Tx_Extbase_MVC_Exception_NoSuchArgument $exception) {
- }
- }
-
- /**
- * @test
- */
- public function issetReturnsCorrectResult() {
- $mockArgument = $this->getMock('Tx_Extbase_MVC_Controller_Argument', array('getName'), array(), '', FALSE);
- $mockArgument->expects($this->any())->method('getName')->will($this->returnValue('argumentName1234'));
- $arguments = new Tx_Extbase_MVC_Controller_Arguments;
-
- $this->assertFalse(isset($arguments['argumentName1234']), 'isset() did not return FALSE.');
- $arguments[] = $mockArgument;
- $this->assertTrue(isset($arguments['argumentName1234']), 'isset() did not return TRUE.');
- }
-
- /**
- * @test
- */
- public function getArgumentNamesReturnsNamesOfAddedArguments() {
- $mockArgument1 = $this->getMock('Tx_Extbase_MVC_Controller_Argument', array('getName'), array(), '', FALSE);
- $mockArgument1->expects($this->any())->method('getName')->will($this->returnValue('argumentName1'));
- $mockArgument2 = $this->getMock('Tx_Extbase_MVC_Controller_Argument', array('getName'), array(), '', FALSE);
- $mockArgument2->expects($this->any())->method('getName')->will($this->returnValue('argumentName2'));
- $mockArgument3 = $this->getMock('Tx_Extbase_MVC_Controller_Argument', array('getName'), array(), '', FALSE);
- $mockArgument3->expects($this->any())->method('getName')->will($this->returnValue('argumentName3'));
- $arguments = new Tx_Extbase_MVC_Controller_Arguments;
- $arguments[] = $mockArgument1;
- $arguments[] = $mockArgument2;
- $arguments[] = $mockArgument3;
-
- $expectedArgumentNames = array('argumentName1', 'argumentName2', 'argumentName3');
- $this->assertEquals($expectedArgumentNames, $arguments->getArgumentNames(), 'Returned argument names were not as expected.');
- }
-
- /**
- * @test
- */
- public function getArgumentShortNamesReturnsShortNamesOfAddedArguments() {
- $mockArgument1 = $this->getMock('Tx_Extbase_MVC_Controller_Argument', array('getName', 'getShortName'), array(), '', FALSE);
- $mockArgument1->expects($this->any())->method('getName')->will($this->returnValue('argumentName1'));
- $mockArgument1->expects($this->any())->method('getShortName')->will($this->returnValue('a'));
- $mockArgument2 = $this->getMock('Tx_Extbase_MVC_Controller_Argument', array('getName', 'getShortName'), array(), '', FALSE);
- $mockArgument2->expects($this->any())->method('getName')->will($this->returnValue('argumentName2'));
- $mockArgument2->expects($this->any())->method('getShortName')->will($this->returnValue('b'));
- $mockArgument3 = $this->getMock('Tx_Extbase_MVC_Controller_Argument', array('getName', 'getShortName'), array(), '', FALSE);
- $mockArgument3->expects($this->any())->method('getName')->will($this->returnValue('argumentName3'));
- $mockArgument3->expects($this->any())->method('getShortName')->will($this->returnValue('c'));
- $arguments = new Tx_Extbase_MVC_Controller_Arguments;
- $arguments[] = $mockArgument1;
- $arguments[] = $mockArgument2;
- $arguments[] = $mockArgument3;
-
- $expectedShortNames = array('a', 'b', 'c');
- $this->assertEquals($expectedShortNames, $arguments->getArgumentShortNames(), 'Returned argument short names were not as expected.');
- }
-
- /**
- * @test
- */
- public function addNewArgumentCreatesAndAddsNewArgument() {
- $mockArgument = $this->getMock('Tx_Extbase_MVC_Controller_Argument', array('getName'), array(), '', FALSE);
- $mockArgument->expects($this->any())->method('getName')->will($this->returnValue('dummyName'));
- $mockArguments = $this->getMock('Tx_Extbase_MVC_Controller_Arguments', array('createArgument'));
- $mockArguments->expects($this->any())->method('createArgument')->with($this->equalTo('dummyName'))->will($this->returnValue($mockArgument));
-
- $addedArgument = $mockArguments->addNewArgument('dummyName');
- $this->assertType('Tx_Extbase_MVC_Controller_Argument', $addedArgument, 'addNewArgument() either did not add a new argument or did not return it.');
-
- $retrievedArgument = $mockArguments['dummyName'];
- $this->assertSame($addedArgument, $retrievedArgument, 'The added and the retrieved argument are not the same.');
- }
-
- /**
- * @test
- */
- public function addNewArgumentAssumesTextDataTypeByDefault() {
- $mockArgument = $this->getMock('Tx_Extbase_MVC_Controller_Argument', array('getName'), array(), '', FALSE);
- $mockArgument->expects($this->any())->method('getName')->will($this->returnValue('dummyName'));
- $mockArguments = $this->getMock('Tx_Extbase_MVC_Controller_Arguments', array('createArgument'));
- $mockArguments->expects($this->any())->method('createArgument')->with($this->equalTo('dummyName'), $this->equalTo('Text'))->will($this->returnValue($mockArgument));
-
- $addedArgument = $mockArguments->addNewArgument('dummyName');
- }
-
- /**
- * @test
- */
- public function addNewArgumentCanAddArgumentsMarkedAsRequired() {
- $mockArgument = $this->getMock('Tx_Extbase_MVC_Controller_Argument', array('getName', 'setRequired'), array(), '', FALSE);
- $mockArgument->expects($this->any())->method('getName')->will($this->returnValue('dummyName'));
- $mockArgument->expects($this->any())->method('setRequired')->with(TRUE);
- $mockArguments = $this->getMock('Tx_Extbase_MVC_Controller_Arguments', array('createArgument'));
- $mockArguments->expects($this->any())->method('createArgument')->with($this->equalTo('dummyName'), $this->equalTo('Text'))->will($this->returnValue($mockArgument));
-
- $addedArgument = $mockArguments->addNewArgument('dummyName', 'Text', TRUE);
- }
-
- /**
- * @test
- */
- public function addNewArgumentCanAddArgumentsMarkedAsOptionalWithDefaultValues() {
- $mockArgument = $this->getMock('Tx_Extbase_MVC_Controller_Argument', array('getName', 'setRequired'), array(), '', FALSE);
- $mockArgument->expects($this->any())->method('getName')->will($this->returnValue('dummyName'));
- $mockArgument->expects($this->any())->method('setRequired')->with(TRUE);
- $mockArguments = $this->getMock('Tx_Extbase_MVC_Controller_Arguments', array('createArgument'));
- $mockArguments->expects($this->any())->method('createArgument')->with($this->equalTo('dummyName'), $this->equalTo('Text'))->will($this->returnValue($mockArgument));
-
- $addedArgument = $mockArguments->addNewArgument('dummyName', 'Text', TRUE);
- }
-
- /**
- * @test
- * @expectedException LogicException
- * @author Bastian Waidelich <bastian@typo3.org>
- */
- public function callingInvalidMethodThrowsException() {
- $arguments = $this->objectManager->get('Tx_Extbase_MVC_Controller_Arguments');
- $arguments->nonExistingMethod();
- }
-
- /**
- * @test
- * @author Christopher Hlubek <hlubek@networkteam.com>
- */
- public function removeAllClearsAllArguments() {
- $mockArgument1 = $this->getMock('Tx_Extbase_MVC_Controller_Argument', array('getName', 'getShortName'), array(), '', FALSE);
- $mockArgument1->expects($this->any())->method('getName')->will($this->returnValue('argumentName1'));
- $mockArgument2 = $this->getMock('Tx_Extbase_MVC_Controller_Argument', array('getName', 'getShortName'), array(), '', FALSE);
- $mockArgument2->expects($this->any())->method('getName')->will($this->returnValue('argumentName2'));
- $arguments = new Tx_Extbase_MVC_Controller_Arguments;
- $arguments[] = $mockArgument1;
- $arguments[] = $mockArgument2;
-
- $this->assertTrue($arguments->hasArgument('argumentName2'));
- $arguments->removeAll();
- $this->assertFalse($arguments->hasArgument('argumentName2'));
- }
-}
-?>
\ No newline at end of file
+++ /dev/null
-<?php
-/***************************************************************
-* Copyright notice
-*
-* (c) 2010 Jochen Rau <jochen.rau@typoplanet.de>
-* 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!
-***************************************************************/
-
-/**
- * Testcase for the MVC Dispatcher
- *
- * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License, version 3 or later
- */
-class Tx_Extbase_MVC_DispatcherTest extends Tx_Extbase_BaseTestCase {
-
- /**
- * @test
- */
- public function dispatchCallsTheControllersProcessRequestMethodUntilTheIsDispatchedFlagInTheRequestObjectIsSet() {
- $mockRequest = $this->getMock('Tx_Extbase_MVC_RequestInterface');
- $mockRequest->expects($this->at(0))->method('isDispatched')->will($this->returnValue(FALSE));
- $mockRequest->expects($this->at(1))->method('isDispatched')->will($this->returnValue(FALSE));
- $mockRequest->expects($this->at(2))->method('isDispatched')->will($this->returnValue(TRUE));
-
- $mockResponse = $this->getMock('Tx_Extbase_MVC_ResponseInterface');
-
- $mockController = $this->getMock('Tx_Extbase_MVC_Controller_ControllerInterface', array('processRequest', 'canProcessRequest'));
- $mockController->expects($this->exactly(2))->method('processRequest')->with($mockRequest, $mockResponse);
-
- $dispatcher = $this->getMock('Tx_Extbase_MVC_Dispatcher', array('resolveController'), array(), '', FALSE);
- $dispatcher->expects($this->any())->method('resolveController')->will($this->returnValue($mockController));
- $dispatcher->dispatch($mockRequest, $mockResponse);
- }
-
- /**
- * @test
- * @expectedException Tx_Extbase_MVC_Exception_InfiniteLoop
- */
- public function dispatchThrowsAnInfiniteLoopExceptionIfTheRequestCouldNotBeDispachedAfter99Iterations() {
- $requestCallCounter = 0;
- $requestCallBack = function() use (&$requestCallCounter) {
- return ($requestCallCounter++ < 101) ? FALSE : TRUE;
- };
- $mockRequest = $this->getMock('Tx_Extbase_MVC_RequestInterface');
- $mockRequest->expects($this->any())->method('isDispatched')->will($this->returnCallBack($requestCallBack, '__invoke'));
-
- $mockResponse = $this->getMock('Tx_Extbase_MVC_ResponseInterface');
- $mockController = $this->getMock('Tx_Extbase_MVC_Controller_ControllerInterface', array('processRequest', 'canProcessRequest'));
-
- $dispatcher = $this->getMock('Tx_Extbase_MVC_Dispatcher', array('resolveController'), array(), '', FALSE);
- $dispatcher->expects($this->any())->method('resolveController')->will($this->returnValue($mockController));
- $dispatcher->dispatch($mockRequest, $mockResponse);
- }
-
-}
-?>
\ No newline at end of file
+++ /dev/null
-<?php
-/***************************************************************
-* Copyright notice
-*
-* (c) 2009 Jochen Rau <jochen.rau@typoplanet.de>
-* All rights reserved
-*
-* This class is a backport of the corresponding class of FLOW3.
-* All credits go to the v5 team.
-*
-* 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!
-***************************************************************/
-
-class Tx_Extbase_MVC_Web_RequestBuilder_testcase extends Tx_Extbase_BaseTestCase {
-
- /**
- * @var array
- */
- protected $getBackup = array();
-
- /**
- * @var array
- */
- protected $postBackup = array();
-
- public function __construct() {
- require_once(t3lib_extMgm::extPath('extbase', 'Classes/MVC/Web/RequestBuilder.php'));
- }
-
- public function setUp() {
- $this->configuration = array(
- 'userFunc' => 'Tx_Extbase_Dispatcher->dispatch',
- 'pluginName' => 'Pi1',
- 'extensionName' => 'MyExtension',
- 'controller' => 'TheFirstController',
- 'action' => 'show',
- 'switchableControllerActions' => array(
- 'TheFirstController' => array(
- 'controller' => 'TheFirstController',
- 'actions' => 'show,index, ,new,create,delete,edit,update,setup,test'
- ),
- 'TheSecondController' => array(
- 'controller' => 'TheSecondController',
- 'actions' => 'show, index'
- ),
- 'TheThirdController' => array(
- 'controller' => 'TheThirdController',
- 'actions' => 'delete,create'
- )
- )
- );
- $this->builder = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_MVC_Web_RequestBuilder'), array('dummy'));
- $this->getBackup = $_GET;
- $this->postBackup = $_POST;
- }
-
- public function tearDown() {
- $_GET = $this->getBackup;
- $_POST = $this->postBackup;
- }
-
- /**
- * @test
- */
- public function buildReturnsAWebRequestObject() {
- $this->builder->initialize($this->configuration);
- $request = $this->builder->build();
- $this->assertEquals('Tx_Extbase_MVC_Web_Request', get_class($request));
- $this->assertEquals('Pi1', $request->getPluginName());
- $this->assertEquals('MyExtension', $request->getControllerExtensionName());
- $this->assertEquals('TheFirstController', $request->getControllerName());
- $this->assertEquals('show', $request->getControllerActionName());
- }
-
- /**
- * @test
- */
- public function buildWithoutConfigurationReturnsAWebRequestObjectWithDefaultSettings() {
- $request = $this->builder->build();
- $this->assertEquals('plugin', $request->getPluginName());
- $this->assertEquals('Extbase', $request->getControllerExtensionName());
- $this->assertEquals('Standard', $request->getControllerName());
- $this->assertEquals('index', $request->getControllerActionName());
- }
-
- /**
- * @test
- */
- public function buildWithMissingControllerConfigurationsReturnsAWebRequestObjectWithDefaultControllerSettings() {
- $configuration = $this->configuration;
- unset($configuration['controller']);
- unset($configuration['action']);
- unset($configuration['switchableControllerActions']);
- $this->builder->initialize($configuration);
- $request = $this->builder->build();
- $this->assertEquals('Pi1', $request->getPluginName());
- $this->assertEquals('MyExtension', $request->getControllerExtensionName());
- $this->assertEquals('Standard', $request->getControllerName());
- $this->assertEquals('index', $request->getControllerActionName());
- }
-
- /**
- * @test
- */
- public function buildWithMissingActionsReturnsAWebRequestObjectWithDefaultControllerSettings() {
- $configuration = $this->configuration;
- unset($configuration['action']);
- unset($configuration['switchableControllerActions']);
- $this->builder->initialize($configuration);
- $request = $this->builder->build();
- $this->assertEquals('Pi1', $request->getPluginName());
- $this->assertEquals('MyExtension', $request->getControllerExtensionName());
- $this->assertEquals('TheFirstController', $request->getControllerName());
- $this->assertEquals('index', $request->getControllerActionName());
- }
-
- /**
- * @test
- */
- public function buildSetsTheRequestURIInTheRequestObject() {
- $this->builder->initialize($this->configuration);
- $request = $this->builder->build();
- $this->assertEquals(t3lib_div::getIndpEnv('TYPO3_REQUEST_URL'), $request->getRequestURI());
- }
-
- /**
- * @test
- */
- public function buildSetsParametersFromGetAndPostVariables() {
- $this->builder->_set('extensionName', 'someExtensionName');
- $this->builder->_set('pluginName', 'somePluginName');
-
- $_GET = array(
- 'tx_someotherextensionname_somepluginname' => array(
- 'foo' => 'bar'
- ),
- 'tx_someextensionname_somepluginname' => array(
- 'parameter1' => 'valueGetsOverwritten',
- 'parameter2' => array(
- 'parameter3' => 'value3'
- )
- )
- );
- $_POST = array(
- 'tx_someextensionname_someotherpluginname' => array(
- 'foo' => 'bar'
- ),
- 'tx_someextensionname_somepluginname' => array(
- 'parameter1' => 'value1',
- 'parameter2' => array(
- 'parameter4' => 'value4'
- )
- )
- );
-
- $request = $this->builder->build();
- $expectedResult = array(
- 'parameter1' => 'value1',
- 'parameter2' => array(
- 'parameter3' => 'value3',
- 'parameter4' => 'value4',
- ),
- );
- $actualResult = $request->getArguments();
- $this->assertEquals($expectedResult, $actualResult);
- }
-
- /**
- * @test
- */
- public function initializeCorrectlySetsAllowedControllerActions() {
- $this->builder->initialize($this->configuration);
- $expectedResult = array(
- 'TheFirstController' => array(
- 'show', 'index', 'new', 'create', 'delete', 'edit', 'update', 'setup', 'test'
- ),
- 'TheSecondController' => array(
- 'show', 'index'
- ),
- 'TheThirdController' => array(
- 'delete', 'create'
- )
- );
- $actualResult = $this->builder->_get('allowedControllerActions');
- $this->assertEquals($expectedResult, $actualResult);
- }
-}
-?>
\ No newline at end of file
+++ /dev/null
-<?php
-/***************************************************************
-* Copyright notice
-*
-* (c) 2010 Sebastian Kurfuerst <sebastian@typo3.org>
-* All rights reserved
-*
-* This class is a backport of the corresponding class of FLOW3.
-* All credits go to the v5 team.
-*
-* 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!
-***************************************************************/
-
-class Tx_Extbase_MVC_Web_RequestTest extends Tx_Extbase_BaseTestCase {
- /**
- * @test
- */
- public function isCachedReturnsFalseByDefault() {
- $request = new Tx_Extbase_MVC_Web_Request();
- $this->assertFalse($request->isCached());
- }
-
- /**
- * @test
- */
- public function isCachedReturnsTheValueWhichWasPreviouslySet() {
- $request = new Tx_Extbase_MVC_Web_Request();
- $request->setIsCached(TRUE);
- $this->assertTrue($request->isCached());
- }
-}
-?>
\ No newline at end of file
+++ /dev/null
-<?php
-/***************************************************************
-* Copyright notice
-*
-* (c) 2009 Jochen Rau <jochen.rau@typoplanet.de>
-* All rights reserved
-*
-* This class is a backport of the corresponding class of FLOW3.
-* All credits go to the v5 team.
-*
-* 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!
-***************************************************************/
-
-require_once (t3lib_extMgm::extPath('extbase') . 'Tests/Fixtures/Entity.php');
-
-class Tx_Extbase_MVC_Web_Routing_UriBuilder_testcase extends Tx_Extbase_BaseTestCase {
-
- /**
- * @var tslib_fe
- */
- protected $tsfeBackup;
-
- /**
- * @var array
- */
- protected $getBackup;
-
- /**
- * @var tslib_cObj
- */
- protected $contentObject;
-
- /**
- * @var Tx_Extbase_MVC_Web_Request
- */
- protected $request;
-
- /**
- * @var Tx_Extbase_MVC_Web_Routing_UriBuilder
- */
- protected $uriBuilder;
-
- public function setUp() {
- $this->tsfeBackup = $GLOBALS['TSFE'];
- $GLOBALS['TSFE'] = $this->getMock('tslib_fe', array(), array(), '', FALSE);
-
- $this->getBackup = t3lib_div::_GET();
-
- $this->contentObject = $this->getMock('tslib_cObj');
- $this->request = $this->getMock('Tx_Extbase_MVC_Web_Request');
-
- $this->uriBuilder = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_MVC_Web_Routing_UriBuilder'), array('dummy'), array($this->contentObject));
- $this->uriBuilder->setRequest($this->request);
- }
-
- public function tearDown() {
- $GLOBALS['TSFE'] = $this->tsfeBackup;
- t3lib_div::_GETset($this->getBackup);
- }
-
- /**
- * @test
- */
- public function settersAndGettersWorkAsExpected() {
- $this->uriBuilder
- ->reset()
- ->setArguments(array('test' => 'arguments'))
- ->setSection('testSection')
- ->setFormat('testFormat')
- ->setCreateAbsoluteUri(TRUE)
- ->setAddQueryString(TRUE)
- ->setArgumentsToBeExcludedFromQueryString(array('test' => 'addQueryStringExcludeArguments'))
- ->setLinkAccessRestrictedPages(TRUE)
- ->setTargetPageUid(123)
- ->setTargetPageType(321)
- ->setNoCache(TRUE)
- ->setUseCacheHash(FALSE);
-
- $this->assertEquals(array('test' => 'arguments'), $this->uriBuilder->getArguments());
- $this->assertEquals('testSection', $this->uriBuilder->getSection());
- $this->assertEquals('testFormat', $this->uriBuilder->getFormat());
- $this->assertEquals(TRUE, $this->uriBuilder->getCreateAbsoluteUri());
- $this->assertEquals(TRUE, $this->uriBuilder->getAddQueryString());
- $this->assertEquals(array('test' => 'addQueryStringExcludeArguments'), $this->uriBuilder->getArgumentsToBeExcludedFromQueryString());
- $this->assertEquals(TRUE, $this->uriBuilder->getLinkAccessRestrictedPages());
- $this->assertEquals(123, $this->uriBuilder->getTargetPageUid());
- $this->assertEquals(321, $this->uriBuilder->getTargetPageType());
- $this->assertEquals(TRUE, $this->uriBuilder->getNoCache());
- $this->assertEquals(FALSE, $this->uriBuilder->getUseCacheHash());
- }
-
- /**
- * @test
- */
- public function uriForPrefixesArgumentsWithExtensionAndPluginNameAndSetsControllerArgument() {
- $expectedArguments = array('tx_someextension_someplugin' => array('foo' => 'bar', 'baz' => array('extbase' => 'fluid'), 'controller' => 'SomeController'));
-
- $this->uriBuilder->uriFor(NULL, array('foo' => 'bar', 'baz' => array('extbase' => 'fluid')), 'SomeController', 'SomeExtension', 'SomePlugin');
- $this->assertEquals($expectedArguments, $this->uriBuilder->getArguments());
- }
-
- /**
- * @test
- */
- public function uriForRecursivelyMergesAndOverrulesControllerArgumentsWithArguments() {
- $arguments = array('tx_someextension_someplugin' => array('foo' => 'bar'), 'additionalParam' => 'additionalValue');
- $controllerArguments = array('foo' => 'overruled', 'baz' => array('extbase' => 'fluid'));
- $expectedArguments = array('tx_someextension_someplugin' => array('foo' => 'overruled', 'baz' => array('extbase' => 'fluid'), 'controller' => 'SomeController'), 'additionalParam' => 'additionalValue');
-
- $this->uriBuilder->setArguments($arguments);
- $this->uriBuilder->uriFor(NULL, $controllerArguments, 'SomeController', 'SomeExtension', 'SomePlugin');
- $this->assertEquals($expectedArguments, $this->uriBuilder->getArguments());
- }
-
- /**
- * @test
- */
- public function uriForOnlySetsActionArgumentIfSpecified() {
- $expectedArguments = array('tx_someextension_someplugin' => array('controller' => 'SomeController'));
-
- $this->uriBuilder->uriFor(NULL, array(), 'SomeController', 'SomeExtension', 'SomePlugin');
- $this->assertEquals($expectedArguments, $this->uriBuilder->getArguments());
- }
-
- /**
- * @test
- */
- public function uriForSetsControllerFromRequestIfControllerIsNotSet() {
- $this->request->expects($this->once())->method('getControllerName')->will($this->returnValue('SomeControllerFromRequest'));
-
- $expectedArguments = array('tx_someextension_someplugin' => array('controller' => 'SomeControllerFromRequest'));
-
- $this->uriBuilder->uriFor(NULL, array(), NULL, 'SomeExtension', 'SomePlugin');
- $this->assertEquals($expectedArguments, $this->uriBuilder->getArguments());
- }
-
- /**
- * @test
- */
- public function uriForSetsExtensionNameFromRequestIfExtensionNameIsNotSet() {
- $this->request->expects($this->once())->method('getControllerExtensionName')->will($this->returnValue('SomeExtensionNameFromRequest'));
-
- $expectedArguments = array('tx_someextensionnamefromrequest_someplugin' => array('controller' => 'SomeController'));
-
- $this->uriBuilder->uriFor(NULL, array(), 'SomeController', NULL, 'SomePlugin');
- $this->assertEquals($expectedArguments, $this->uriBuilder->getArguments());
- }
-
- /**
- * @test
- */
- public function uriForSetsPluginNameFromRequestIfPluginNameIsNotSet() {
- $this->request->expects($this->once())->method('getPluginName')->will($this->returnValue('SomePluginNameFromRequest'));
-
- $expectedArguments = array('tx_someextension_somepluginnamefromrequest' => array('controller' => 'SomeController'));
-
- $this->uriBuilder->uriFor(NULL, array(), 'SomeController', 'SomeExtension');
- $this->assertEquals($expectedArguments, $this->uriBuilder->getArguments());
- }
-
- /**
- * @test
- */
- public function buildBackendUriKeepsQueryParametersIfAddQueryStringIsSet() {
- t3lib_div::_GETset(array('M' => 'moduleKey', 'id' => 'pageId', 'foo' => 'bar'));
-
- $this->uriBuilder->setAddQueryString(TRUE);
-
- $expectedResult = 'mod.php?M=moduleKey&id=pageId&foo=bar';
- $actualResult = $this->uriBuilder->buildBackendUri();
-
- $this->assertEquals($expectedResult, $actualResult);
- }
-
- /**
- * @test
- */
- public function buildBackendUriRemovesSpecifiedQueryParametersIfArgumentsToBeExcludedFromQueryStringIsSet() {
- t3lib_div::_GETset(array('M' => 'moduleKey', 'id' => 'pageId', 'foo' => 'bar'));
-
- $this->uriBuilder->setAddQueryString(TRUE);
- $this->uriBuilder->setArgumentsToBeExcludedFromQueryString(array('M', 'id'));
-
- $expectedResult = 'mod.php?foo=bar';
- $actualResult = $this->uriBuilder->buildBackendUri();
-
- $this->assertEquals($expectedResult, $actualResult);
- }
-
- /**
- * @test
- */
- public function buildBackendUriKeepsModuleQueryParametersIfAddQueryStringIsNotSet() {
- t3lib_div::_GETset(array('M' => 'moduleKey', 'id' => 'pageId', 'foo' => 'bar'));
-
- $expectedResult = 'mod.php?M=moduleKey&id=pageId';
- $actualResult = $this->uriBuilder->buildBackendUri();
-
- $this->assertEquals($expectedResult, $actualResult);
- }
-
- /**
- * @test
- */
- public function buildBackendUriMergesAndOverrulesQueryParametersWithArguments() {
- t3lib_div::_GETset(array('M' => 'moduleKey', 'id' => 'pageId', 'foo' => 'bar'));
-
- $this->uriBuilder->setArguments(array('M' => 'overwrittenModuleKey', 'somePrefix' => array('bar' => 'baz')));
-
- $expectedResult = 'mod.php?M=overwrittenModuleKey&id=pageId&somePrefix%5Bbar%5D=baz';
- $actualResult = $this->uriBuilder->buildBackendUri();
-
- $this->assertEquals($expectedResult, $actualResult);
- }
-
- /**
- * @test
- */
- public function buildBackendUriConvertsDomainObjectsAfterArgumentsHaveBeenMerged() {
- t3lib_div::_GETset(array('M' => 'moduleKey'));
-
- $mockDomainObject = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_DomainObject_AbstractEntity'), array('dummy'));
- $mockDomainObject->_set('uid', '123');
-
- $this->uriBuilder->setArguments(array('somePrefix' => array('someDomainObject' => $mockDomainObject)));
-
- $expectedResult = 'mod.php?M=moduleKey&somePrefix%5BsomeDomainObject%5D=123';
- $actualResult = $this->uriBuilder->buildBackendUri();
-
- $this->assertEquals($expectedResult, $actualResult);
- }
-
- /**
- * @test
- */
- public function buildBackendUriRespectsSection() {
- t3lib_div::_GETset(array('M' => 'moduleKey'));
-
- $this->uriBuilder->setSection('someSection');
-
- $expectedResult = 'mod.php?M=moduleKey#someSection';
- $actualResult = $this->uriBuilder->buildBackendUri();
-
- $this->assertEquals($expectedResult, $actualResult);
- }
-
- /**
- * @test
- */
- public function buildBackendUriCreatesAbsoluteUrisIfSpecified() {
- t3lib_div::_GETset(array('M' => 'moduleKey'));
-
- $this->request->expects($this->any())->method('getBaseURI')->will($this->returnValue('http://baseuri/' . TYPO3_mainDir));
- $this->uriBuilder->setCreateAbsoluteUri(TRUE);
-
- $expectedResult = 'http://baseuri/' . TYPO3_mainDir . 'mod.php?M=moduleKey';
- $actualResult = $this->uriBuilder->buildBackendUri();
- $this->assertSame($expectedResult, $actualResult);
- }
-
- /**
- * @test
- */
- public function buildFrontendUriCreatesTypoLink() {
- $uriBuilder = $this->getMock('Tx_Extbase_MVC_Web_Routing_UriBuilder', array('buildTypolinkConfiguration'), array($this->contentObject));
- $uriBuilder->expects($this->once())->method('buildTypolinkConfiguration')->will($this->returnValue(array('someTypoLinkConfiguration')));
-
- $this->contentObject->expects($this->once())->method('typoLink_URL')->with(array('someTypoLinkConfiguration'));
-
- $uriBuilder->buildFrontendUri();
- }
-
- /**
- * @test
- */
- public function buildFrontendUriCreatesRelativeUrisByDefault() {
- $this->contentObject->expects($this->once())->method('typoLink_URL')->will($this->returnValue('relative/uri'));
-
- $expectedResult = 'relative/uri';
- $actualResult = $this->uriBuilder->buildFrontendUri();
-
- $this->assertSame($expectedResult, $actualResult);
- }
-
- /**
- * @test
- */
- public function buildFrontendUriDoesNotStripLeadingSlashesFromRelativeUris() {
- $this->contentObject->expects($this->once())->method('typoLink_URL')->will($this->returnValue('/relative/uri'));
-
- $expectedResult = '/relative/uri';
- $actualResult = $this->uriBuilder->buildFrontendUri();
-
- $this->assertSame($expectedResult, $actualResult);
- }
-
- /**
- * @test
- */
- public function buildFrontendUriCreatesAbsoluteUrisIfSpecified() {
- $uriBuilder = $this->getMock('Tx_Extbase_MVC_Web_Routing_UriBuilder', array('buildTypolinkConfiguration'), array($this->contentObject));
- $uriBuilder->expects($this->once())->method('buildTypolinkConfiguration')->will($this->returnValue(array('foo' => 'bar')));
-
- $this->contentObject->expects($this->once())->method('typoLink_URL')->with(array('foo' => 'bar', 'forceAbsoluteUrl' => TRUE))->will($this->returnValue('http://baseuri/relative/uri'));
- $uriBuilder->setCreateAbsoluteUri(TRUE);
-
- $expectedResult = 'http://baseuri/relative/uri';
- $actualResult = $uriBuilder->buildFrontendUri();
- $this->assertSame($expectedResult, $actualResult);
- }
-
- /**
- * @test
- */
- public function resetSetsAllOptionsToTheirDefaultValue() {
- $this->uriBuilder
- ->setArguments(array('test' => 'arguments'))
- ->setSection('testSection')
- ->setFormat('someFormat')
- ->setCreateAbsoluteUri(TRUE)
- ->setAddQueryString(TRUE)
- ->setArgumentsToBeExcludedFromQueryString(array('test' => 'addQueryStringExcludeArguments'))
- ->setLinkAccessRestrictedPages(TRUE)
- ->setTargetPageUid(123)
- ->setTargetPageType(321)
- ->setNoCache(TRUE)
- ->setUseCacheHash(FALSE);
-
- $this->uriBuilder->reset();
-
- $this->assertEquals(array(), $this->uriBuilder->getArguments());
- $this->assertEquals('', $this->uriBuilder->getSection());
- $this->assertEquals('', $this->uriBuilder->getFormat());
- $this->assertEquals(FALSE, $this->uriBuilder->getCreateAbsoluteUri());
- $this->assertEquals(FALSE, $this->uriBuilder->getAddQueryString());
- $this->assertEquals(array(), $this->uriBuilder->getArgumentsToBeExcludedFromQueryString());
- $this->assertEquals(FALSE, $this->uriBuilder->getLinkAccessRestrictedPages());
- $this->assertEquals(NULL, $this->uriBuilder->getTargetPageUid());
- $this->assertEquals(0, $this->uriBuilder->getTargetPageType());
- $this->assertEquals(FALSE, $this->uriBuilder->getNoCache());
- $this->assertEquals(TRUE, $this->uriBuilder->getUseCacheHash());
- }
-
- /**
- * @test
- */
- public function buildTypolinkConfigurationRespectsSpecifiedTargetPageUid() {
- $GLOBALS['TSFE']->id = 123;
- $this->uriBuilder->setTargetPageUid(321);
-
- $expectedConfiguration = array('parameter' => 321, 'useCacheHash' => 1);
- $actualConfiguration = $this->uriBuilder->_call('buildTypolinkConfiguration');
-
- $this->assertEquals($expectedConfiguration, $actualConfiguration);
- }
-
- /**
- * @test
- */
- public function buildTypolinkConfigurationUsesCurrentPageUidIfTargetPageUidIsNotSet() {
- $GLOBALS['TSFE']->id = 123;
-
- $expectedConfiguration = array('parameter' => 123, 'useCacheHash' => 1);
- $actualConfiguration = $this->uriBuilder->_call('buildTypolinkConfiguration');
-
- $this->assertEquals($expectedConfiguration, $actualConfiguration);
- }
-
- /**
- * @test
- */
- public function buildTypolinkConfigurationProperlySetsAdditionalArguments() {
- $this->uriBuilder->setTargetPageUid(123);
- $this->uriBuilder->setArguments(array('foo' => 'bar', 'baz' => array('extbase' => 'fluid')));
-
- $expectedConfiguration = array('parameter' => 123, 'useCacheHash' => 1, 'additionalParams' => '&foo=bar&baz[extbase]=fluid');
- $actualConfiguration = $this->uriBuilder->_call('buildTypolinkConfiguration');
-
- $this->assertEquals($expectedConfiguration, $actualConfiguration);
- }
-
- /**
- * @test
- */
- public function buildTypolinkConfigurationConvertsDomainObjects() {
- $mockDomainObject1 = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_DomainObject_AbstractEntity'), array('dummy'));
- $mockDomainObject1->_set('uid', '123');
-
- $mockDomainObject2 = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_DomainObject_AbstractEntity'), array('dummy'));
- $mockDomainObject2->_set('uid', '321');
-
- $this->uriBuilder->setTargetPageUid(123);
- $this->uriBuilder->setArguments(array('someDomainObject' => $mockDomainObject1, 'baz' => array('someOtherDomainObject' => $mockDomainObject2)));
-
- $expectedConfiguration = array('parameter' => 123, 'useCacheHash' => 1, 'additionalParams' => '&someDomainObject=123&baz[someOtherDomainObject]=321');
- $actualConfiguration = $this->uriBuilder->_call('buildTypolinkConfiguration');
-
- $this->assertEquals($expectedConfiguration, $actualConfiguration);
- }
-
- /**
- * @test
- */
- public function buildTypolinkConfigurationConsidersPageType() {
- $this->uriBuilder->setTargetPageUid(123);
- $this->uriBuilder->setTargetPageType(2);
-
- $expectedConfiguration = array('parameter' => '123,2', 'useCacheHash' => 1);
- $actualConfiguration = $this->uriBuilder->_call('buildTypolinkConfiguration');
-
- $this->assertEquals($expectedConfiguration, $actualConfiguration);
- }
-
- /**
- * @test
- */
- public function buildTypolinkConfigurationDisablesCacheHashIfNoCacheIsSet() {
- $this->uriBuilder->setTargetPageUid(123);
- $this->uriBuilder->setNoCache(TRUE);
-
- $expectedConfiguration = array('parameter' => 123, 'no_cache' => 1);
- $actualConfiguration = $this->uriBuilder->_call('buildTypolinkConfiguration');
-
- $this->assertEquals($expectedConfiguration, $actualConfiguration);
- }
-
- /**
- * @test
- */
- public function buildTypolinkConfigurationDoesNotSetUseCacheHashOptionIfUseCacheHashIsDisabled() {
- $this->uriBuilder->setTargetPageUid(123);
- $this->uriBuilder->setUseCacheHash(FALSE);
-
- $expectedConfiguration = array('parameter' => 123);
- $actualConfiguration = $this->uriBuilder->_call('buildTypolinkConfiguration');
-
- $this->assertEquals($expectedConfiguration, $actualConfiguration);
- }
-
- /**
- * @test
- */
- public function buildTypolinkConfigurationConsidersSection() {
- $this->uriBuilder->setTargetPageUid(123);
- $this->uriBuilder->setSection('SomeSection');
-
- $expectedConfiguration = array('parameter' => 123, 'useCacheHash' => 1, 'section' => 'SomeSection');
- $actualConfiguration = $this->uriBuilder->_call('buildTypolinkConfiguration');
-
- $this->assertEquals($expectedConfiguration, $actualConfiguration);
- }
-
- /**
- * @test
- */
- public function buildTypolinkConfigurationLinkAccessRestrictedPagesSetting() {
- $this->uriBuilder->setTargetPageUid(123);
- $this->uriBuilder->setLinkAccessRestrictedPages(TRUE);
-
- $expectedConfiguration = array('parameter' => 123, 'useCacheHash' => 1, 'linkAccessRestrictedPages' => 1);
- $actualConfiguration = $this->uriBuilder->_call('buildTypolinkConfiguration');
-
- $this->assertEquals($expectedConfiguration, $actualConfiguration);
- }
-
- /**
- * @test
- */
- public function convertDomainObjectsToIdentityArraysConvertsDomainObjects() {
- $mockDomainObject1 = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_DomainObject_AbstractEntity'), array('dummy'));
- $mockDomainObject1->_set('uid', '123');
-
- $mockDomainObject2 = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_DomainObject_AbstractEntity'), array('dummy'));
- $mockDomainObject2->_set('uid', '321');
-
- $expectedResult = array('foo' => array('bar' => 'baz'), 'domainObject1' => '123', 'second' => array('domainObject2' =>'321'));
- $actualResult = $this->uriBuilder->_call('convertDomainObjectsToIdentityArrays', array('foo' => array('bar' => 'baz'), 'domainObject1' => $mockDomainObject1, 'second' => array('domainObject2' => $mockDomainObject2)));
-
- $this->assertEquals($expectedResult, $actualResult);
- }
-
- /**
- * @test
- */
- public function conversionOfTansientObjectsIsInvoked() {
- $className = uniqid('Tx_Extbase_Tests_Fixtures_Object');
- eval('class ' . $className . ' extends Tx_Extbase_DomainObject_AbstractValueObject { public $name; public $uid; }');
- $mockValueObject = new $className;
- $mockValueObject->name = 'foo';
-
- $mockUriBuilder = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_MVC_Web_Routing_UriBuilder'), array('convertTransientObjectToArray'));
- $mockUriBuilder->expects($this->once())->method('convertTransientObjectToArray')->will($this->returnValue(array('foo' => 'bar')));
- $actualResult = $mockUriBuilder->_call('convertDomainObjectsToIdentityArrays', array('object' => $mockValueObject));
-
- $expectedResult = array('object' => array('foo' => 'bar'));
- $this->assertEquals($expectedResult, $actualResult);
- }
-
- /**
- * @test
- * @expectedException Tx_Extbase_MVC_Exception_InvalidArgumentValue
- */
- public function conversionOfTansientObjectsThrowsExceptionForOtherThanValueObjects() {
- $className = uniqid('Tx_Extbase_Tests_Fixtures_Object');
- eval('class ' . $className . ' extends Tx_Extbase_DomainObject_AbstractEntity { public $name; public $uid; }');
- $mockEntity = new $className;
- $mockEntity->name = 'foo';
-
- $mockUriBuilder = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_MVC_Web_Routing_UriBuilder'), array('dummy'));
- $actualResult = $mockUriBuilder->_call('convertDomainObjectsToIdentityArrays', array('object' => $mockEntity));
- }
-
- /**
- * @test
- */
- public function tansientObjectsAreConvertedToAnArrayOfProperties() {
- $className = uniqid('Tx_Extbase_Tests_Fixtures_Object');
- eval('class ' . $className . ' extends Tx_Extbase_DomainObject_AbstractValueObject { public $name; public $uid; }');
- $mockValueObject = new $className;
- $mockValueObject->name = 'foo';
-
- $mockUriBuilder = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_MVC_Web_Routing_UriBuilder'), array('dummy'));
- $actualResult = $mockUriBuilder->_call('convertTransientObjectToArray', $mockValueObject);
-
- $expectedResult = array('name' => 'foo', 'uid' => NULL);
- $this->assertEquals($expectedResult, $actualResult);
- }
-
- /**
- * @test
- */
- public function tansientObjectsAreRecursivelyConverted() {
- $className = uniqid('Tx_Extbase_Tests_Fixtures_Object');
- eval('class ' . $className . ' extends Tx_Extbase_DomainObject_AbstractValueObject { public $name; public $uid; }');
- $mockInnerValueObject2 = new $className;
- $mockInnerValueObject2->name = 'foo';
- $mockInnerValueObject2->uid = 99;
-
- $className = uniqid('Tx_Extbase_Tests_Fixtures_Object');
- eval('class ' . $className . ' extends Tx_Extbase_DomainObject_AbstractValueObject { public $object; public $uid; }');
- $mockInnerValueObject1 = new $className;
- $mockInnerValueObject1->object = $mockInnerValueObject2;
-
- $className = uniqid('Tx_Extbase_Tests_Fixtures_Object');
- eval('class ' . $className . ' extends Tx_Extbase_DomainObject_AbstractValueObject { public $object; public $uid; }');
- $mockValueObject = new $className;
- $mockValueObject->object = $mockInnerValueObject1;
-
- $mockUriBuilder = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_MVC_Web_Routing_UriBuilder'), array('dummy'));
- $actualResult = $mockUriBuilder->_call('convertTransientObjectToArray', $mockValueObject);
-
- $expectedResult = array(
- 'object' => array(
- 'object' => 99,
- 'uid' => NULL),
- 'uid' => NULL);
- $this->assertEquals($expectedResult, $actualResult);
- }
-
-
-}
-?>
\ No newline at end of file
+++ /dev/null
-<?php
-/***************************************************************
-* Copyright notice
-* (c) 2010 Daniel Pötzinger
-* (c) 2010 Bastian Waidelich <bastian@typo3.org>
-* 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!
-***************************************************************/
-
-require_once(t3lib_extMgm::extPath('extbase') . 'Tests/Object/Container/Fixtures/Testclasses.php');
-
-/**
- * Testcase for class t3lib_object_ClassInfoFactory.
- *
- * @author Daniel Pötzinger
- * @author Bastian Waidelich <bastian@typo3.org>
- * @package TYPO3
- * @subpackage t3lib
- */
-class Tx_Extbase_Object_Container_ClassInfoFactoryTest extends tx_phpunit_testcase {
-
- /**
- * @var t3lib_object_ClassInfoFactory
- */
- private $classInfoFactory;
-
- /**
- *
- */
- public function setUp() {
- $this->classInfoFactory = new Tx_Extbase_Object_Container_ClassInfoFactory();
- }
-}
-?>
\ No newline at end of file
+++ /dev/null
-<?php
-/***************************************************************
-* Copyright notice
-* (c) 2010 Daniel Pötzinger
-* (c) 2010 Bastian Waidelich <bastian@typo3.org>
-* 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!
-***************************************************************/
-
-require_once(t3lib_extMgm::extPath('extbase') . 'Tests/Object/Container/Fixtures/Testclasses.php');
-
-/**
- * Testcase for class t3lib_object_Container.
- *
- * @author Daniel Pötzinger
- * @author Bastian Waidelich <bastian@typo3.org>
- * @package TYPO3
- * @subpackage t3lib
- */
-class Tx_Extbase_Object_Container_ContainerTest extends tx_phpunit_testcase {
-
- private $container;
-
- public function setUp() {
- $this->container = Tx_Extbase_Object_Container_Container::getContainer();
-
- }
-
- /**
- * @test
- */
- public function getInstanceReturnsInstanceOfSimpleClass() {
- $object = $this->container->getInstance('t3lib_object_tests_c');
- $this->assertType('t3lib_object_tests_c', $object);
- }
-
- /**
- * @test
- */
- public function getInstanceReturnsInstanceOfAClassWithDependency() {
- $object = $this->container->getInstance('t3lib_object_tests_b');
- $this->assertType('t3lib_object_tests_b', $object);
- }
-
- /**
- * @test
- */
- public function getInstanceReturnsInstanceOfAClassWithTwoLevelDependency() {
- $object = $this->container->getInstance('t3lib_object_tests_a');
- $this->assertType('t3lib_object_tests_a', $object);
- }
-
- /**
- * @test
- */
- public function getInstanceReturnsInstanceOfAClassWithTwoLevelMixedArrayDependency() {
- $object = $this->container->getInstance('t3lib_object_tests_amixed_array');
- $this->assertType('t3lib_object_tests_amixed_array', $object);
- }
-
- /**
- * @test
- */
- public function getInstanceReturnsInstanceOfAClassWithTwoLevelMixedStringDependency() {
- $object = $this->container->getInstance('t3lib_object_tests_amixed_string');
- $this->assertType('t3lib_object_tests_amixed_string', $object);
- }
-
- /**
- * @test
- */
- public function getInstancePassesGivenParameterToTheNewObject() {
- $mockObject = $this->getMock('t3lib_object_tests_c');
-
- $object = $this->container->getInstance('t3lib_object_tests_a', $mockObject);
- $this->assertType('t3lib_object_tests_a', $object);
- $this->assertSame($mockObject, $object->c);
- }
-
- /**
- * @test
- */
- public function getInstanceReturnsAFreshInstanceIfObjectIsNoSingleton() {
- $object1 = $this->container->getInstance('t3lib_object_tests_a');
- $object2 = $this->container->getInstance('t3lib_object_tests_a');
-
- $this->assertNotSame($object1, $object2);
- }
-
- /**
- * @test
- */
- public function getInstanceReturnsSameInstanceInstanceIfObjectIsSingleton() {
- $object1 = $this->container->getInstance('t3lib_object_tests_singleton');
- $object2 = $this->container->getInstance('t3lib_object_tests_singleton');
-
- $this->assertSame($object1, $object2);
- }
-
- /**
- * @test
- * @expectedException Exception
- */
- public function getInstanceThrowsExceptionIfObjectContainsCyclicDependency() {
- $this->container->getInstance('t3lib_object_tests_cyclic1');
-
- }
-
- /**
- * @test
- * @expectedException Exception
- */
- public function getInstanceThrowsExceptionIfClassWasNotFound() {
- $this->container->getInstance('nonextistingclass_bla');
-
- }
-
- /**
- * @test
- */
- public function test_canGetChildClass() {
- $object = $this->container->getInstance('t3lib_object_tests_b_child');
- $this->assertType('t3lib_object_tests_b_child', $object);
- }
-
- /**
- * @test
- */
- public function test_canInjectInterfaceInClass() {
- $this->container->registerImplementation('t3lib_object_tests_someinterface', 't3lib_object_tests_someimplementation');
- $object = $this->container->getInstance('t3lib_object_tests_needsinterface');
- $this->assertType('t3lib_object_tests_needsinterface', $object);
- }
-
- /**
- * @test
- */
- public function test_canBuildCyclicDependenciesWithSetter() {
- $object = $this->container->getInstance('t3lib_object_tests_resolveablecyclic1');
- $this->assertType('t3lib_object_tests_resolveablecyclic1', $object);
- $this->assertType('t3lib_object_tests_resolveablecyclic1', $object->o->o);
- }
-
-
-
-}
-
-
-?>
+++ /dev/null
-<?php
-
-/**
- * a singleton class
- *
- */
-class t3lib_object_tests_singleton implements t3lib_Singleton {
-
-}
-
-/**
- * test class A that depends on B and C
- *
- */
-class t3lib_object_tests_a {
- public $b;
- public $c;
-
- public function __construct( t3lib_object_tests_c $c, t3lib_object_tests_b $b) {
- $this->b = $b;
- $this->c = $c;
- }
-}
-/**
- * test class A that depends on B and C and has a third default parameter in constructor
- *
- */
-class t3lib_object_tests_amixed_array implements t3lib_Singleton {
- public function __construct(t3lib_object_tests_b $b, t3lib_object_tests_c $c, array $myvalue=array()) {
-
- }
-}
-/**
- * test class A that depends on B and C and has a third default parameter in constructor
- *
- */
-class t3lib_object_tests_amixed_string implements t3lib_Singleton {
- public function __construct(t3lib_object_tests_b $b, t3lib_object_tests_c $c, $myvalue='test') {
-
- }
-}
-/**
- * test class B that depends on C
- *
- */
-class t3lib_object_tests_b implements t3lib_Singleton {
- public function __construct(t3lib_object_tests_c $c) {
-
- }
-}
-
-
-/**
- * test class C without dependencys
- *
- */
-class t3lib_object_tests_c implements t3lib_Singleton {
-
-}
-
-/**
- * test class B-Child that extends Class B (therfore depends also on Class C)
- *
- */
-class t3lib_object_tests_b_child extends t3lib_object_tests_b {
-}
-
-interface t3lib_object_tests_someinterface {
-
-}
-
-/**
- * class which implements a Interface
- *
- */
-class t3lib_object_tests_someimplementation implements t3lib_object_tests_someinterface, t3lib_Singleton {
-}
-
-/**
- * test class B-Child that extends Class B (therfore depends also on Class C)
- *
- */
-class t3lib_object_tests_b_child_someimplementation extends t3lib_object_tests_b implements t3lib_object_tests_someinterface {
-}
-
-/**
- * class which depends on a Interface
- *
- */
-class t3lib_object_tests_needsinterface {
- public function __construct(t3lib_object_tests_someinterface $i) {
-
- }
-}
-
-/**
- * classes that depends on each other (death look)
- *
- */
-class t3lib_object_tests_cyclic1 {
- public function __construct(t3lib_object_tests_cyclic2 $c) {
-
- }
-}
-
-class t3lib_object_tests_cyclic2 {
- public function __construct(t3lib_object_tests_cyclic1 $c) {
-
- }
-}
-
-/**
- * class which has setter injections defined
- *
- */
-class t3lib_object_tests_injectmethods {
- public $b;
- public $bchild;
-
- public function injectClassB(t3lib_object_tests_b $o) {
- $this->b = $o;
- }
-
- /**
- * @inject
- * @param t3lib_object_tests_b $o
- */
- public function setClassBChild(t3lib_object_tests_b_child $o) {
- $this->bchild = $o;
- }
-}
-
-/**
- * class which needs extenson settings injected
- *
- */
-class t3lib_object_tests_injectsettings {
- public $settings;
- public function injectExtensionSettings(array $settings) {
- $this->settings = $settings;
- }
-}
-
-/**
- *
- *
- */
-class t3lib_object_tests_resolveablecyclic1 implements t3lib_Singleton {
- public $o;
- public function __construct(t3lib_object_tests_resolveablecyclic2 $cyclic2) {
- $this->o = $cyclic2;
- }
-}
-
-/**
- *
- *
- */
-class t3lib_object_tests_resolveablecyclic2 implements t3lib_Singleton {
- public $o;
- public function injectCyclic1(t3lib_object_tests_resolveablecyclic1 $o) {
- $this->o = $o;
- }
-}
-
-
+++ /dev/null
-<?php
-/***************************************************************
-* Copyright notice
-*
-* (c) 2009 Jochen Rau <jochen.rau@typoplanet.de>
-* All rights reserved
-*
-* This class is a backport of the corresponding class of FLOW3.
-* All credits go to the v5 team.
-*
-* 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!
-***************************************************************/
-
-require_once(PATH_tslib . 'class.tslib_content.php');
-
-class Tx_Extbase_Persistence_Mapper_DataMapFactory_testcase extends Tx_Extbase_BaseTestCase {
-
- /**
- * @test
- */
- public function setRelationsDetectsOneToOneRelation() {
- $mockColumnMap = $this->getMock('Tx_Extbase_Persistence_Mapper_ColumnMap', array(), array(), '', FALSE);
- $columnConfiguration = array(
- 'type' => 'select',
- 'foreign_table' => 'tx_myextension_bar',
- 'foreign_field' => 'parentid',
- );
- $propertyMetaData = array(
- 'type' => 'Tx_Myext_Domain_Model_Foo',
- 'elementType' => NULL
- );
- $mockDataMapFactory = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_Persistence_Mapper_DataMapFactory'), array('setOneToOneRelation', 'setOneToManyRelation', 'setManyToManyRelation'), array(), '', FALSE);
- $mockDataMapFactory->expects($this->once())->method('setOneToOneRelation');
- $mockDataMapFactory->expects($this->never())->method('setOneToManyRelation');
- $mockDataMapFactory->expects($this->never())->method('setManyToManyRelation');
- $mockDataMapFactory->_callRef('setRelations', $mockColumnMap, $columnConfiguration, $propertyMetaData);
- }
-
- /**
- * @test
- */
- public function setRelationsDetectsOneToOneRelationWithIntermediateTable() {
- $mockColumnMap = $this->getMock('Tx_Extbase_Persistence_Mapper_ColumnMap', array(), array(), '', FALSE);
- $columnConfiguration = array(
- 'type' => 'select',
- 'foreign_table' => 'tx_myextension_bar',
- 'MM' => 'tx_myextension_mm'
- );
- $propertyMetaData = array(
- 'type' => 'Tx_Myext_Domain_Model_Foo',
- 'elementType' => NULL
- );
- $mockDataMapFactory = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_Persistence_Mapper_DataMapFactory'), array('setOneToOneRelation', 'setOneToManyRelation', 'setManyToManyRelation'), array(), '', FALSE);
- $mockDataMapFactory->expects($this->never())->method('setOneToOneRelation');
- $mockDataMapFactory->expects($this->never())->method('setOneToManyRelation');
- $mockDataMapFactory->expects($this->once())->method('setManyToManyRelation');
- $mockDataMapFactory->_callRef('setRelations', $mockColumnMap, $columnConfiguration, $propertyMetaData);
- }
-
- /**
- * @test
- */
- public function setRelationsDetectsOneToManyRelation() {
- $mockColumnMap = $this->getMock('Tx_Extbase_Persistence_Mapper_ColumnMap', array(), array(), '', FALSE);
- $columnConfiguration = array(
- 'type' => 'select',
- 'foreign_table' => 'tx_myextension_bar',
- 'foreign_field' => 'parentid',
- 'foreign_table_field' => 'parenttable',
- );
- $propertyMetaData = array(
- 'type' => 'Tx_Extbase_Persistence_ObjectStorage',
- 'elementType' => 'Tx_Myext_Domain_Model_Foo'
- );
- $mockDataMapFactory = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_Persistence_Mapper_DataMapFactory'), array('setOneToOneRelation', 'setOneToManyRelation', 'setManyToManyRelation'), array(), '', FALSE);
- $mockDataMapFactory->expects($this->never())->method('setOneToOneRelation');
- $mockDataMapFactory->expects($this->once())->method('setOneToManyRelation');
- $mockDataMapFactory->expects($this->never())->method('setManyToManyRelation');
- $mockDataMapFactory->_callRef('setRelations', $mockColumnMap, $columnConfiguration, $propertyMetaData);
- }
-
- /**
- * @test
- */
- public function setRelationsDetectsManyToManyRelationOfTypeSelect() {
- $mockColumnMap = $this->getMock('Tx_Extbase_Persistence_Mapper_ColumnMap', array(), array(), '', FALSE);
- $columnConfiguration = array(
- 'type' => 'select',
- 'foreign_table' => 'tx_myextension_bar',
- 'MM' => 'tx_myextension_mm'
- );
- $propertyMetaData = array(
- 'type' => 'Tx_Extbase_Persistence_ObjectStorage',
- 'elementType' => 'Tx_Myext_Domain_Model_Foo'
- );
- $mockDataMapFactory = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_Persistence_Mapper_DataMapFactory'), array('setOneToOneRelation', 'setOneToManyRelation', 'setManyToManyRelation'), array(), '', FALSE);
- $mockDataMapFactory->expects($this->never())->method('setOneToOneRelation');
- $mockDataMapFactory->expects($this->never())->method('setOneToManyRelation');
- $mockDataMapFactory->expects($this->once())->method('setManyToManyRelation');
- $mockDataMapFactory->_callRef('setRelations', $mockColumnMap, $columnConfiguration, $propertyMetaData);
- }
-
- /**
- * @test
- */
- public function setRelationsDetectsManyToManyRelationOfTypeInlineWithIntermediateTable() {
- $mockColumnMap = $this->getMock('Tx_Extbase_Persistence_Mapper_ColumnMap', array(), array(), '', FALSE);
- $columnConfiguration = array(
- 'type' => 'inline',
- 'foreign_table' => 'tx_myextension_righttable',
- 'MM' => 'tx_myextension_mm'
- );
- $propertyMetaData = array(
- 'type' => 'Tx_Extbase_Persistence_ObjectStorage',
- 'elementType' => 'Tx_Myext_Domain_Model_Foo'
- );
- $mockDataMapFactory = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_Persistence_Mapper_DataMapFactory'), array('setOneToOneRelation', 'setOneToManyRelation', 'setManyToManyRelation'), array(), '', FALSE);
- $mockDataMapFactory->expects($this->never())->method('setOneToOneRelation');
- $mockDataMapFactory->expects($this->never())->method('setOneToManyRelation');
- $mockDataMapFactory->expects($this->once())->method('setManyToManyRelation');
- $mockDataMapFactory->_callRef('setRelations', $mockColumnMap, $columnConfiguration, $propertyMetaData);
- }
-
- /**
- * @test
- */
- public function setRelationsDetectsManyToManyRelationOfTypeInlineWithForeignSelector() {
- $mockColumnMap = $this->getMock('Tx_Extbase_Persistence_Mapper_ColumnMap', array(), array(), '', FALSE);
- $columnConfiguration = array(
- 'type' => 'inline',
- 'foreign_table' => 'tx_myextension_mm',
- 'foreign_field' => 'uid_local',
- 'foreign_selector' => 'uid_foreign'
- );
- $propertyMetaData = array(
- 'type' => 'Tx_Extbase_Persistence_ObjectStorage',
- 'elementType' => 'Tx_Myext_Domain_Model_Foo'
- );
- $mockDataMapFactory = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_Persistence_Mapper_DataMapFactory'), array('setOneToOneRelation', 'setOneToManyRelation', 'setManyToManyRelation'), array(), '', FALSE);
- $mockDataMapFactory->expects($this->never())->method('setOneToOneRelation');
- $mockDataMapFactory->expects($this->never())->method('setOneToManyRelation');
- $mockDataMapFactory->expects($this->once())->method('setManyToManyRelation');
- $mockDataMapFactory->_callRef('setRelations', $mockColumnMap, $columnConfiguration, $propertyMetaData);
- }
-
- /**
- * @test
- */
- public function columnMapIsInitializedWithManyToManyRelationOfTypeSelect() {
- $leftColumnsDefinition = array(
- 'rights' => array(
- 'type' => 'select',
- 'foreign_table' => 'tx_myextension_righttable',
- 'foreign_table_where' => 'WHERE 1=1',
- 'MM' => 'tx_myextension_mm',
- 'MM_table_where' => 'WHERE 2=2',
- ),
- );
- $mockColumnMap = $this->getMock('Tx_Extbase_Persistence_Mapper_ColumnMap', array(), array(), '', FALSE);
- $mockColumnMap->expects($this->once())->method('setTypeOfRelation')->with($this->equalTo(Tx_Extbase_Persistence_Mapper_ColumnMap::RELATION_HAS_AND_BELONGS_TO_MANY));
- $mockColumnMap->expects($this->once())->method('setRelationTableName')->with($this->equalTo('tx_myextension_mm'));
- $mockColumnMap->expects($this->once())->method('setChildTableName')->with($this->equalTo('tx_myextension_righttable'));
- $mockColumnMap->expects($this->once())->method('setChildTableWhereStatement')->with($this->equalTo('WHERE 1=1'));
- $mockColumnMap->expects($this->once())->method('setChildSortbyFieldName')->with($this->equalTo('sorting'));
- $mockColumnMap->expects($this->once())->method('setParentKeyFieldName')->with($this->equalTo('uid_local'));
- $mockColumnMap->expects($this->never())->method('setParentTableFieldName');
- $mockColumnMap->expects($this->never())->method('setRelationTableMatchFields');
- $mockColumnMap->expects($this->never())->method('setRelationTableInsertFields');
-
- $mockDataMapFactory = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_Persistence_Mapper_DataMapFactory'), array('dummy'), array(), '', FALSE);
- $mockDataMapFactory->_callRef('setManyToManyRelation', $mockColumnMap, $leftColumnsDefinition['rights']);
- }
-
- /**
- * @test
- */
- public function columnMapIsInitializedWithOppositeManyToManyRelationOfTypeSelect() {
- $rightColumnsDefinition = array(
- 'lefts' => array(
- 'type' => 'select',
- 'foreign_table' => 'tx_myextension_lefttable',
- 'MM' => 'tx_myextension_mm',
- 'MM_opposite_field' => 'rights'
- ),
- );
- $leftColumnsDefinition['rights']['MM_opposite_field'] = 'opposite_field';
- $mockColumnMap = $this->getMock('Tx_Extbase_Persistence_Mapper_ColumnMap', array(), array(), '', FALSE);
- $mockColumnMap->expects($this->once())->method('setTypeOfRelation')->with($this->equalTo(Tx_Extbase_Persistence_Mapper_ColumnMap::RELATION_HAS_AND_BELONGS_TO_MANY));
- $mockColumnMap->expects($this->once())->method('setRelationTableName')->with($this->equalTo('tx_myextension_mm'));
- $mockColumnMap->expects($this->once())->method('setChildTableName')->with($this->equalTo('tx_myextension_lefttable'));
- $mockColumnMap->expects($this->once())->method('setChildTableWhereStatement')->with(NULL);
- $mockColumnMap->expects($this->once())->method('setChildSortbyFieldName')->with($this->equalTo('sorting_foreign'));
- $mockColumnMap->expects($this->once())->method('setParentKeyFieldName')->with($this->equalTo('uid_foreign'));
- $mockColumnMap->expects($this->never())->method('setParentTableFieldName');
- $mockColumnMap->expects($this->never())->method('setRelationTableMatchFields');
- $mockColumnMap->expects($this->never())->method('setRelationTableInsertFields');
-
- $mockDataMapFactory = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_Persistence_Mapper_DataMapFactory'), array('dummy'), array(), '', FALSE);
- $mockDataMapFactory->_callRef('setManyToManyRelation', $mockColumnMap, $rightColumnsDefinition['lefts']);
- }
-
- /**
- * @test
- */
- public function columnMapIsInitializedWithManyToManyRelationOfTypeInlineAndIntermediateTable() {
- $leftColumnsDefinition = array(
- 'rights' => array(
- 'type' => 'inline',
- 'foreign_table' => 'tx_myextension_righttable',
- 'MM' => 'tx_myextension_mm',
- 'foreign_sortby' => 'sorting'
- )
- );
- $mockColumnMap = $this->getMock('Tx_Extbase_Persistence_Mapper_ColumnMap', array(), array(), '', FALSE);
- $mockColumnMap->expects($this->once())->method('setTypeOfRelation')->with($this->equalTo(Tx_Extbase_Persistence_Mapper_ColumnMap::RELATION_HAS_AND_BELONGS_TO_MANY));
- $mockColumnMap->expects($this->once())->method('setRelationTableName')->with($this->equalTo('tx_myextension_mm'));
- $mockColumnMap->expects($this->once())->method('setChildTableName')->with($this->equalTo('tx_myextension_righttable'));
- $mockColumnMap->expects($this->once())->method('setChildTableWhereStatement');
- $mockColumnMap->expects($this->once())->method('setChildSortbyFieldName')->with($this->equalTo('sorting'));
- $mockColumnMap->expects($this->once())->method('setParentKeyFieldName')->with($this->equalTo('uid_local'));
- $mockColumnMap->expects($this->never())->method('setParentTableFieldName');
- $mockColumnMap->expects($this->never())->method('setRelationTableMatchFields');
- $mockColumnMap->expects($this->never())->method('setRelationTableInsertFields');
-
- $mockDataMapFactory = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_Persistence_Mapper_DataMapFactory'), array('getColumnsDefinition'), array(), '', FALSE);
- $mockDataMapFactory->expects($this->never())->method('getColumnsDefinition');
- $mockDataMapFactory->_callRef('setManyToManyRelation', $mockColumnMap, $leftColumnsDefinition['rights']);
- }
-
- /**
- * @test
- */
- public function columnMapIsInitializedWithManyToManyRelationOfTypeInlineAndForeignSelector() {
- $leftColumnsDefinition = array(
- 'rights' => array(
- 'type' => 'inline',
- 'foreign_table' => 'tx_myextension_mm',
- 'foreign_field' => 'uid_local',
- 'foreign_selector' => 'uid_foreign',
- 'foreign_sortby' => 'sorting'
- )
- );
- $relationTableColumnsDefiniton = array(
- 'uid_local' => array(
- 'config' => array('foreign_table' => 'tx_myextension_localtable')
- ),
- 'uid_foreign' => array(
- 'config' => array('foreign_table' => 'tx_myextension_righttable')
- )
- );
- $rightColumnsDefinition = array(
- 'lefts' => array(
- 'type' => 'inline',
- 'foreign_table' => 'tx_myextension_mm',
- 'foreign_field' => 'uid_foreign',
- 'foreign_selector' => 'uid_local',
- 'foreign_sortby' => 'sorting_foreign'
- )
- );
- $mockColumnMap = $this->getMock('Tx_Extbase_Persistence_Mapper_ColumnMap', array(), array(), '', FALSE);
- $mockColumnMap->expects($this->once())->method('setTypeOfRelation')->with($this->equalTo(Tx_Extbase_Persistence_Mapper_ColumnMap::RELATION_HAS_AND_BELONGS_TO_MANY));
- $mockColumnMap->expects($this->once())->method('setRelationTableName')->with($this->equalTo('tx_myextension_mm'));
- $mockColumnMap->expects($this->once())->method('setChildTableName')->with($this->equalTo('tx_myextension_righttable'));
- $mockColumnMap->expects($this->never())->method('setChildTableWhereStatement');
- $mockColumnMap->expects($this->once())->method('setChildSortbyFieldName')->with($this->equalTo('sorting'));
- $mockColumnMap->expects($this->once())->method('setParentKeyFieldName')->with($this->equalTo('uid_local'));
- $mockColumnMap->expects($this->never())->method('setParentTableFieldName');
- $mockColumnMap->expects($this->never())->method('setRelationTableMatchFields');
- $mockColumnMap->expects($this->never())->method('setRelationTableInsertFields');
-
- $mockDataMapFactory = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_Persistence_Mapper_DataMapFactory'), array('getColumnsDefinition'), array(), '', FALSE);
- $mockDataMapFactory->expects($this->once())->method('getColumnsDefinition')->with($this->equalTo('tx_myextension_mm'))->will($this->returnValue($relationTableColumnsDefiniton));
- $mockDataMapFactory->_callRef('setManyToManyRelation', $mockColumnMap, $leftColumnsDefinition['rights']);
- }
-
- /**
- * @test
- */
- public function columnMapIsInitializedWithManyToManyRelationWithoutPidColumn() {
- $leftColumnsDefinition = array(
- 'rights' => array(
- 'type' => 'select',
- 'foreign_table' => 'tx_myextension_righttable',
- 'foreign_table_where' => 'WHERE 1=1',
- 'MM' => 'tx_myextension_mm',
- ),
- );
- $mockColumnMap = $this->getMock('Tx_Extbase_Persistence_Mapper_ColumnMap', array(), array(), '', FALSE);
- $mockColumnMap->expects($this->once())->method('setRelationTableName')->with($this->equalTo('tx_myextension_mm'));
- $mockColumnMap->expects($this->once())->method('getRelationTableName')->will($this->returnValue('tx_myextension_mm'));
- $mockColumnMap->expects($this->never())->method('setrelationTablePageIdColumnName');
-
- $mockDataMapFactory = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_Persistence_Mapper_DataMapFactory'), array('getControlSection'), array(), '', FALSE);
- $mockDataMapFactory->expects($this->once())->method('getControlSection')->with($this->equalTo('tx_myextension_mm'))->will($this->returnValue(NULL));
- $mockDataMapFactory->_callRef('setManyToManyRelation', $mockColumnMap, $leftColumnsDefinition['rights']);
- }
-
- /**
- * @test
- */
- public function columnMapIsInitializedWithManyToManyRelationWithPidColumn() {
- $leftColumnsDefinition = array(
- 'rights' => array(
- 'type' => 'select',
- 'foreign_table' => 'tx_myextension_righttable',
- 'foreign_table_where' => 'WHERE 1=1',
- 'MM' => 'tx_myextension_mm',
- ),
- );
- $mockColumnMap = $this->getMock('Tx_Extbase_Persistence_Mapper_ColumnMap', array(), array(), '', FALSE);
- $mockColumnMap->expects($this->once())->method('setRelationTableName')->with($this->equalTo('tx_myextension_mm'));
- $mockColumnMap->expects($this->once())->method('getRelationTableName')->will($this->returnValue('tx_myextension_mm'));
- $mockColumnMap->expects($this->once())->method('setrelationTablePageIdColumnName')->with($this->equalTo('pid'));
-
- $mockDataMapFactory = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_Persistence_Mapper_DataMapFactory'), array('getControlSection'), array(), '', FALSE);
- $mockDataMapFactory->expects($this->once())->method('getControlSection')->with($this->equalTo('tx_myextension_mm'))->will($this->returnValue(array('ctrl' => array('foo' => 'bar'))));
- $mockDataMapFactory->_callRef('setManyToManyRelation', $mockColumnMap, $leftColumnsDefinition['rights']);
- }
-
- /**
- * @test
- * @expectedException Tx_Extbase_Persistence_Exception_InvalidClass
- */
- public function buildDataMapThrowsExceptionIfClassNameIsNotKnown() {
- $mockDataMapFactory = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_Persistence_Mapper_DataMapFactory'), array('getControlSection'), array(), '', FALSE);
- $mockDataMapFactory->buildDataMap('UnknownObject');
- }
-
-}
-?>
\ No newline at end of file
+++ /dev/null
-<?php
-/***************************************************************
-* Copyright notice
-*
-* (c) 2009 Jochen Rau <jochen.rau@typoplanet.de>
-* All rights reserved
-*
-* This class is a backport of the corresponding class of FLOW3.
-* All credits go to the v5 team.
-*
-* 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!
-***************************************************************/
-
-class Tx_Extbase_Persistence_ObjectStorage_testcase extends Tx_Extbase_BaseTestCase {
-
- /**
- * @test
- */
- public function anObjectCanBeAttached() {
- $objectStorage = new Tx_Extbase_Persistence_ObjectStorage();
- $object1 = new StdClass;
- $object2 = new StdClass;
- $objectStorage->attach($object1);
- $objectStorage->attach($object2, 'foo');
- $this->assertEquals($objectStorage[$object1], NULL);
- $this->assertEquals($objectStorage[$object2], 'foo');
- }
-
- /**
- * @test
- */
- public function anObjectCanBeDetached() {
- $objectStorage = new Tx_Extbase_Persistence_ObjectStorage();
- $object1 = new StdClass;
- $object2 = new StdClass;
- $objectStorage->attach($object1);
- $objectStorage->attach($object2, 'foo');
- $this->assertEquals(count($objectStorage), 2);
- $objectStorage->detach($object1);
- $this->assertEquals(count($objectStorage), 1);
- $objectStorage->detach($object2);
- $this->assertEquals(count($objectStorage), 0);
- }
-
- /**
- * @test
- */
- public function offsetSetAssociatesDataToAnObjectInTheStorage() {
- $objectStorage = new Tx_Extbase_Persistence_ObjectStorage();
- $object1 = new StdClass;
- $object2 = new StdClass;
- $objectStorage->offsetSet($object1, 'foo');
- $this->assertEquals(count($objectStorage), 1);
- $objectStorage[$object2] = 'bar';
- $this->assertEquals(count($objectStorage), 2);
- }
-
- /**
- * @test
- */
- public function offsetUnsetRemovesAnObjectFromTheStorage() {
- $objectStorage = new Tx_Extbase_Persistence_ObjectStorage();
- $object1 = new StdClass;
- $object2 = new StdClass;
- $objectStorage->attach($object1);
- $objectStorage->attach($object2, 'foo');
- $this->assertEquals(count($objectStorage), 2);
- $objectStorage->offsetUnset($object2);
- $this->assertEquals(count($objectStorage), 1);
- $objectStorage->offsetUnset($object1);
- $this->assertEquals(count($objectStorage), 0);
- }
-
- /**
- * @test
- */
- public function offsetGetReturnsTheDataAssociatedWithAnObject() {
- $objectStorage = new Tx_Extbase_Persistence_ObjectStorage();
- $object1 = new StdClass;
- $object2 = new StdClass;
- $objectStorage[$object1] = 'foo';
- $objectStorage->attach($object2);
- $this->assertEquals($objectStorage->offsetGet($object1), 'foo');
- $this->assertEquals($objectStorage->offsetGet($object2), NULL);
- }
-
- /**
- * @test
- */
- public function offsetExistsChecksWhetherAnObjectExistsInTheStorage() {
- $objectStorage = new Tx_Extbase_Persistence_ObjectStorage();
- $object1 = new StdClass;
- $object2 = new StdClass;
- $objectStorage->attach($object1);
- $this->assertEquals($objectStorage->offsetExists($object1), TRUE);
- $this->assertEquals($objectStorage->offsetExists($object2), FALSE);
- }
-
- /**
- * @test
- */
- public function getInfoReturnsTheDataAssociatedWithTheCurrentIteratorEntry() {
- $objectStorage = new Tx_Extbase_Persistence_ObjectStorage();
- $object1 = new StdClass;
- $object2 = new StdClass;
- $object3 = new StdClass;
- $objectStorage->attach($object1, 42);
- $objectStorage->attach($object2, 'foo');
- $objectStorage->attach($object3, array('bar', 'baz'));
- $objectStorage->rewind();
- $this->assertEquals($objectStorage->getInfo(), 42);
- $objectStorage->next();
- $this->assertEquals($objectStorage->getInfo(), 'foo');
- $objectStorage->next();
- $this->assertEquals($objectStorage->getInfo(), array('bar', 'baz'));
- }
-
- /**
- * @test
- */
- public function setInfoSetsTheDataAssociatedWithTheCurrentIteratorEntry() {
- $objectStorage = new Tx_Extbase_Persistence_ObjectStorage();
- $object1 = new StdClass;
- $object2 = new StdClass;
- $objectStorage->attach($object1);
- $objectStorage->attach($object2, 'foo');
- $objectStorage->rewind();
- $objectStorage->setInfo(42);
- $objectStorage->next();
- $objectStorage->setInfo('bar');
- $this->assertEquals($objectStorage[$object1], 42);
- $this->assertEquals($objectStorage[$object2], 'bar');
- }
-
- /**
- * @test
- */
- public function removeAllRemovesObjectsContainedInAnotherStorageFromTheCurrentStorage() {
- $object1 = new StdClass;
- $object2 = new StdClass;
- $objectStorageA = new Tx_Extbase_Persistence_ObjectStorage();
- $objectStorageA->attach($object1, 'foo');
- $objectStorageB = new Tx_Extbase_Persistence_ObjectStorage();
- $objectStorageB->attach($object1, 'bar');
- $objectStorageB->attach($object2, 'baz');
- $this->assertEquals(count($objectStorageB), 2);
- $objectStorageB->removeAll($objectStorageA);
- $this->assertEquals(count($objectStorageB), 1);
- }
-
- /**
- * @test
- */
- public function addAllAddsAllObjectsFromAnotherStorage() {
- $object1 = new StdClass;
- $object2 = new StdClass;
- $objectStorageA = new Tx_Extbase_Persistence_ObjectStorage(); // It might be better to mock this
- $objectStorageA->attach($object1, 'foo');
- $objectStorageB = new Tx_Extbase_Persistence_ObjectStorage();
- $objectStorageB->attach($object2, 'baz');
- $this->assertEquals($objectStorageB->offsetExists($object1), FALSE);
- $objectStorageB->addAll($objectStorageA);
- $this->assertEquals($objectStorageB[$object1], 'foo');
- $this->assertEquals($objectStorageB[$object2], 'baz');
- }
-
-
- /**
- * @test
- */
- public function theStorageCanBeRetrievedAsArray() {
- $objectStorage = new Tx_Extbase_Persistence_ObjectStorage();
- $object1 = new StdClass;
- $object2 = new StdClass;
- $objectStorage->attach($object1, 'foo');
- $objectStorage->attach($object2, 'bar');
- $this->assertEquals($objectStorage->toArray(), array($object1, $object2));
- }
-
-}
-?>
\ No newline at end of file
+++ /dev/null
-<?php\r
-/***************************************************************\r
-* Copyright notice\r
-*\r
-* (c) 2010 Bastian Waidelich <bastian@typo3.org>\r
-* All rights reserved\r
-*\r
-* This script is part of the TYPO3 project. The TYPO3 project is\r
-* free software; you can redistribute it and/or modify\r
-* it under the terms of the GNU General Public License as published by\r
-* the Free Software Foundation; either version 2 of the License, or\r
-* (at your option) any later version.\r
-*\r
-* The GNU General Public License can be found at\r
-* http://www.gnu.org/copyleft/gpl.html.\r
-*\r
-* This script is distributed in the hope that it will be useful,\r
-* but WITHOUT ANY WARRANTY; without even the implied warranty of\r
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
-* GNU General Public License for more details.\r
-*\r
-* This copyright notice MUST APPEAR in all copies of the script!\r
-***************************************************************/\r
-\r
-class Tx_Extbase_Persistence_QueryResult_testcase extends Tx_Extbase_BaseTestCase {\r
-\r
- /**\r
- * @var Tx_Extbase_Persistence_QueryResult\r
- */\r
- protected $queryResult;\r
-\r
- /**\r
- * @var Tx_Extbase_Persistence_QueryInterface\r
- */\r
- protected $query;\r
-\r
- /**\r
- * @var Tx_Extbase_Persistence_ManagerInterface\r
- */\r
- protected $persistenceManager;\r
-\r
- /**\r
- * @var Tx_Extbase_Persistence_DataMapper\r
- */\r
- protected $dataMapper;\r
-\r
- /**\r
- * Sets up this test case\r
- *\r
- * @return void\r
- */\r
- public function setUp() {\r
- $this->persistenceManager = $this->getMock('Tx_Extbase_Persistence_ManagerInterface');\r
- $this->persistenceManager->expects($this->any())->method('getObjectDataByQuery')->will($this->returnValue(array('one', 'two')));\r
- $this->persistenceManager->expects($this->any())->method('getObjectCountByQuery')->will($this->returnValue(2));\r
- $this->dataMapper = $this->getMock('Tx_Extbase_Persistence_Mapper_DataMapper');\r
- $this->query = $this->getMock('Tx_Extbase_Persistence_QueryInterface');\r
- $this->queryResult = new Tx_Extbase_Persistence_QueryResult($this->query);\r
- $this->queryResult->injectPersistenceManager($this->persistenceManager);\r
- $this->queryResult->injectDataMapper($this->dataMapper);\r
- $this->sampleResult = array(array('foo' => 'Foo1', 'bar' => 'Bar1'), array('foo' => 'Foo2', 'bar' => 'Bar2'));\r
- $this->dataMapper->expects($this->any())->method('map')->will($this->returnValue($this->sampleResult));\r
- }\r
-\r
- /**\r
- * @test\r
- */\r
- public function getQueryReturnsQueryObject() {\r
- $this->assertType('Tx_Extbase_Persistence_QueryInterface', $this->queryResult->getQuery());\r
- }\r
-\r
- /**\r
- * @test\r
- */\r
- public function getQueryReturnsAClone() {\r
- $this->assertNotSame($this->query, $this->queryResult->getQuery());\r
- }\r
-\r
- /**\r
- * @test\r
- */\r
- public function offsetExistsWorksAsExpected() {\r
- $this->assertTrue($this->queryResult->offsetExists(0));\r
- $this->assertFalse($this->queryResult->offsetExists(2));\r
- $this->assertFalse($this->queryResult->offsetExists('foo'));\r
- }\r
-\r
- /**\r
- * @test\r
- */\r
- public function offsetGetWorksAsExpected() {\r
- $this->assertEquals(array('foo' => 'Foo1', 'bar' => 'Bar1'), $this->queryResult->offsetGet(0));\r
- $this->assertNull($this->queryResult->offsetGet(2));\r
- $this->assertNull($this->queryResult->offsetGet('foo'));\r
- }\r
-\r
- /**\r
- * @test\r
- */\r
- public function offsetSetWorksAsExpected() {\r
- $this->queryResult->offsetSet(0, array('foo' => 'FooOverridden', 'bar' => 'BarOverridden'));\r
- $this->assertEquals(array('foo' => 'FooOverridden', 'bar' => 'BarOverridden'), $this->queryResult->offsetGet(0));\r
- }\r
-\r
- /**\r
- * @test\r
- */\r
- public function offsetUnsetWorksAsExpected() {\r
- $this->queryResult->offsetUnset(0);\r
- $this->assertFalse($this->queryResult->offsetExists(0));\r
- }\r
-\r
- /**\r
- * @test\r
- */\r
- public function countDoesNotInitializeProxy() {\r
- $queryResult = $this->getMock('Tx_Extbase_Persistence_QueryResult', array('initialize'), array($this->query));\r
- $queryResult->injectPersistenceManager($this->persistenceManager);\r
- $queryResult->expects($this->never())->method('initialize');\r
- $queryResult->count();\r
- }\r
-\r
- /**\r
- * @test\r
- */\r
- public function countCallsGetObjectCountByQueryOnPersistenceManager() {\r
- $queryResult = $this->getMock('Tx_Extbase_Persistence_QueryResult', array('initialize'), array($this->query));\r
- $queryResult->injectPersistenceManager($this->persistenceManager);\r
- $this->assertEquals(2, $queryResult->count());\r
- }\r
-\r
- /**\r
- * @test\r
- */\r
- public function iteratorMethodsAreCorrectlyImplemented() {\r
- $array1 = array('foo' => 'Foo1', 'bar' => 'Bar1');\r
- $array2 = array('foo' => 'Foo2', 'bar' => 'Bar2');\r
- $this->assertEquals($array1, $this->queryResult->current());\r
- $this->assertTrue($this->queryResult->valid());\r
- $this->queryResult->next();\r
- $this->assertEquals($array2, $this->queryResult->current());\r
- $this->assertTrue($this->queryResult->valid());\r
- $this->assertEquals(1, $this->queryResult->key());\r
- $this->queryResult->next();\r
- $this->assertFalse($this->queryResult->current());\r
- $this->assertFalse($this->queryResult->valid());\r
- $this->assertNull($this->queryResult->key());\r
- $this->queryResult->rewind();\r
- $this->assertEquals(0, $this->queryResult->key());\r
- $this->assertEquals($array1, $this->queryResult->current());\r
- }\r
-\r
- /**\r
- * @test\r
- */\r
- public function initializeExecutesQueryWithArrayFetchMode() {\r
- $queryResult = $this->getAccessibleMock('Tx_Extbase_Persistence_QueryResult', array('dummy'), array($this->query));\r
- $queryResult->injectPersistenceManager($this->persistenceManager);\r
- $queryResult->injectDataMapper($this->dataMapper);\r
- $this->persistenceManager->expects($this->once())->method('getObjectDataByQuery')->with($this->query)->will($this->returnValue(array('FAKERESULT')));\r
- $queryResult->_call('initialize');\r
- }\r
-\r
-}\r
-?>
\ No newline at end of file
+++ /dev/null
-<?php
-/***************************************************************
-* Copyright notice
-*
-* (c) 2009 Christopher Hlubek <hlubek@networkteam.com>
-* (c) 2010 Bastian Waidelich <bastian@typo3.org>
-* 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!
-***************************************************************/
-
-class Tx_Extbase_Persistence_Query_testcase extends Tx_Extbase_BaseTestCase {
-
- /**
- * @var Tx_Extbase_Persistence_Query
- */
- protected $query;
-
- /**
- * @var Tx_Extbase_Persistence_QuerySettingsInterface
- */
- protected $querySettings;
-
- /**
- * @var Tx_Extbase_Object_ObjectManagerInterface
- */
- protected $objectManager;
-
- /**
- * @var Tx_Extbase_Persistence_ManagerInterface
- */
- protected $persistenceManager;
-
- /**
- * @var Tx_Extbase_Persistence_BackendInterface
- */
- protected $backend;
-
- /**
- * @var Tx_Extbase_Persistence_DataMapper
- */
- protected $dataMapper;
-
- /**
- * Sets up this test case
- * @return void
- */
- public function setUp() {
- $this->objectManager = $this->getMock('Tx_Extbase_Object_ObjectManagerInterface');
- $this->query = new Tx_Extbase_Persistence_Query('someType');
- $this->query->injectObjectManager($this->objectManager);
- $this->querySettings = $this->getMock('Tx_Extbase_Persistence_QuerySettingsInterface');
- $this->query->setQuerySettings($this->querySettings);
- $this->persistenceManager = $this->getMock('Tx_Extbase_Persistence_ManagerInterface');
- $this->backend = $this->getMock('Tx_Extbase_Persistence_BackendInterface');
- $this->backend->expects($this->any())->method('getQomFactory')->will($this->returnValue(NULL));
- $this->persistenceManager->expects($this->any())->method('getBackend')->will($this->returnValue($this->backend));
- $this->query->injectPersistenceManager($this->persistenceManager);
- $this->dataMapper = $this->getMock('Tx_Extbase_Persistence_Mapper_DataMapper');
- $this->query->injectDataMapper($this->dataMapper);
- }
-
- /**
- * @test
- */
- public function executeReturnsQueryResultInstanceAndInjectsItself() {
- $queryResult = $this->getMock('Tx_Extbase_Persistence_QueryResult', array(), array(), '', FALSE);
- $this->objectManager->expects($this->once())->method('create')->with('Tx_Extbase_Persistence_QueryResultInterface', $this->query)->will($this->returnValue($queryResult));
- $actualResult = $this->query->execute();
- $this->assertSame($queryResult, $actualResult);
- }
-
- /**
- * @test
- */
- public function executeReturnsRawObjectDataIfRawQueryResultSettingIsTrue() {
- $this->querySettings->expects($this->once())->method('getReturnRawQueryResult')->will($this->returnValue(TRUE));
- $this->persistenceManager->expects($this->once())->method('getObjectDataByQuery')->with($this->query)->will($this->returnValue('rawQueryResult'));
- $expectedResult = 'rawQueryResult';
- $actualResult = $this->query->execute();
- $this->assertEquals($expectedResult, $actualResult);
- }
-
- /**
- * @test
- * @expectedException InvalidArgumentException
- */
- public function setLimitAcceptsOnlyIntegers() {
- $this->query->setLimit(1.5);
- }
-
- /**
- * @test
- * @expectedException InvalidArgumentException
- */
- public function setLimitRejectsIntegersLessThanOne() {
- $this->query->setLimit(0);
- }
-
- /**
- * @test
- * @expectedException InvalidArgumentException
- */
- public function setOffsetAcceptsOnlyIntegers() {
- $this->query->setOffset(1.5);
- }
-
- /**
- * @test
- * @expectedException InvalidArgumentException
- */
- public function setOffsetRejectsIntegersLessThanZero() {
- $this->query->setOffset(-1);
- }
-
-}
-?>
\ No newline at end of file
+++ /dev/null
-<?php\r
-/***************************************************************\r
-* Copyright notice\r
-*\r
-* (c) 2010 Bastian Waidelich <bastian@typo3.org>\r
-* All rights reserved\r
-*\r
-* This script is part of the TYPO3 project. The TYPO3 project is\r
-* free software; you can redistribute it and/or modify\r
-* it under the terms of the GNU General Public License as published by\r
-* the Free Software Foundation; either version 2 of the License, or\r
-* (at your option) any later version.\r
-*\r
-* The GNU General Public License can be found at\r
-* http://www.gnu.org/copyleft/gpl.html.\r
-*\r
-* This script is distributed in the hope that it will be useful,\r
-* but WITHOUT ANY WARRANTY; without even the implied warranty of\r
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
-* GNU General Public License for more details.\r
-*\r
-* This copyright notice MUST APPEAR in all copies of the script!\r
-***************************************************************/\r
-\r
-class Tx_Extbase_Persistence_Repository_testcase extends Tx_Extbase_BaseTestCase {\r
-\r
- /**\r
- * @var Tx_Extbase_Persistence_Repository\r
- */\r
- protected $repository;\r
-\r
- /**\r
- * @var Tx_Extbase_Persistence_IdentityMap\r
- */\r
- protected $identityMap;\r
-\r
- /**\r
- * @var Tx_Extbase_Persistence_QueryFactory\r
- */\r
- protected $queryFactory;\r
-\r
- /**\r
- * @var Tx_Extbase_Persistence_ManagerInterface\r
- */\r
- protected $persistenceManager;\r
-\r
- /**\r
- * @var Tx_Extbase_Persistence_QueryInterface\r
- */\r
- protected $query;\r
-\r
- /**\r
- * @var Tx_Extbase_Persistence_QuerySettingsInterface\r
- */\r
- protected $querySettings;\r
-\r
- public function setUp() {\r
- $this->identityMap = $this->getMock('Tx_Extbase_Persistence_IdentityMap');\r
- $this->queryFactory = $this->getMock('Tx_Extbase_Persistence_QueryFactory');\r
- $this->query = $this->getMock('Tx_Extbase_Persistence_QueryInterface');\r
- $this->querySettings = $this->getMock('Tx_Extbase_Persistence_QuerySettingsInterface');\r
- $this->query->expects($this->any())->method('getQuerySettings')->will($this->returnValue($this->querySettings));\r
- $this->queryFactory->expects($this->any())->method('create')->will($this->returnValue($this->query));\r
- $this->persistenceManager = $this->getMock('Tx_Extbase_Persistence_ManagerInterface');\r
- $this->repository = $this->getAccessibleMock('Tx_Extbase_Persistence_Repository', array('dummy'), array($this->identityMap, $this->queryFactory, $this->persistenceManager));\r
- }\r
-\r
- /**\r
- * @test\r
- */\r
- public function abstractRepositoryImplementsRepositoryInterface() {\r
- $this->assertTrue($this->repository instanceof Tx_Extbase_Persistence_RepositoryInterface);\r
- }\r
-\r
- /**\r
- * @test\r
- */\r
- public function addActuallyAddsAnObjectToTheInternalObjectsArray() {\r
- $someObject = new stdClass();\r
- $this->repository->_set('objectType', get_class($someObject));\r
- $this->repository->add($someObject);\r
-\r
- $this->assertTrue($this->repository->getAddedObjects()->contains($someObject));\r
- }\r
-\r
- /**\r
- * @test\r
- */\r
- public function removeActuallyRemovesAnObjectFromTheInternalObjectsArray() {\r
- $object1 = new stdClass();\r
- $object2 = new stdClass();\r
- $object3 = new stdClass();\r
-\r
- $this->repository->_set('objectType', get_class($object1));\r
- $this->repository->add($object1);\r
- $this->repository->add($object2);\r
- $this->repository->add($object3);\r
-\r
- $this->repository->remove($object2);\r
-\r
- $this->assertTrue($this->repository->getAddedObjects()->contains($object1));\r
- $this->assertFalse($this->repository->getAddedObjects()->contains($object2));\r
- $this->assertTrue($this->repository->getAddedObjects()->contains($object3));\r
- }\r
-\r
- /**\r
- * @test\r
- */\r
- public function removeRemovesTheRightObjectEvenIfItHasBeenModifiedSinceItsAddition() {\r
- $object1 = new ArrayObject(array('val' => '1'));\r
- $object2 = new ArrayObject(array('val' => '2'));\r
- $object3 = new ArrayObject(array('val' => '3'));\r
-\r
- $this->repository->_set('objectType', get_class($object1));\r
- $this->repository->add($object1);\r
- $this->repository->add($object2);\r
- $this->repository->add($object3);\r
-\r
- $object2['foo'] = 'bar';\r
- $object3['val'] = '2';\r
-\r
- $this->repository->remove($object2);\r
-\r
- $this->assertTrue($this->repository->getAddedObjects()->contains($object1));\r
- $this->assertFalse($this->repository->getAddedObjects()->contains($object2));\r
- $this->assertTrue($this->repository->getAddedObjects()->contains($object3));\r
- }\r
-\r
- /**\r
- * Make sure we remember the objects that are not currently add()ed\r
- * but might be in persistent storage.\r
- *\r
- * @test\r
- */\r
- public function removeRetainsObjectForObjectsNotInCurrentSession() {\r
- $object = new ArrayObject(array('val' => '1'));\r
- $this->repository->_set('objectType', get_class($object));\r
- $this->repository->remove($object);\r
-\r
- $this->assertTrue($this->repository->getRemovedObjects()->contains($object));\r
- }\r
-\r
- /**\r
- * dataProvider for createQueryCallsQueryFactoryWithExpectedType\r
- */\r
- public function modelAndRepositoryClassNames() {\r
- return array(\r
- array('Tx_BlogExample_Domain_Repository_BlogRepository', 'Tx_BlogExample_Domain_Model_Blog'),\r
- array('_Domain_Repository_Content_PageRepository', '_Domain_Model_Content_Page')\r
- );\r
- }\r
-\r
- /**\r
- * @test\r
- * @dataProvider modelAndRepositoryClassNames\r
- */\r
- public function constructSetsObjectTypeFromClassName($repositoryClassName, $modelClassName) {\r
- $mockClassName = 'MockRepository' . uniqid();\r
- eval('class ' . $mockClassName . ' extends Tx_Extbase_Persistence_Repository {\r
- protected function getRepositoryClassName() {\r
- return \'' . $repositoryClassName . '\';\r
- }\r
- public function _getObjectType() {\r
- return $this->objectType;\r
- }\r
- }');\r
-\r
- $this->repository = new $mockClassName($this->identityMap, $this->queryFactory, $this->persistenceManager);\r
- $this->assertEquals($modelClassName, $this->repository->_getObjectType());\r
- }\r
-\r
- /**\r
- * @test\r
- */\r
- public function createQueryCallsQueryFactoryWithExpectedClassName() {\r
- $this->queryFactory->expects($this->once())->method('create')->with('ExpectedType');\r
- $this->repository->_set('objectType', 'ExpectedType');\r
- $this->repository->createQuery();\r
- }\r
-\r
- /**\r
- * @test\r
- */\r
- public function findAllCreatesQueryAndReturnsResultOfExecuteCall() {\r
- $expectedResult = $this->getMock('Tx_Extbase_Persistence_QueryResultInterface');\r
- $this->query->expects($this->once())->method('execute')->with()->will($this->returnValue($expectedResult));\r
- $this->assertSame($expectedResult, $this->repository->findAll());\r
- }\r
-\r
- /**\r
- * @test\r
- */\r
- public function findByUidReturnsResultOfGetObjectByIdentifierCall() {\r
- $fakeUid = '123';\r
- $object = new stdClass();\r
-\r
- $this->persistenceManager->expects($this->once())->method('getObjectByIdentifier')->with($fakeUid)->will($this->returnValue($object));\r
- $this->repository->_set('objectType', 'stdClass');\r
-\r
- $this->assertSame($object, $this->repository->findByUid($fakeUid));\r
- }\r
-\r
- /**\r
- * @test\r
- */\r
- public function findByUidReturnsNullIfObjectOfMismatchingTypeWasFoundByGetObjectByIdentifierCall() {\r
- $fakeUUID = '123';\r
- $object = new stdClass();\r
-\r
- $this->persistenceManager->expects($this->once())->method('getObjectByIdentifier')->with($fakeUUID)->will($this->returnValue($object));\r
- $this->repository->_set('objectType', 'otherExpectedClass');\r
-\r
- $this->assertNULL($this->repository->findByUuid($fakeUUID));\r
- }\r
-\r
- /**\r
- * Replacing a reconstituted object (which has a uuid) by a new object\r
- * will ask the persistence backend to replace them accordingly in the\r
- * identity map.\r
- *\r
- * @test\r
- * @return void\r
- */\r
- public function replaceReconstitutedEntityByNewObject() {\r
- $existingObject = new stdClass;\r
- $newObject = new stdClass;\r
-\r
- $this->persistenceManager->expects($this->once())->method('getIdentifierByObject')->with($existingObject)->will($this->returnValue('86ea8820-19f6-11de-8c30-0800200c9a66'));\r
- $this->persistenceManager->expects($this->once())->method('replaceObject')->with($existingObject, $newObject);\r
-\r
- $this->repository->_set('objectType', get_class($newObject));\r
- $this->repository->replace($existingObject, $newObject);\r
- }\r
-\r
- /**\r
- * Replacing a reconstituted object which during this session has been\r
- * marked for removal (by calling the repository's remove method)\r
- * additionally registers the "newObject" for removal and removes the\r
- * "existingObject" from the list of removed objects.\r
- *\r
- * @test\r
- * @return void\r
- */\r
- public function replaceReconstitutedObjectWhichIsMarkedToBeRemoved() {\r
- $existingObject = new stdClass;\r
- $newObject = new stdClass;\r
-\r
- $removedObjects = new SplObjectStorage;\r
- $removedObjects->attach($existingObject);\r
-\r
- $this->persistenceManager->expects($this->once())->method('getIdentifierByObject')->with($existingObject)->will($this->returnValue('86ea8820-19f6-11de-8c30-0800200c9a66'));\r
- $this->persistenceManager->expects($this->once())->method('replaceObject')->with($existingObject, $newObject);\r
-\r
- $this->repository->_set('objectType', get_class($newObject));\r
- $this->repository->_set('removedObjects', $removedObjects);\r
- $this->repository->replace($existingObject, $newObject);\r
-\r
- $this->assertFalse($removedObjects->contains($existingObject));\r
- $this->assertTrue($removedObjects->contains($newObject));\r
- }\r
-\r
- /**\r
- * Replacing a new object which has not yet been persisted by another\r
- * new object will just replace them in the repository's list of added\r
- * objects.\r
- *\r
- * @test\r
- * @return void\r
- */\r
- public function replaceNewObjectByNewObject() {\r
- $existingObject = new stdClass;\r
- $newObject = new stdClass;\r
-\r
- $addedObjects = new SplObjectStorage;\r
- $addedObjects->attach($existingObject);\r
-\r
- $this->persistenceManager->expects($this->once())->method('getIdentifierByObject')->with($existingObject)->will($this->returnValue(NULL));\r
- $this->persistenceManager->expects($this->never())->method('replaceObject');\r
-\r
- $this->repository->_set('objectType', get_class($newObject));\r
- $this->repository->_set('addedObjects', $addedObjects);\r
- $this->repository->replace($existingObject, $newObject);\r
-\r
- $this->assertFalse($addedObjects->contains($existingObject));\r
- $this->assertTrue($addedObjects->contains($newObject));\r
- }\r
-\r
- /**\r
- * @test\r
- * @expectedException Tx_Extbase_Persistence_Exception_IllegalObjectType\r
- */\r
- public function replaceChecksObjectType() {\r
- $this->repository->_set('objectType', 'ExpectedObjectType');\r
-\r
- $this->repository->replace(new stdClass(), new stdClass());\r
- }\r
-\r
- /**\r
- * @test\r
- */\r
- public function updateReplacesAnObjectWithTheSameUuidByTheGivenObject() {\r
- $existingObject = new stdClass;\r
- $modifiedObject = $this->getMock('FooBar' . uniqid(), array('FLOW3_Persistence_isClone'));\r
- $modifiedObject->expects($this->once())->method('FLOW3_Persistence_isClone')->will($this->returnValue(TRUE));\r
-\r
- $this->persistenceManager->expects($this->once())->method('getIdentifierByObject')->with($modifiedObject)->will($this->returnValue('86ea8820-19f6-11de-8c30-0800200c9a66'));\r
- $this->persistenceManager->expects($this->once())->method('getObjectByIdentifier')->with('86ea8820-19f6-11de-8c30-0800200c9a66')->will($this->returnValue($existingObject));\r
-\r
- $this->repository->expects($this->once())->method('replaceObject')->with($existingObject, $modifiedObject);\r
-\r
- $this->repository->_set('objectType', get_class($modifiedObject));\r
- $this->repository->update($modifiedObject);\r
- }\r
-\r
- /**\r
- * @test\r
- * @expectedException Tx_Extbase_Persistence_Exception_IllegalObjectType\r
- */\r
- public function updateRejectsNonClonedObjects() {\r
- $someObject = $this->getMock('FooBar' . uniqid(), array('FLOW3_Persistence_isClone'));\r
- $someObject->expects($this->once())->method('FLOW3_Persistence_isClone')->will($this->returnValue(FALSE));\r
-\r
- $this->repository->_set('objectType', get_class($someObject));\r
-\r
- $this->repository->update($someObject);\r
- }\r
-\r
- /**\r
- * @test\r
- * @expectedException Tx_Extbase_Persistence_Exception_IllegalObjectType\r
- */\r
- public function updateRejectsObjectsOfWrongType() {\r
- $this->repository->_set('objectType', 'Foo');\r
- $this->repository->update(new stdClass());\r
- }\r
-\r
- /**\r
- * @test\r
- */\r
- public function magicCallMethodAcceptsFindBySomethingCallsAndExecutesAQueryWithThatCriteria() {\r
- $mockQueryResult = $this->getMock('Tx_Extbase_Persistence_QueryResultInterface');\r
- $mockQuery = $this->getMock('Tx_Extbase_Persistence_QueryInterface');\r
- $mockQuery->expects($this->once())->method('equals')->with('foo', 'bar')->will($this->returnValue('matchCriteria'));\r
- $mockQuery->expects($this->once())->method('matching')->with('matchCriteria')->will($this->returnValue($mockQuery));\r
- $mockQuery->expects($this->once())->method('execute')->with()->will($this->returnValue($mockQueryResult));\r
-\r
- $this->repository->expects($this->once())->method('createQuery')->will($this->returnValue($mockQuery));\r
-\r
- $this->assertSame($mockQueryResult, $this->repository->findByFoo('bar'));\r
- }\r
-\r
- /**\r
- * @test\r
- */\r
- public function magicCallMethodAcceptsFindOneBySomethingCallsAndExecutesAQueryWithThatCriteria() {\r
- $object = new stdClass();\r
- $mockQueryResult = $this->getMock('Tx_Extbase_Persistence_QueryResultInterface');\r
- $mockQueryResult->expects($this->once())->method('getFirst')->will($this->returnValue($object));\r
- $mockQuery = $this->getMock('Tx_Extbase_Persistence_QueryInterface');\r
- $mockQuery->expects($this->once())->method('equals')->with('foo', 'bar')->will($this->returnValue('matchCriteria'));\r
- $mockQuery->expects($this->once())->method('matching')->with('matchCriteria')->will($this->returnValue($mockQuery));\r
- $mockQuery->expects($this->once())->method('execute')->will($this->returnValue($mockQueryResult));\r
-\r
- $this->repository->expects($this->once())->method('createQuery')->will($this->returnValue($mockQuery));\r
-\r
- $this->assertSame($object, $this->repository->findOneByFoo('bar'));\r
- }\r
-\r
- /**\r
- * @test\r
- */\r
- public function magicCallMethodAcceptsCountBySomethingCallsAndExecutesAQueryWithThatCriteria() {\r
- $mockQueryResult = $this->getMock('Tx_Extbase_Persistence_QueryResultInterface');\r
- $mockQueryResult->expects($this->once())->method('count')->will($this->returnValue(2));\r
- $mockQuery = $this->getMock('Tx_Extbase_Persistence_QueryInterface');\r
- $mockQuery->expects($this->once())->method('equals')->with('foo', 'bar')->will($this->returnValue('matchCriteria'));\r
- $mockQuery->expects($this->once())->method('matching')->with('matchCriteria')->will($this->returnValue($mockQuery));\r
- $mockQuery->expects($this->once())->method('execute')->will($this->returnValue($mockQueryResult));\r
-\r
- $this->repository->expects($this->once())->method('createQuery')->will($this->returnValue($mockQuery));\r
-\r
- $this->assertSame(2, $this->repository->countByFoo('bar'));\r
- }\r
-\r
- /**\r
- * @test\r
- * @expectedException Exception\r
- */\r
- public function magicCallMethodTriggersAnErrorIfUnknownMethodsAreCalled() {\r
- $this->repository->__call('foo', array());\r
- }\r
-\r
- /**\r
- * @test\r
- * @expectedException Tx_Extbase_Persistence_Exception_IllegalObjectType\r
- */\r
- public function addChecksObjectType() {\r
- $this->repository->_set('objectType', 'ExpectedObjectType');\r
-\r
- $this->repository->add(new stdClass());\r
- }\r
-\r
- /**\r
- * @test\r
- * @expectedException Tx_Extbase_Persistence_Exception_IllegalObjectType\r
- */\r
- public function removeChecksObjectType() {\r
- $this->repository->_set('objectType', 'ExpectedObjectType');\r
-\r
- $this->repository->remove(new stdClass());\r
- }\r
-\r
-}\r
-?>
\ No newline at end of file
+++ /dev/null
-<?php
-/***************************************************************
-* Copyright notice
-*
-* (c) 2009 Jochen Rau <jochen.rau@typoplanet.de>
-* All rights reserved
-*
-* This class is a backport of the corresponding class of FLOW3.
-* All credits go to the v5 team.
-*
-* 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!
-***************************************************************/
-
-require_once(PATH_tslib . 'class.tslib_content.php');
-
-class Tx_Extbase_Persistence_Session_testcase extends tx_phpunit_testcase {
-
- /**
- * @test
- */
- public function newSessionIsEmpty() {
- $persistenceSession = new Tx_Extbase_Persistence_Session;
- $reconstitutedObjects = $persistenceSession->getReconstitutedObjects();
- $this->assertEquals(0, count($reconstitutedObjects), 'The reconstituted objects storage was not empty.');
- }
-
- /**
- * @test
- */
- public function objectCanBeRegisteredAsReconstituted() {
- $persistenceSession = new Tx_Extbase_Persistence_Session;
- $entity = $this->getMock('Tx_Extbase_DomainObject_AbstractEntity');
- $persistenceSession->registerReconstitutedObject($entity);
- $reconstitutedObjects = $persistenceSession->getReconstitutedObjects();
- $this->assertTrue($reconstitutedObjects->contains($entity), 'The object was not registered as reconstituted.');
- }
-
- /**
- * @test
- */
- public function objectCanBeUnregisteredAsReconstituted() {
- $persistenceSession = new Tx_Extbase_Persistence_Session;
- $entity = $this->getMock('Tx_Extbase_DomainObject_AbstractEntity');
- $persistenceSession->registerReconstitutedObject($entity);
- $persistenceSession->unregisterReconstitutedObject($entity);
- $reconstitutedObjects = $persistenceSession->getReconstitutedObjects();
-
- $this->assertEquals(0, count($reconstitutedObjects), 'The reconstituted objects storage was not empty.');
- }
-
-}
-?>
\ No newline at end of file
+++ /dev/null
-<?php
-/***************************************************************
- * Copyright notice
- *
- * (c) 2009 Jochen Rau <jochen.rau@typoplanet.de>
- * All rights reserved
- *
- * This class is a backport of the corresponding class of FLOW3.
- * All credits go to the v5 team.
- *
- * 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!
- ***************************************************************/
-
-class Tx_Extbase_Persistence_Storage_Typo3DbBackend_testcase extends Tx_Extbase_BaseTestCase {
-
- /**
- * This is the data provider for the statement generation with a basic comparison
- *
- * @return array An array of data
- */
- public function providerForBasicComparison() {
- return array(
- 'equal' => array(
- Tx_Extbase_Persistence_QueryInterface::OPERATOR_EQUAL_TO,
- "SELECT table_name_from_selector.* FROM table_name_from_selector WHERE table_name_from_property.foo = 'baz'"
- ),
- 'less' => array(
- Tx_Extbase_Persistence_QueryInterface::OPERATOR_LESS_THAN,
- "SELECT table_name_from_selector.* FROM table_name_from_selector WHERE table_name_from_property.foo < 'baz'"
- ),
- 'less or equal' => array(
- Tx_Extbase_Persistence_QueryInterface::OPERATOR_LESS_THAN_OR_EQUAL_TO,
- "SELECT table_name_from_selector.* FROM table_name_from_selector WHERE table_name_from_property.foo <= 'baz'"
- ),
- 'greater' => array(
- Tx_Extbase_Persistence_QueryInterface::OPERATOR_GREATER_THAN,
- "SELECT table_name_from_selector.* FROM table_name_from_selector WHERE table_name_from_property.foo > 'baz'"
- ),
- 'greater or equal' => array(
- Tx_Extbase_Persistence_QueryInterface::OPERATOR_GREATER_THAN_OR_EQUAL_TO,
- "SELECT table_name_from_selector.* FROM table_name_from_selector WHERE table_name_from_property.foo >= 'baz'"
- ),
-
- );
- }
-
- /**
- * @test
- */
- public function getStatementWorksWithMinimalisticQueryObjectModel() {
- $this->markTestIncomplete();
- }
-
- /**
- * @test
- */
- public function getStatementWorksWithBasicEqualsCondition() {
- $this->markTestIncomplete();
- }
-
- /**
- * @test
- * @expectedException Tx_Extbase_Persistence_Storage_Exception_BadConstraint
- */
- public function countRowsWithStatementConstraintResultsInAnException() {
- $this->markTestIncomplete();
- }
-
- /**
- * @test
- */
- public function joinStatementGenerationWorks() {
- $this->markTestIncomplete();
- }
-
- /**
- * @test
- */
- public function orderStatementGenerationWorks() {
- $mockSource = $this->getMock('Tx_Extbase_Persistence_QOM_Selector', array('getNodeTypeName'), array(), '', FALSE);
- $mockSource->expects($this->any())->method('getNodeTypeName')->will($this->returnValue('Tx_MyExt_ClassName'));
-
- $mockDataMapper = $this->getMock('Tx_Extbase_Persistence_Mapper_DataMapper', array('convertPropertyNameToColumnName', 'convertClassNameToTableName'), array(), '', FALSE);
- $mockDataMapper->expects($this->once())->method('convertClassNameToTableName')->with('Tx_MyExt_ClassName')->will($this->returnValue('tx_myext_tablename'));
- $mockDataMapper->expects($this->once())->method('convertPropertyNameToColumnName')->with('fooProperty', 'Tx_MyExt_ClassName')->will($this->returnValue('converted_fieldname'));
-
- $sql = array();
- $orderings = array('fooProperty' => Tx_Extbase_Persistence_QOM_QueryObjectModelConstantsInterface::JCR_ORDER_ASCENDING);
- $mockTypo3DbBackend = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_Persistence_Storage_Typo3DbBackend'), array('parserOrderings'), array(), '', FALSE);
- $mockTypo3DbBackend->_set('dataMapper', $mockDataMapper);
- $mockTypo3DbBackend->_callRef('parseOrderings', $orderings, $mockSource, $sql);
-
- $expecedSql = array('orderings' => array('tx_myext_tablename.converted_fieldname ASC'));
- $this->assertSame($expecedSql, $sql);
- }
-
- /**
- * @test
- * @expectedException Tx_Extbase_Persistence_Exception_UnsupportedOrder
- */
- public function orderStatementGenerationThrowsExceptionOnUnsupportedOrder() {
- $mockSource = $this->getMock('Tx_Extbase_Persistence_QOM_Selector', array('getNodeTypeName'), array(), '', FALSE);
- $mockSource->expects($this->never())->method('getNodeTypeName');
-
- $mockDataMapper = $this->getMock('Tx_Extbase_Persistence_Mapper_DataMapper', array('convertPropertyNameToColumnName', 'convertClassNameToTableName'), array(), '', FALSE);
- $mockDataMapper->expects($this->never())->method('convertClassNameToTableName');
- $mockDataMapper->expects($this->never())->method('convertPropertyNameToColumnName');
-
- $sql = array();
- $orderings = array('fooProperty' => 'unsupported_order');
- $mockTypo3DbBackend = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_Persistence_Storage_Typo3DbBackend'), array('parserOrderings'), array(), '', FALSE);
- $mockTypo3DbBackend->_set('dataMapper', $mockDataMapper);
- $mockTypo3DbBackend->_callRef('parseOrderings', $orderings, $mockSource, $sql);
- }
-
- /**
- * @test
- */
- public function orderStatementGenerationWorksWithMultipleOrderings() {
- $mockSource = $this->getMock('Tx_Extbase_Persistence_QOM_Selector', array('getNodeTypeName'), array(), '', FALSE);
- $mockSource->expects($this->any())->method('getNodeTypeName')->will($this->returnValue('Tx_MyExt_ClassName'));
-
- $mockDataMapper = $this->getMock('Tx_Extbase_Persistence_Mapper_DataMapper', array('convertPropertyNameToColumnName', 'convertClassNameToTableName'), array(), '', FALSE);
- $mockDataMapper->expects($this->any())->method('convertClassNameToTableName')->with('Tx_MyExt_ClassName')->will($this->returnValue('tx_myext_tablename'));
- $mockDataMapper->expects($this->any())->method('convertPropertyNameToColumnName')->will($this->returnValue('converted_fieldname'));
-
- $sql = array();
- $orderings = array(
- 'fooProperty' => Tx_Extbase_Persistence_QOM_QueryObjectModelConstantsInterface::JCR_ORDER_ASCENDING,
- 'barProperty' => Tx_Extbase_Persistence_QOM_QueryObjectModelConstantsInterface::JCR_ORDER_DESCENDING
- );
- $mockTypo3DbBackend = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_Persistence_Storage_Typo3DbBackend'), array('parserOrderings'), array(), '', FALSE);
- $mockTypo3DbBackend->_set('dataMapper', $mockDataMapper);
- $mockTypo3DbBackend->_callRef('parseOrderings', $orderings, $mockSource, $sql);
-
- $expecedSql = array('orderings' => array('tx_myext_tablename.converted_fieldname ASC', 'tx_myext_tablename.converted_fieldname DESC'));
- $this->assertSame($expecedSql, $sql);
- }
-
-}
-?>
\ No newline at end of file
+++ /dev/null
-<?php
-/***************************************************************
-* Copyright notice
-*
-* (c) 2009 Christopher Hlubek <hlubek@networkteam.com>
-* 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!
-***************************************************************/
-
-/**
- * Some functional tests for the backport of the reflection service
- */
-class Tx_Extbase_Reflection_Service_testcase extends Tx_Extbase_BaseTestCase {
-
- /**
- * @param array $foo The foo parameter
- * @return nothing
- */
- public function fixtureMethodForMethodTagsValues(array $foo) {
-
- }
-
- public function test_GetMethodTagsValues() {
- $service = new Tx_Extbase_Reflection_Service();
- $tagsValues = $service->getMethodTagsValues('Tx_Extbase_Reflection_Service_testcase', 'fixtureMethodForMethodTagsValues');
-
- $this->assertEquals(array(
- 'param' => array('array $foo The foo parameter'),
- 'return' => array('nothing')
- ), $tagsValues);
- }
-
- public function test_GetMethodParameters() {
- $service = new Tx_Extbase_Reflection_Service();
- $parameters = $service->getMethodParameters('Tx_Extbase_Reflection_Service_testcase', 'fixtureMethodForMethodTagsValues');
-
- $this->assertEquals(array(
- 'foo' => array(
- 'position' => 0,
- 'byReference' => FALSE,
- 'array' => TRUE,
- 'optional' => FALSE,
- 'allowsNull' => FALSE,
- 'class' => NULL,
- 'type' => 'array'
- )
- ), $parameters);
- }
-}
-?>
\ No newline at end of file
+++ /dev/null
-<?php
-/***************************************************************
-* Copyright notice
-*
-* (c) 2009 Sebastian Kurfürst <sebastian@typo3.org>
-* All rights reserved
-*
-* This class is a backport of the corresponding class of FLOW3.
-* All credits go to the v5 team.
-*
-* 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!
-***************************************************************/
-
-/**
- * Testcase for the Request Hash Service
- *
- * @version $Id: RequestHashService_testcase.php 1729 2009-11-25 21:37:20Z stucki $
- * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser Public License, version 3 or later
- */
-class Tx_Extbase_Security_Channel_RequestHashService_testcase extends Tx_Extbase_BaseTestCase {
-
- public function dataProviderForGenerateRequestHash() {
- return array(
- // Simple cases
- array(
- array(),
- array(),
- ),
- array(
- array('field1'),
- array('field1' => 1),
- ),
- array(
- array('field1', 'field2'),
- array(
- 'field1' => 1,
- 'field2' => 1
- ),
- ),
- // recursion
- array(
- array('field1', 'field[subfield1]', 'field[subfield2]'),
- array(
- 'field1' => 1,
- 'field' => array(
- 'subfield1' => 1,
- 'subfield2' => 1
- )
- ),
- ),
- // recursion with duplicated field name
- array(
- array('field1', 'field[subfield1]', 'field[subfield2]', 'field1'),
- array(
- 'field1' => 1,
- 'field' => array(
- 'subfield1' => 1,
- 'subfield2' => 1
- )
- ),
- ),
- // Recursion with un-named fields at the end (...[]). There, they should be made explicit by increasing the counter
- array(
- array('field1', 'field[subfield1][]', 'field[subfield1][]', 'field[subfield2]'),
- array(
- 'field1' => 1,
- 'field' => array(
- 'subfield1' => array(
- 0 => 1,
- 1 => 1
- ),
- 'subfield2' => 1
- )
- ),
- ),
- );
- }
-
- // Data provider for error cases which should throw an exception
- public function dataProviderForGenerateRequestHashWithUnallowedValues() {
- return array(
- // Overriding form fields (string overridden by array)
- array(
- array('field1', 'field2', 'field2[bla]', 'field2[blubb]'),
- ),
- array(
- array('field1', 'field2[bla]', 'field2[bla][blubb][blubb]'),
- ),
- // Overriding form fields (array overridden by string)
- array(
- array('field1', 'field2[bla]', 'field2[blubb]', 'field2'),
- ),
- array(
- array('field1', 'field2[bla][blubb][blubb]', 'field2[bla]'),
- ),
- // Empty [] not as last argument
- array(
- array('field1', 'field2[][bla]'),
- )
-
- );
- }
-
- /**
- * @test
- * @author Sebastian Kurfürst <sebastian@typo3.org>
- * @dataProvider dataProviderForGenerateRequestHash
- */
- public function generateRequestHashGeneratesTheCorrectHashesInNormalOperation($input, $expected) {
- $requestHashService = $this->getMock('Tx_Extbase_Security_Channel_RequestHashService', array('serializeAndHashFormFieldArray'));
- $requestHashService->expects($this->once())->method('serializeAndHashFormFieldArray')->with($expected);
- $requestHashService->generateRequestHash($input);
- }
-
- /**
- * @test
- * @author Sebastian Kurfürst <sebastian@typo3.org>
- * @dataProvider dataProviderForGenerateRequestHashWithUnallowedValues
- * @expectedException Tx_Extbase_Security_Exception_InvalidArgumentForRequestHashGeneration
- */
- public function generateRequestHashThrowsExceptionInWrongCases($input) {
- $requestHashService = $this->getMock('Tx_Extbase_Security_Channel_RequestHashService', array('serializeAndHashFormFieldArray'));
- $requestHashService->generateRequestHash($input);
- }
-
- /**
- * @test
- * @author Sebastian Kurfürst <sebastian@typo3.org>
- */
- public function serializeAndHashFormFieldArrayWorks() {
- $formFieldArray = array(
- 'bla' => array(
- 'blubb' => 1,
- 'hu' => 1
- )
- );
- $mockHash = '12345';
-
- $hashService = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_Security_Cryptography_HashService'), array('generateHash'));
- $hashService->expects($this->once())->method('generateHash')->with(serialize($formFieldArray))->will($this->returnValue($mockHash));
-
- $requestHashService = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_Security_Channel_RequestHashService'), array('dummy'));
- $requestHashService->_set('hashService', $hashService);
-
- $expected = serialize($formFieldArray) . $mockHash;
- $actual = $requestHashService->_call('serializeAndHashFormFieldArray', $formFieldArray);
- $this->assertEquals($expected, $actual);
- }
-
- /**
- * @test
- * @author Sebastian Kurfürst
- */
- public function verifyRequestHashSetsHmacVerifiedToFalseIfRequestDoesNotHaveAnHmacArgument() {
- $request = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_MVC_Web_Request'), array('hasArgument', 'setHmacVerified'));
- $request->expects($this->once())->method('hasArgument')->with('__hmac')->will($this->returnValue(FALSE));
- &n