diff --git a/composer.json b/composer.json index a550f4404..ae1b4f07a 100644 --- a/composer.json +++ b/composer.json @@ -25,7 +25,6 @@ "container-interop/container-interop": "^1.1" }, "require-dev": { - "zendframework/zend-authentication": "^2.5.3", "zendframework/zend-cache": "^2.6.1", "zendframework/zend-di": "^2.6", "zendframework/zend-filter": "^2.6.1", @@ -34,7 +33,6 @@ "zendframework/zend-json": "^2.6.1", "zendframework/zend-log": "^2.7.1", "zendframework/zend-modulemanager": "^2.7.1", - "zendframework/zend-session": "^2.6.2", "zendframework/zend-serializer": "^2.6.1", "zendframework/zend-text": "^2.6", "zendframework/zend-validator": "^2.6", @@ -56,6 +54,10 @@ "zendframework/zend-log": "Zend\\Log component", "zendframework/zend-modulemanager": "Zend\\ModuleManager component", "zendframework/zend-mvc-console": "zend-mvc-console provides the ability to expose zend-mvc as a console application", + "zendframework/zend-mvc-plugin-fileprg": "To provide Post/Redirect/Get functionality around forms that container file uploads", + "zendframework/zend-mvc-plugin-flashmessenger": "To provide flash messaging capabilities between requests", + "zendframework/zend-mvc-plugin-identity": "To access the authenticated identity (per zend-authentication) in controllers", + "zendframework/zend-mvc-plugin-prg": "To provide Post/Redirect/Get functionality within controllers", "zendframework/zend-serializer": "Zend\\Serializer component", "zendframework/zend-session": "Zend\\Session component for FlashMessenger, PRG, and FPRG plugins", "zendframework/zend-text": "Zend\\Text component", diff --git a/composer.lock b/composer.lock index f7dae209d..ae46a232a 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,8 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "461af74d944100d2b6649c33f63ef9bb", - "content-hash": "ab7905a6a20cd8037d6807363da3fe41", + "hash": "71ded8610a1133ad360ca1152f3c74ee", + "content-hash": "ef3fd706a03fcb3e7b8430e139001841", "packages": [ { "name": "container-interop/container-interop", @@ -1878,16 +1878,16 @@ }, { "name": "symfony/console", - "version": "v2.8.3", + "version": "v2.8.4", "source": { "type": "git", "url": "https://github.com/symfony/console.git", - "reference": "56cc5caf051189720b8de974e4746090aaa10d44" + "reference": "9a5aef5fc0d4eff86853d44202b02be8d5a20154" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/console/zipball/56cc5caf051189720b8de974e4746090aaa10d44", - "reference": "56cc5caf051189720b8de974e4746090aaa10d44", + "url": "https://api.github.com/repos/symfony/console/zipball/9a5aef5fc0d4eff86853d44202b02be8d5a20154", + "reference": "9a5aef5fc0d4eff86853d44202b02be8d5a20154", "shasum": "" }, "require": { @@ -1934,20 +1934,20 @@ ], "description": "Symfony Console Component", "homepage": "https://symfony.com", - "time": "2016-02-28 16:20:50" + "time": "2016-03-17 09:19:04" }, { "name": "symfony/event-dispatcher", - "version": "v2.8.3", + "version": "v2.8.4", "source": { "type": "git", "url": "https://github.com/symfony/event-dispatcher.git", - "reference": "78c468665c9568c3faaa9c416a7134308f2d85c3" + "reference": "47d2d8cade9b1c3987573d2943bb9352536cdb87" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/event-dispatcher/zipball/78c468665c9568c3faaa9c416a7134308f2d85c3", - "reference": "78c468665c9568c3faaa9c416a7134308f2d85c3", + "url": "https://api.github.com/repos/symfony/event-dispatcher/zipball/47d2d8cade9b1c3987573d2943bb9352536cdb87", + "reference": "47d2d8cade9b1c3987573d2943bb9352536cdb87", "shasum": "" }, "require": { @@ -1994,20 +1994,20 @@ ], "description": "Symfony EventDispatcher Component", "homepage": "https://symfony.com", - "time": "2016-01-27 05:14:19" + "time": "2016-03-07 14:04:32" }, { "name": "symfony/filesystem", - "version": "v2.8.3", + "version": "v2.8.4", "source": { "type": "git", "url": "https://github.com/symfony/filesystem.git", - "reference": "65cb36b6539b1d446527d60457248f30d045464d" + "reference": "f08ffdf229252cd2745558cb2112df43903bcae4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/filesystem/zipball/65cb36b6539b1d446527d60457248f30d045464d", - "reference": "65cb36b6539b1d446527d60457248f30d045464d", + "url": "https://api.github.com/repos/symfony/filesystem/zipball/f08ffdf229252cd2745558cb2112df43903bcae4", + "reference": "f08ffdf229252cd2745558cb2112df43903bcae4", "shasum": "" }, "require": { @@ -2043,20 +2043,20 @@ ], "description": "Symfony Filesystem Component", "homepage": "https://symfony.com", - "time": "2016-02-22 15:02:30" + "time": "2016-03-27 10:20:16" }, { "name": "symfony/finder", - "version": "v2.8.3", + "version": "v2.8.4", "source": { "type": "git", "url": "https://github.com/symfony/finder.git", - "reference": "877bb4b16ea573cc8c024e9590888fcf7eb7e0f7" + "reference": "ca24cf2cd4e3826f571e0067e535758e73807aa1" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/finder/zipball/877bb4b16ea573cc8c024e9590888fcf7eb7e0f7", - "reference": "877bb4b16ea573cc8c024e9590888fcf7eb7e0f7", + "url": "https://api.github.com/repos/symfony/finder/zipball/ca24cf2cd4e3826f571e0067e535758e73807aa1", + "reference": "ca24cf2cd4e3826f571e0067e535758e73807aa1", "shasum": "" }, "require": { @@ -2092,7 +2092,7 @@ ], "description": "Symfony Finder Component", "homepage": "https://symfony.com", - "time": "2016-02-22 16:12:45" + "time": "2016-03-10 10:53:53" }, { "name": "symfony/polyfill-mbstring", @@ -2155,16 +2155,16 @@ }, { "name": "symfony/process", - "version": "v2.8.3", + "version": "v2.8.4", "source": { "type": "git", "url": "https://github.com/symfony/process.git", - "reference": "7dedd5b60550f33dca16dd7e94ef8aca8b67bbfe" + "reference": "fb467471952ef5cf8497c029980e556b47545333" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/process/zipball/7dedd5b60550f33dca16dd7e94ef8aca8b67bbfe", - "reference": "7dedd5b60550f33dca16dd7e94ef8aca8b67bbfe", + "url": "https://api.github.com/repos/symfony/process/zipball/fb467471952ef5cf8497c029980e556b47545333", + "reference": "fb467471952ef5cf8497c029980e556b47545333", "shasum": "" }, "require": { @@ -2200,20 +2200,20 @@ ], "description": "Symfony Process Component", "homepage": "https://symfony.com", - "time": "2016-02-02 13:33:15" + "time": "2016-03-23 13:11:46" }, { "name": "symfony/stopwatch", - "version": "v2.8.3", + "version": "v2.8.4", "source": { "type": "git", "url": "https://github.com/symfony/stopwatch.git", - "reference": "e3bc8e2a984f4382690a438c8bb650f3ffd71e73" + "reference": "9e24824b2a9a16e17ab997f61d70bc03948e434e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/stopwatch/zipball/e3bc8e2a984f4382690a438c8bb650f3ffd71e73", - "reference": "e3bc8e2a984f4382690a438c8bb650f3ffd71e73", + "url": "https://api.github.com/repos/symfony/stopwatch/zipball/9e24824b2a9a16e17ab997f61d70bc03948e434e", + "reference": "9e24824b2a9a16e17ab997f61d70bc03948e434e", "shasum": "" }, "require": { @@ -2249,29 +2249,29 @@ ], "description": "Symfony Stopwatch Component", "homepage": "https://symfony.com", - "time": "2016-01-03 15:33:41" + "time": "2016-03-04 07:54:35" }, { "name": "symfony/yaml", - "version": "v3.0.3", + "version": "v2.8.4", "source": { "type": "git", "url": "https://github.com/symfony/yaml.git", - "reference": "b5ba64cd67ecd6887f63868fa781ca094bd1377c" + "reference": "584e52cb8f788a887553ba82db6caacb1d6260bb" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/yaml/zipball/b5ba64cd67ecd6887f63868fa781ca094bd1377c", - "reference": "b5ba64cd67ecd6887f63868fa781ca094bd1377c", + "url": "https://api.github.com/repos/symfony/yaml/zipball/584e52cb8f788a887553ba82db6caacb1d6260bb", + "reference": "584e52cb8f788a887553ba82db6caacb1d6260bb", "shasum": "" }, "require": { - "php": ">=5.5.9" + "php": ">=5.3.9" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "3.0-dev" + "dev-master": "2.8-dev" } }, "autoload": { @@ -2298,7 +2298,7 @@ ], "description": "Symfony Yaml Component", "homepage": "https://symfony.com", - "time": "2016-02-23 15:16:06" + "time": "2016-03-04 07:54:35" }, { "name": "zendframework/zend-authentication", diff --git a/doc/book/migration/to-v3-0.md b/doc/book/migration/to-v3-0.md index 2c4fd1e24..f1090a361 100644 --- a/doc/book/migration/to-v3-0.md +++ b/doc/book/migration/to-v3-0.md @@ -86,6 +86,51 @@ the [component installer as detailed above](#dependency-reduction) before installing the plugins, to automate injection into your application configuration. +### fileprg() + +The `fileprg()` plugin is now provided via the +[zend-mvc-plugin-fileprg](https://github.com/zendframework/zend-mvc-plugin-fileprg) +component. + +```bash +$ composer require zendframework/zend-mvc-plugin-fileprg +``` + +`Zend\Mvc\Controller\Plugin\FilePostRedirectGet` becomes +`Zend\Mvc\Plugin\FilePrg\FilePostRedirectGet`. However, it is still mapped as +`fileprg()`. + +### flashMessenger() + +The `flashMessenger()` plugin is now provided via the +[zend-mvc-plugin-flashmessenger](https://github.com/zendframework/zend-mvc-plugin-flashmessenger) +component. + +```bash +$ composer require zendframework/zend-mvc-plugin-flashmessenger +``` + +`Zend\Mvc\Controller\Plugin\FlashMessenger` becomes +`Zend\Mvc\Plugin\FlashMessenger\FlashMessenger`. However, it is still mapped as +`flashMessenger()` and `flashmessenger()`. + +### identity() + +The `identity()` plugin is now provided via the +[zend-mvc-plugin-identity](https://github.com/zendframework/zend-mvc-plugin-identity) +component. + +```bash +$ composer require zendframework/zend-mvc-plugin-identity +``` + +`Zend\Mvc\Controller\Plugin\Identity` becomes +`Zend\Mvc\Plugin\Identity\Identity`. However, it is still mapped as +`identity()`. + +Additionally, `Zend\Mvc\Controller\Plugin\Service\IdentityFactory` now becomes +`Zend\Mvc\Plugin\Identity\IdentityFactory`. + ### prg() The `prg()` plugin is now provided via the diff --git a/doc/book/plugins.md b/doc/book/plugins.md index e25b1f84b..8f9af894c 100644 --- a/doc/book/plugins.md +++ b/doc/book/plugins.md @@ -8,13 +8,9 @@ your own custom plugins with the manager. The built-in plugins are: - [Zend\\Mvc\\Controller\\Plugin\\AcceptableViewModelSelector](#acceptableviewmodelselector-plugin) -- [Zend\\Mvc\\Controller\\Plugin\\FlashMessenger](#flashmessenger-plugin) - [Zend\\Mvc\\Controller\\Plugin\\Forward](#forward-plugin) -- [Zend\\Mvc\\Controller\\Plugin\\Identity](#identity-plugin) - [Zend\\Mvc\\Controller\\Plugin\\Layout](#layout-plugin) - [Zend\\Mvc\\Controller\\Plugin\\Params](#params-plugin) -- [Zend\\Mvc\\Controller\\Plugin\\PostRedirectGet](#postredirectget-plugin) -- [Zend\\Mvc\\Controller\\Plugin\\FilePostRedirectGet](#file-postredirectget-plugin) - [Zend\\Mvc\\Controller\\Plugin\\Redirect](#redirect-plugin) - [Zend\\Mvc\\Controller\\Plugin\\Url](#url-plugin) @@ -73,105 +69,6 @@ The above would return a standard `Zend\View\Model\ViewModel` instance if the criteria is not met, and the specified view model types if the specific criteria is met. Rules are matched in order, with the first match "winning." -## FlashMessenger Plugin - -The `FlashMessenger` is a plugin designed to create and retrieve self-expiring, -session-based messages. It exposes a number of methods: - -- `setSessionManager(Zend\Session\ManagerInterface $manager) : FlashMessenger`: - Allows you to specify an alternate session manager, if desired. - -- `getSessionManager() : Zend\Session\ManagerInterface`: Allows you to retrieve - the session manager registered. - -- `getContainer() : Zend\Session\Container`: Returns the - `Zend\Session\Container` instance in which the flash messages are stored. - -- `setNamespace(string $namespace = 'default') : FlashMessenger`: - Allows you to specify a specific namespace in the container in which to store - or from which to retrieve flash messages. - -- `getNamespace() : string`: retrieves the name of the flash message namespace. - -- `addMessage(string $message) : FlashMessenger`: Allows you to add a message to - the current namespace of the session container. - -- `hasMessages() : bool`: Lets you determine if there are any flash messages - from the current namespace in the session container. - -- `getMessages() : array`: Retrieves the flash messages from the current - namespace of the session container - -- `clearMessages() : bool`: Clears all flash messages in current namespace of - the session container. Returns `true` if messages were cleared, `false` if - none existed. - -- `hasCurrentMessages() : bool`: Indicates whether any messages were added - during the current request. - -- `getCurrentMessages() : array`: Retrieves any messages added during the - current request. - -- `clearCurrentMessages() : bool`: Removes any messages added during the current - request. Returns `true` if current messages were cleared, `false` if none - existed. - -- `clearMessagesFromContainer() : bool`: Clear all messages from the container. - Returns `true` if any messages were cleared, `false` if none existed. - -This plugin also provides four meaningful namespaces, namely: `INFO`, `ERROR`, -`WARNING`, and `SUCCESS`. The following functions are related to these -namespaces: - -- `addInfoMessage(string $message): FlashMessenger`: Add a message to "info" - namespace. - -- `hasCurrentInfoMessages() : bool`: Check to see if messages have been added to - "info" namespace within this request. - -- `addWarningMessage(string $message) : FlashMessenger`: Add a message to - "warning" namespace. - -- `hasCurrentWarningMessages() : bool`: Check to see if messages have been added - to "warning" namespace within this request. - -- `addErrorMessage(string $message) : FlashMessenger`: Add a message to "error" - namespace. - -- `hasCurrentErrorMessages() : bool`: Check to see if messages have been added - to "error" namespace within this request. - -- `addSuccessMessage(string $message) : FlashMessenger`: Add a message to - "success" namespace. - -- `hasCurrentSuccessMessages() :bool`: Check to see if messages have been added - to "success" namespace within this request. - -Additionally, the `FlashMessenger` implements both `IteratorAggregate` and -`Countable`, allowing you to iterate over and count the flash messages in the -current namespace within the session container. - -### Examples - -```php -public function processAction() -{ - // ... do some work ... - $this->flashMessenger()->addMessage('You are now logged in.'); - return $this->redirect()->toRoute('user-success'); -} - -public function successAction() -{ - $return = ['success' => true]; - $flashMessenger = $this->flashMessenger(); - if ($flashMessenger->hasMessages()) { - $return['messages'] = $flashMessenger->getMessages(); - } - return $return; -} -``` - ## Forward Plugin Occasionally, you may want to dispatch additional controllers from within the @@ -207,58 +104,6 @@ return [ ]; ``` -## Identity Plugin - -The `Identity` plugin allows retrieving the identity from the -`AuthenticationService`. - -For the `Identity` plugin to work, a `Zend\Authentication\AuthenticationService` -name or alias must be defined and recognized by the `ServiceManager`. - -`Identity` returns the identity in the `AuthenticationService` or `null` if no -identity is available. - -As an example: - -```php -public function testAction() -{ - if ($user = $this->identity()) { - // someone is logged ! - } else { - // not logged in - } -} -``` - -When invoked, the `Identity` plugin will look for a service by the name or alias -`Zend\Authentication\AuthenticationService` in the `ServiceManager`. You can -provide this service to the `ServiceManager` in a configuration file: - -```php -// In a configuration file... -use Zend\Authentication\AuthenticationService; - -return [ - 'service_manager' => [ - 'aliases' => [ - AuthenticationService::class => 'my_auth_service', - ], - 'invokables' => [ - 'my_auth_service' => AuthenticationService::class, - ], - ], -]; -``` - -The `Identity` plugin exposes two methods: - -- `setAuthenticationService(AuthenticationService $authenticationService) : void`: - Sets the authentication service instance to be used by the plugin. - -- `getAuthenticationService() : AuthenticationService`: Retrieves the current - authentication service instance if any is attached. - ## Layout Plugin The `Layout` plugin allows changing layout templates from within controller actions. @@ -314,127 +159,6 @@ $this->params()->fromRoute('param', $default); $this->params('param', $default); ``` -## Post/Redirect/Get Plugin - -When a user sends a POST request (e.g. after submitting a form), their browser -will try to protect them from sending the POST again, breaking the back button, -causing browser warnings and pop-ups, and sometimes reposting the form. Instead, -when receiving a POST, we should store the data in a session container and -redirect the user to a GET request. - -This plugin can be invoked with two arguments: - -- `$redirect`, a string containing the redirect location, which can either be a - named route or a URL, based on the contents of the second parameter. -- `$redirectToUrl`, a boolean that when set to `TRUE`, causes the first - parameter to be treated as a URL instead of a route name (this is required - when redirecting to a URL instead of a route). This argument defaults to - `false`. - -When no arguments are provided, the current matched route is used. - -### Example Usage - -```php -// Pass in the route/url you want to redirect to after the POST -$prg = $this->prg('/user/register', true); - -if ($prg instanceof \Zend\Http\PhpEnvironment\Response) { - // Returned a response to redirect us. - return $prg; -} - -if ($prg === false) { - // This wasn't a POST request, but there were no params in the flash - // messenger; this is probably the first time the form was loaded. - return ['form' => $myForm]; -} - -// $prg is an array containing the POST params from the previous request -$form->setData($prg); - -// ... your form processing code here -``` - -## File Post/Redirect/Get Plugin - -While similar to the [Post/Redirect/Get Plugin](#postredirectget-plugin), -the File PRG Plugin will work for forms with file inputs. The difference is in -the behavior: The File PRG Plugin will interact directly with your form instance -and the file inputs, rather than *only* returning the POST params from the -previous request. - -By interacting directly with the form, the File PRG Plugin will turn off any -file inputs `required` flags for already uploaded files (for a partially valid -form state), as well as run the file input filters to move the uploaded files -into a new location (configured by the user). - -> ### Files must be relocated on upload -> -> You **must** attach a filter for moving the uploaded files to a new location, such as the -> [RenameUpload Filter](http://zendframework.github.io/zend-filter/file/#renameupload), -> or else your files will be removed upon the redirect. - -This plugin is invoked with three arguments: - -- `$form`: the form instance. -- `$redirect`: (Optional) a string containing the redirect location, which can - either be a named route or a URL, based on the contents of the third - parameter. If this argument is not provided, it will default to the current - matched route. -- `$redirectToUrl`: (Optional) a boolean that when set to `TRUE`, causes the - second parameter to be treated as a URL instead of a route name (this is - required when redirecting to a URL instead of a route). This argument defaults - to `false`. - -### Example Usage - -```php -$myForm = new Zend\Form\Form('my-form'); -$myForm->add([ - 'type' => 'Zend\Form\Element\File', - 'name' => 'file', -]); - -// NOTE: Without a filter to move the file, -// our files will disappear between the requests -$myForm->getInputFilter()->getFilterChain()->attach( - new Zend\Filter\File\RenameUpload([ - 'target' => './data/tmpuploads/file', - 'randomize' => true, - ]) -); - -// Pass in the form and optional the route/url you want to redirect to after the POST -$prg = $this->fileprg($myForm, '/user/profile-pic', true); - -if ($prg instanceof \Zend\Http\PhpEnvironment\Response) { - // Returned a response to redirect us. - return $prg; -} - -if ($prg === false) { - // First time the form was loaded. - return array('form' => $myForm); -} - -// Form was submitted. -// $prg is now an array containing the POST params from the previous request, -// but we don't have to apply it to the form since that has already been done. - -// Process the form -if ($form->isValid()) { - // ...Save the form... - return $this->redirect()->toRoute('/user/profile-pic/success'); -} - -// Form not valid, but file uploads might be valid and uploaded -$fileErrors = $form->get('file')->getMessages(); -if (empty($fileErrors)) { - $tempFile = $form->get('file')->getValue(); -} -``` - ## Redirect Plugin Redirections are quite common operations within applications. If done manually, diff --git a/src/Controller/AbstractController.php b/src/Controller/AbstractController.php index 5fd1c062a..80593cf14 100644 --- a/src/Controller/AbstractController.php +++ b/src/Controller/AbstractController.php @@ -29,15 +29,9 @@ * Convenience methods for pre-built plugins (@see __call): * * @method \Zend\View\Model\ModelInterface acceptableViewModelSelector(array $matchAgainst = null, bool $returnDefault = true, \Zend\Http\Header\Accept\FieldValuePart\AbstractFieldValuePart $resultReference = null) - * @method bool|array|\Zend\Http\Response fileprg(\Zend\Form\FormInterface $form, $redirect = null, $redirectToUrl = false) - * @method bool|array|\Zend\Http\Response filePostRedirectGet(\Zend\Form\FormInterface $form, $redirect = null, $redirectToUrl = false) - * @method \Zend\Mvc\Controller\Plugin\FlashMessenger flashMessenger() * @method \Zend\Mvc\Controller\Plugin\Forward forward() - * @method mixed|null identity() * @method \Zend\Mvc\Controller\Plugin\Layout|\Zend\View\Model\ModelInterface layout(string $template = null) * @method \Zend\Mvc\Controller\Plugin\Params|mixed params(string $param = null, mixed $default = null) - * @method \Zend\Http\Response|array prg(string $redirect = null, bool $redirectToUrl = false) - * @method \Zend\Http\Response|array postRedirectGet(string $redirect = null, bool $redirectToUrl = false) * @method \Zend\Mvc\Controller\Plugin\Redirect redirect() * @method \Zend\Mvc\Controller\Plugin\Url url() * @method \Zend\View\Model\ViewModel createHttpNotFoundModel(Response $response) diff --git a/src/Controller/Plugin/FilePostRedirectGet.php b/src/Controller/Plugin/FilePostRedirectGet.php deleted file mode 100644 index 02fe3a415..000000000 --- a/src/Controller/Plugin/FilePostRedirectGet.php +++ /dev/null @@ -1,340 +0,0 @@ - /valid/target/path'. - * This is so the files are moved to a new location between requests. - * If this filter is not added, the temporary upload files will disappear - * between requests. - */ -class FilePostRedirectGet extends AbstractPlugin -{ - /** - * @var Container - */ - protected $sessionContainer; - - /** - * @param FormInterface $form - * @param string $redirect Route or URL string (default: current route) - * @param bool $redirectToUrl Use $redirect as a URL string (default: false) - * @return bool|array|Response - */ - public function __invoke(FormInterface $form, $redirect = null, $redirectToUrl = false) - { - $request = $this->getController()->getRequest(); - if ($request->isPost()) { - return $this->handlePostRequest($form, $redirect, $redirectToUrl); - } else { - return $this->handleGetRequest($form); - } - } - - /** - * @param FormInterface $form - * @param string $redirect Route or URL string (default: current route) - * @param bool $redirectToUrl Use $redirect as a URL string (default: false) - * @return Response - */ - protected function handlePostRequest(FormInterface $form, $redirect, $redirectToUrl) - { - $container = $this->getSessionContainer(); - $request = $this->getController()->getRequest(); - $postFiles = $request->getFiles()->toArray(); - $postOther = $request->getPost()->toArray(); - $post = ArrayUtils::merge($postOther, $postFiles, true); - - // Fill form with the data first, collections may alter the form/filter structure - $form->setData($post); - - // Change required flag to false for any previously uploaded files - $inputFilter = $form->getInputFilter(); - $previousFiles = ($container->files) ?: []; - $this->traverseInputs( - $inputFilter, - $previousFiles, - function ($input, $value) { - if ($input instanceof FileInput) { - $input->setRequired(false); - } - return $value; - } - ); - - // Run the form validations/filters and retrieve any errors - $isValid = $form->isValid(); - $data = $form->getData(FormInterface::VALUES_AS_ARRAY); - $errors = (!$isValid) ? $form->getMessages() : null; - - // Merge and replace previous files with new valid files - $prevFileData = $this->getEmptyUploadData($inputFilter, $previousFiles); - $newFileData = $this->getNonEmptyUploadData($inputFilter, $data); - $postFiles = ArrayUtils::merge( - $prevFileData ?: [], - $newFileData ?: [], - true - ); - $post = ArrayUtils::merge($postOther, $postFiles, true); - - // Save form data in session - $container->setExpirationHops(1, ['post', 'errors', 'isValid']); - $container->post = $post; - $container->errors = $errors; - $container->isValid = $isValid; - $container->files = $postFiles; - - return $this->redirect($redirect, $redirectToUrl); - } - - /** - * @param FormInterface $form - * @return bool|array - */ - protected function handleGetRequest(FormInterface $form) - { - $container = $this->getSessionContainer(); - if (null === $container->post) { - // No previous post, bail early - unset($container->files); - return false; - } - - // Collect data from session - $post = $container->post; - $errors = $container->errors; - $isValid = $container->isValid; - unset($container->post); - unset($container->errors); - unset($container->isValid); - - // Fill form with the data first, collections may alter the form/filter structure - $form->setData($post); - - // Remove File Input validators and filters on previously uploaded files - // in case $form->isValid() or $form->bindValues() is run - $inputFilter = $form->getInputFilter(); - $this->traverseInputs( - $inputFilter, - $post, - function ($input, $value) { - if ($input instanceof FileInput) { - $input->setAutoPrependUploadValidator(false) - ->setValidatorChain(new ValidatorChain()) - ->setFilterChain(new FilterChain); - } - return $value; - } - ); - - // set previous state - $form->isValid(); // re-validate to bind values - if (null !== $errors) { - $form->setMessages($errors); // overwrite messages - } - $this->setProtectedFormProperty($form, 'isValid', $isValid); // force previous state - - // Clear previous files from session data if form was valid - if ($isValid) { - unset($container->files); - } - - return $post; - } - - /** - * @return Container - */ - public function getSessionContainer() - { - if (!isset($this->sessionContainer)) { - $this->sessionContainer = new Container('file_prg_post1'); - } - return $this->sessionContainer; - } - - /** - * @param Container $container - * @return FilePostRedirectGet - */ - public function setSessionContainer(Container $container) - { - $this->sessionContainer = $container; - return $this; - } - - /** - * @param FormInterface $form - * @param string $property - * @param mixed $value - * @return FilePostRedirectGet - */ - protected function setProtectedFormProperty(FormInterface $form, $property, $value) - { - $formClass = new \ReflectionClass($form); - $property = $formClass->getProperty($property); - $property->setAccessible(true); - $property->setValue($form, $value); - return $this; - } - - /** - * Traverse the InputFilter and run a callback against each Input and associated value - * - * @param InputFilterInterface $inputFilter - * @param array $values - * @param callable $callback - * @return array|null - */ - protected function traverseInputs(InputFilterInterface $inputFilter, $values, $callback) - { - $returnValues = null; - foreach ($values as $name => $value) { - if (!$inputFilter->has($name)) { - continue; - } - - $input = $inputFilter->get($name); - if ($input instanceof InputFilterInterface && is_array($value)) { - $retVal = $this->traverseInputs($input, $value, $callback); - if (null !== $retVal) { - $returnValues[$name] = $retVal; - } - continue; - } - - $retVal = $callback($input, $value); - if (null !== $retVal) { - $returnValues[$name] = $retVal; - } - } - return $returnValues; - } - - /** - * Traverse the InputFilter and only return the data of FileInputs that have an upload - * - * @param InputFilterInterface $inputFilter - * @param array $data - * @return array - */ - protected function getNonEmptyUploadData(InputFilterInterface $inputFilter, $data) - { - return $this->traverseInputs( - $inputFilter, - $data, - function ($input, $value) { - $messages = $input->getMessages(); - if (is_array($value) && $input instanceof FileInput && empty($messages)) { - $rawValue = $input->getRawValue(); - if ( - (isset($rawValue['error']) && $rawValue['error'] !== UPLOAD_ERR_NO_FILE) - || (isset($rawValue[0]['error']) && $rawValue[0]['error'] !== UPLOAD_ERR_NO_FILE) - ) { - return $value; - } - } - return; - } - ); - } - - /** - * Traverse the InputFilter and only return the data of FileInputs that are empty - * - * @param InputFilterInterface $inputFilter - * @param array $data - * @return array - */ - protected function getEmptyUploadData(InputFilterInterface $inputFilter, $data) - { - return $this->traverseInputs( - $inputFilter, - $data, - function ($input, $value) { - $messages = $input->getMessages(); - if (is_array($value) && $input instanceof FileInput && empty($messages)) { - $rawValue = $input->getRawValue(); - if ((isset($rawValue['error']) && $rawValue['error'] === UPLOAD_ERR_NO_FILE) - || (isset($rawValue[0]['error']) && $rawValue[0]['error'] === UPLOAD_ERR_NO_FILE) - ) { - return $value; - } - } - return; - } - ); - } - - /** - * TODO: Good candidate for traits method in PHP 5.4 with PostRedirectGet plugin - * - * @param string $redirect - * @param bool $redirectToUrl - * @return Response - * @throws \Zend\Mvc\Exception\RuntimeException - */ - protected function redirect($redirect, $redirectToUrl) - { - $controller = $this->getController(); - $params = []; - $options = []; - $reuseMatchedParams = false; - - if (null === $redirect) { - $routeMatch = $controller->getEvent()->getRouteMatch(); - - $redirect = $routeMatch->getMatchedRouteName(); - //null indicates to redirect for self. - $reuseMatchedParams = true; - } - - if (method_exists($controller, 'getPluginManager')) { - // get the redirect plugin from the plugin manager - $redirector = $controller->getPluginManager()->get('Redirect'); - } else { - /* - * If the user wants to redirect to a route, the redirector has to come - * from the plugin manager -- otherwise no router will be injected - */ - if ($redirectToUrl === false) { - throw new RuntimeException('Could not redirect to a route without a router'); - } - - $redirector = new Redirect(); - } - - if ($redirectToUrl === false) { - $response = $redirector->toRoute($redirect, $params, $options, $reuseMatchedParams); - $response->setStatusCode(303); - return $response; - } - - $response = $redirector->toUrl($redirect); - $response->setStatusCode(303); - - return $response; - } -} diff --git a/src/Controller/Plugin/FlashMessenger.php b/src/Controller/Plugin/FlashMessenger.php deleted file mode 100644 index c2866ae41..000000000 --- a/src/Controller/Plugin/FlashMessenger.php +++ /dev/null @@ -1,663 +0,0 @@ -session = $manager; - - return $this; - } - - /** - * Retrieve the session manager - * - * If none composed, lazy-loads a SessionManager instance - * - * @return Manager - */ - public function getSessionManager() - { - if (!$this->session instanceof Manager) { - $this->setSessionManager(Container::getDefaultManager()); - } - - return $this->session; - } - - /** - * Get session container for flash messages - * - * @return Container - */ - public function getContainer() - { - if ($this->container instanceof Container) { - return $this->container; - } - - $manager = $this->getSessionManager(); - $this->container = new Container('FlashMessenger', $manager); - - return $this->container; - } - - /** - * Change the namespace messages are added to - * - * Useful for per action controller messaging between requests - * - * @param string $namespace - * @return FlashMessenger Provides a fluent interface - */ - public function setNamespace($namespace = 'default') - { - $this->namespace = $namespace; - - return $this; - } - - /** - * Get the message namespace - * - * @return string - */ - public function getNamespace() - { - return $this->namespace; - } - - /** - * Add a message - * - * @param string $message - * @param null|string $namespace - * @param null|int $hops - * @return FlashMessenger Provides a fluent interface - */ - public function addMessage($message, $namespace = null, $hops = 1) - { - $container = $this->getContainer(); - - if (null === $namespace) { - $namespace = $this->getNamespace(); - } - - if (! $this->messageAdded) { - $this->getMessagesFromContainer(); - $container->setExpirationHops($hops, null); - } - - if (! isset($container->{$namespace}) - || ! $container->{$namespace} instanceof SplQueue - ) { - $container->{$namespace} = new SplQueue(); - } - - $container->{$namespace}->push($message); - - $this->messageAdded = true; - - return $this; - } - - /** - * Add a message with "info" type - * - * @param string $message - * @return FlashMessenger - */ - public function addInfoMessage($message) - { - $this->addMessage($message, self::NAMESPACE_INFO); - - return $this; - } - - /** - * Add a message with "success" type - * - * @param string $message - * @return FlashMessenger - */ - public function addSuccessMessage($message) - { - $this->addMessage($message, self::NAMESPACE_SUCCESS); - - return $this; - } - - /** - * Add a message with "warning" type - * - * @param string $message - * @return FlashMessenger - */ - public function addWarningMessage($message) - { - $this->addMessage($message, self::NAMESPACE_WARNING); - - return $this; - } - - /** - * Add a message with "error" type - * - * @param string $message - * @return FlashMessenger - */ - public function addErrorMessage($message) - { - $this->addMessage($message, self::NAMESPACE_ERROR); - - return $this; - } - - /** - * Whether a specific namespace has messages - * - * @param string $namespace - * @return bool - */ - public function hasMessages($namespace = null) - { - if (null === $namespace) { - $namespace = $this->getNamespace(); - } - - $this->getMessagesFromContainer(); - - return isset($this->messages[$namespace]); - } - - /** - * Whether "info" namespace has messages - * - * @return bool - */ - public function hasInfoMessages() - { - return $this->hasMessages(self::NAMESPACE_INFO); - } - - /** - * Whether "success" namespace has messages - * - * @return bool - */ - public function hasSuccessMessages() - { - return $this->hasMessages(self::NAMESPACE_SUCCESS); - } - - /** - * Whether "warning" namespace has messages - * - * @return bool - */ - public function hasWarningMessages() - { - return $this->hasMessages(self::NAMESPACE_WARNING); - } - - /** - * Whether "error" namespace has messages - * - * @return bool - */ - public function hasErrorMessages() - { - return $this->hasMessages(self::NAMESPACE_ERROR); - } - - /** - * Get messages from a specific namespace - * - * @param string $namespace - * @return array - */ - public function getMessages($namespace = null) - { - if (null === $namespace) { - $namespace = $this->getNamespace(); - } - - if ($this->hasMessages($namespace)) { - return $this->messages[$namespace]->toArray(); - } - - return []; - } - - /** - * Get messages from "info" namespace - * - * @return array - */ - public function getInfoMessages() - { - return $this->getMessages(self::NAMESPACE_INFO); - } - - /** - * Get messages from "success" namespace - * - * @return array - */ - public function getSuccessMessages() - { - return $this->getMessages(self::NAMESPACE_SUCCESS); - } - - /** - * Get messages from "warning" namespace - * - * @return array - */ - public function getWarningMessages() - { - return $this->getMessages(self::NAMESPACE_WARNING); - } - - /** - * Get messages from "error" namespace - * - * @return array - */ - public function getErrorMessages() - { - return $this->getMessages(self::NAMESPACE_ERROR); - } - - /** - * Clear all messages from the previous request & current namespace - * - * @param string $namespace - * @return bool True if messages were cleared, false if none existed - */ - public function clearMessages($namespace = null) - { - if (null === $namespace) { - $namespace = $this->getNamespace(); - } - - if ($this->hasMessages($namespace)) { - unset($this->messages[$namespace]); - - return true; - } - - return false; - } - - /** - * Clear all messages from specific namespace - * - * @param string $namespaceToClear - * @return bool True if messages were cleared, false if none existed - */ - public function clearMessagesFromNamespace($namespaceToClear) - { - return $this->clearMessages($namespaceToClear); - } - - /** - * Clear all messages from the container - * - * @return bool True if messages were cleared, false if none existed - */ - public function clearMessagesFromContainer() - { - $this->getMessagesFromContainer(); - if (empty($this->messages)) { - return false; - } - unset($this->messages); - $this->messages = []; - - return true; - } - - /** - * Check to see if messages have been added to the current - * namespace within this request - * - * @param string $namespace - * @return bool - */ - public function hasCurrentMessages($namespace = null) - { - $container = $this->getContainer(); - if (null === $namespace) { - $namespace = $this->getNamespace(); - } - - return isset($container->{$namespace}); - } - - /** - * Check to see if messages have been added to "info" - * namespace within this request - * - * @return bool - */ - public function hasCurrentInfoMessages() - { - return $this->hasCurrentMessages(self::NAMESPACE_INFO); - } - - /** - * Check to see if messages have been added to "success" - * namespace within this request - * - * @return bool - */ - public function hasCurrentSuccessMessages() - { - return $this->hasCurrentMessages(self::NAMESPACE_SUCCESS); - } - - /** - * Check to see if messages have been added to "warning" - * namespace within this request - * - * @return bool - */ - public function hasCurrentWarningMessages() - { - return $this->hasCurrentMessages(self::NAMESPACE_WARNING); - } - - /** - * Check to see if messages have been added to "error" - * namespace within this request - * - * @return bool - */ - public function hasCurrentErrorMessages() - { - return $this->hasCurrentMessages(self::NAMESPACE_ERROR); - } - - /** - * Get messages that have been added to the current - * namespace within this request - * - * @param string $namespace - * @return array - */ - public function getCurrentMessages($namespace = null) - { - if (null === $namespace) { - $namespace = $this->getNamespace(); - } - - if ($this->hasCurrentMessages($namespace)) { - $container = $this->getContainer(); - - return $container->{$namespace}->toArray(); - } - - return []; - } - - /** - * Get messages that have been added to the "info" - * namespace within this request - * - * @return array - */ - public function getCurrentInfoMessages() - { - return $this->getCurrentMessages(self::NAMESPACE_INFO); - } - - /** - * Get messages that have been added to the "success" - * namespace within this request - * - * @return array - */ - public function getCurrentSuccessMessages() - { - return $this->getCurrentMessages(self::NAMESPACE_SUCCESS); - } - - /** - * Get messages that have been added to the "warning" - * namespace within this request - * - * @return array - */ - public function getCurrentWarningMessages() - { - return $this->getCurrentMessages(self::NAMESPACE_WARNING); - } - - /** - * Get messages that have been added to the "error" - * namespace within this request - * - * @return array - */ - public function getCurrentErrorMessages() - { - return $this->getCurrentMessages(self::NAMESPACE_ERROR); - } - - /** - * Get messages that have been added to the current - * namespace in specific namespace - * - * @param string $namespaceToGet - * @return array - */ - public function getCurrentMessagesFromNamespace($namespaceToGet) - { - return $this->getCurrentMessages($namespaceToGet); - } - - /** - * Clear messages from the current request and current namespace - * - * @param string $namespace - * @return bool True if current messages were cleared, false if none existed. - */ - public function clearCurrentMessages($namespace = null) - { - if (null === $namespace) { - $namespace = $this->getNamespace(); - } - - if ($this->hasCurrentMessages($namespace)) { - $container = $this->getContainer(); - unset($container->{$namespace}); - - return true; - } - - return false; - } - - /** - * Clear messages from the current namespace - * - * @param string $namespaceToClear - * @return bool True if current messages were cleared from the given namespace, false if none existed. - */ - public function clearCurrentMessagesFromNamespace($namespaceToClear) - { - return $this->clearCurrentMessages($namespaceToClear); - } - - /** - * Clear messages from the container - * - * @return bool True if current messages were cleared from the container, false if none existed. - */ - public function clearCurrentMessagesFromContainer() - { - $container = $this->getContainer(); - - $namespaces = []; - foreach ($container as $namespace => $messages) { - $namespaces[] = $namespace; - } - - if (empty($namespaces)) { - return false; - } - - foreach ($namespaces as $namespace) { - unset($container->{$namespace}); - } - - return true; - } - - /** - * Complete the IteratorAggregate interface, for iterating - * - * @return ArrayIterator - */ - public function getIterator() - { - if ($this->hasMessages()) { - return new ArrayIterator($this->getMessages()); - } - - return new ArrayIterator(); - } - - /** - * Complete the countable interface - * - * @return int - */ - public function count() - { - if ($this->hasMessages()) { - return count($this->getMessages()); - } - - return 0; - } - - /** - * Get messages from a specific namespace - * - * @param string $namespaceToGet - * @return array - */ - public function getMessagesFromNamespace($namespaceToGet) - { - return $this->getMessages($namespaceToGet); - } - - /** - * Pull messages from the session container - * - * Iterates through the session container, removing messages into the local - * scope. - * - * @return void - */ - protected function getMessagesFromContainer() - { - if (!empty($this->messages) || $this->messageAdded) { - return; - } - - $container = $this->getContainer(); - - $namespaces = []; - foreach ($container as $namespace => $messages) { - $this->messages[$namespace] = $messages; - $namespaces[] = $namespace; - } - - foreach ($namespaces as $namespace) { - unset($container->{$namespace}); - } - } -} diff --git a/src/Controller/Plugin/Identity.php b/src/Controller/Plugin/Identity.php deleted file mode 100644 index a420b191a..000000000 --- a/src/Controller/Plugin/Identity.php +++ /dev/null @@ -1,59 +0,0 @@ -authenticationService; - } - - /** - * @param AuthenticationServiceInterface $authenticationService - */ - public function setAuthenticationService(AuthenticationServiceInterface $authenticationService) - { - $this->authenticationService = $authenticationService; - } - - /** - * Retrieve the current identity, if any. - * - * If none is present, returns null. - * - * @return mixed|null - * @throws Exception\RuntimeException - */ - public function __invoke() - { - if (!$this->authenticationService instanceof AuthenticationServiceInterface) { - throw new Exception\RuntimeException('No AuthenticationServiceInterface instance provided'); - } - if (!$this->authenticationService->hasIdentity()) { - return; - } - return $this->authenticationService->getIdentity(); - } -} diff --git a/src/Controller/Plugin/Service/IdentityFactory.php b/src/Controller/Plugin/Service/IdentityFactory.php deleted file mode 100644 index 41fb3467e..000000000 --- a/src/Controller/Plugin/Service/IdentityFactory.php +++ /dev/null @@ -1,51 +0,0 @@ -has(AuthenticationService::class)) { - $helper->setAuthenticationService($container->get(AuthenticationService::class)); - } - return $helper; - } - - /** - * Create and return Identity instance - * - * For use with zend-servicemanager v2; proxies to __invoke(). - * - * @param ServiceLocatorInterface $container - * @return Identity - */ - public function createService(ServiceLocatorInterface $container) - { - // Retrieve the parent container when under zend-servicemanager v2 - if (! method_exists($container, 'configure')) { - $container = $container->getServiceLocator() ?: $container; - } - - return $this($container, Identity::class); - } -} diff --git a/src/Controller/PluginManager.php b/src/Controller/PluginManager.php index 8a3e4cea2..9426e7e11 100644 --- a/src/Controller/PluginManager.php +++ b/src/Controller/PluginManager.php @@ -37,17 +37,8 @@ class PluginManager extends AbstractPluginManager 'AcceptableViewModelSelector' => Plugin\AcceptableViewModelSelector::class, 'acceptableViewModelSelector' => Plugin\AcceptableViewModelSelector::class, 'acceptableviewmodelselector' => Plugin\AcceptableViewModelSelector::class, - 'FilePostRedirectGet' => Plugin\FilePostRedirectGet::class, - 'filePostRedirectGet' => Plugin\FilePostRedirectGet::class, - 'filepostredirectget' => Plugin\FilePostRedirectGet::class, - 'fileprg' => Plugin\FilePostRedirectGet::class, - 'FlashMessenger' => Plugin\FlashMessenger::class, - 'flashMessenger' => Plugin\FlashMessenger::class, - 'flashmessenger' => Plugin\FlashMessenger::class, 'Forward' => Plugin\Forward::class, 'forward' => Plugin\Forward::class, - 'Identity' => Plugin\Identity::class, - 'identity' => Plugin\Identity::class, 'Layout' => Plugin\Layout::class, 'layout' => Plugin\Layout::class, 'Params' => Plugin\Params::class, @@ -66,10 +57,7 @@ class PluginManager extends AbstractPluginManager */ protected $factories = [ Plugin\Forward::class => Plugin\Service\ForwardFactory::class, - Plugin\Identity::class => Plugin\Service\IdentityFactory::class, Plugin\AcceptableViewModelSelector::class => InvokableFactory::class, - Plugin\FilePostRedirectGet::class => InvokableFactory::class, - Plugin\FlashMessenger::class => InvokableFactory::class, Plugin\Layout::class => InvokableFactory::class, Plugin\Params::class => InvokableFactory::class, Plugin\Redirect::class => InvokableFactory::class, @@ -79,10 +67,7 @@ class PluginManager extends AbstractPluginManager // v2 normalized names 'zendmvccontrollerpluginforward' => Plugin\Service\ForwardFactory::class, - 'zendmvccontrollerpluginidentity' => Plugin\Service\IdentityFactory::class, 'zendmvccontrollerpluginacceptableviewmodelselector' => InvokableFactory::class, - 'zendmvccontrollerpluginfilepostredirectget' => InvokableFactory::class, - 'zendmvccontrollerpluginflashmessenger' => InvokableFactory::class, 'zendmvccontrollerpluginlayout' => InvokableFactory::class, 'zendmvccontrollerpluginparams' => InvokableFactory::class, 'zendmvccontrollerpluginredirect' => InvokableFactory::class, diff --git a/test/Controller/Plugin/FilePostRedirectGetTest.php b/test/Controller/Plugin/FilePostRedirectGetTest.php deleted file mode 100644 index dd8952d14..000000000 --- a/test/Controller/Plugin/FilePostRedirectGetTest.php +++ /dev/null @@ -1,417 +0,0 @@ -markTestIncomplete('Re-enable when zend-form has been updated to zend-servicemanager v3'); - - $this->form = new Form(); - - $this->collection = new Collection('links', [ - 'count' => 1, - 'allow_add' => true, - 'target_element' => [ - 'type' => 'ZendTest\Mvc\Controller\Plugin\TestAsset\LinksFieldset', - ], - ]); - - $router = new SimpleRouteStack; - $router->addRoute('home', LiteralRoute::factory([ - 'route' => '/', - 'defaults' => [ - 'controller' => 'ZendTest\Mvc\Controller\TestAsset\SampleController', - ] - ])); - - $router->addRoute('sub', SegmentRoute::factory([ - 'route' => '/foo/:param', - 'defaults' => [ - 'param' => 1 - ] - ])); - - $router->addRoute('ctl', SegmentRoute::factory([ - 'route' => '/ctl/:controller', - 'defaults' => [ - '__NAMESPACE__' => 'ZendTest\Mvc\Controller\TestAsset', - ] - ])); - - $this->controller = new SampleController(); - $this->request = new Request(); - $this->event = new MvcEvent(); - $this->routeMatch = new RouteMatch(['controller' => 'controller-sample', 'action' => 'postPage']); - - $this->event->setRequest($this->request); - $this->event->setRouteMatch($this->routeMatch); - $this->event->setRouter($router); - - $this->controller->setEvent($this->event); - } - - public function testReturnsFalseOnIntialGet() - { - $result = $this->controller->dispatch($this->request, $this->response); - $prgResult = $this->controller->fileprg($this->form, 'home'); - - $this->assertFalse($prgResult); - } - - public function testRedirectsToUrlOnPost() - { - $this->request->setMethod('POST'); - $this->request->setPost(new Parameters([ - 'postval1' => 'value' - ])); - - $this->controller->dispatch($this->request, $this->response); - $prgResultUrl = $this->controller->fileprg($this->form, '/test/getPage', true); - - $this->assertInstanceOf('Zend\Http\Response', $prgResultUrl); - $this->assertTrue($prgResultUrl->getHeaders()->has('Location')); - $this->assertEquals('/test/getPage', $prgResultUrl->getHeaders()->get('Location')->getUri()); - $this->assertEquals(303, $prgResultUrl->getStatusCode()); - } - - public function testRedirectsToRouteOnPost() - { - $this->request->setMethod('POST'); - $this->request->setPost(new Parameters([ - 'postval1' => 'value1' - ])); - - $this->controller->dispatch($this->request, $this->response); - $prgResultRoute = $this->controller->fileprg($this->form, 'home'); - - $this->assertInstanceOf('Zend\Http\Response', $prgResultRoute); - $this->assertTrue($prgResultRoute->getHeaders()->has('Location')); - $this->assertEquals('/', $prgResultRoute->getHeaders()->get('Location')->getUri()); - $this->assertEquals(303, $prgResultRoute->getStatusCode()); - } - - /** - * @expectedException Zend\Mvc\Exception\RuntimeException - */ - public function testThrowsExceptionOnRouteWithoutRouter() - { - $controller = $this->controller; - $controller = $controller->getEvent()->setRouter(new SimpleRouteStack); - - $this->request->setMethod('POST'); - $this->request->setPost(new Parameters([ - 'postval1' => 'value' - ])); - - $this->controller->dispatch($this->request, $this->response); - $this->controller->fileprg($this->form, 'some/route'); - } - - public function testNullRouteUsesMatchedRouteName() - { - $this->controller->getEvent()->getRouteMatch()->setMatchedRouteName('home'); - - $this->request->setMethod('POST'); - $this->request->setPost(new Parameters([ - 'postval1' => 'value1' - ])); - - $this->controller->dispatch($this->request, $this->response); - $prgResultRoute = $this->controller->fileprg($this->form); - - $this->assertInstanceOf('Zend\Http\Response', $prgResultRoute); - $this->assertTrue($prgResultRoute->getHeaders()->has('Location')); - $this->assertEquals('/', $prgResultRoute->getHeaders()->get('Location')->getUri()); - $this->assertEquals(303, $prgResultRoute->getStatusCode()); - } - - public function testReuseMatchedParameters() - { - $this->controller->getEvent()->getRouteMatch()->setMatchedRouteName('sub'); - - $this->request->setMethod('POST'); - $this->request->setPost(new Parameters([ - 'postval1' => 'value1' - ])); - - $this->controller->dispatch($this->request, $this->response); - $prgResultRoute = $this->controller->fileprg($this->form); - - $this->assertInstanceOf('Zend\Http\Response', $prgResultRoute); - $this->assertTrue($prgResultRoute->getHeaders()->has('Location')); - $this->assertEquals('/foo/1', $prgResultRoute->getHeaders()->get('Location')->getUri()); - $this->assertEquals(303, $prgResultRoute->getStatusCode()); - } - - public function testReturnsPostOnRedirectGet() - { - // Do POST - $params = [ - 'postval1' => 'value' - ]; - $this->request->setMethod('POST'); - $this->request->setPost(new Parameters($params)); - - $this->form->add([ - 'name' => 'postval1' - ]); - - $this->controller->dispatch($this->request, $this->response); - $prgResultUrl = $this->controller->fileprg($this->form, '/test/getPage', true); - - $this->assertInstanceOf('Zend\Http\Response', $prgResultUrl); - $this->assertTrue($prgResultUrl->getHeaders()->has('Location')); - $this->assertEquals('/test/getPage', $prgResultUrl->getHeaders()->get('Location')->getUri()); - $this->assertEquals(303, $prgResultUrl->getStatusCode()); - - // Do GET - $this->request = new Request(); - $this->controller->dispatch($this->request, $this->response); - $prgResult = $this->controller->fileprg($this->form, '/test/getPage', true); - - $this->assertEquals($params, $prgResult); - $this->assertEquals($params['postval1'], $this->form->get('postval1')->getValue()); - - // Do GET again to make sure data is empty - $this->request = new Request(); - $this->controller->dispatch($this->request, $this->response); - $prgResult = $this->controller->fileprg($this->form, '/test/getPage', true); - - $this->assertFalse($prgResult); - } - - public function testAppliesFormErrorsOnPostRedirectGet() - { - // Do POST - $params = []; - $this->request->setMethod('POST'); - $this->request->setPost(new Parameters($params)); - - $this->form->add([ - 'name' => 'postval1' - ]); - $inputFilter = new InputFilter(); - $inputFilter->add([ - 'name' => 'postval1', - 'required' => true, - ]); - $this->form->setInputFilter($inputFilter); - - $this->controller->dispatch($this->request, $this->response); - $prgResultUrl = $this->controller->fileprg($this->form, '/test/getPage', true); - $this->assertInstanceOf('Zend\Http\Response', $prgResultUrl); - $this->assertTrue($prgResultUrl->getHeaders()->has('Location')); - $this->assertEquals('/test/getPage', $prgResultUrl->getHeaders()->get('Location')->getUri()); - $this->assertEquals(303, $prgResultUrl->getStatusCode()); - - // Do GET - $this->request = new Request(); - $this->controller->dispatch($this->request, $this->response); - $prgResult = $this->controller->fileprg($this->form, '/test/getPage', true); - $messages = $this->form->getMessages(); - - $this->assertEquals($params, $prgResult); - $this->assertNotEmpty($messages['postval1']['isEmpty']); - } - - public function testReuseMatchedParametersWithSegmentController() - { - $expects = '/ctl/sample'; - $this->request->setMethod('POST'); - $this->request->setUri($expects); - $this->request->setPost(new Parameters([ - 'postval1' => 'value1' - ])); - - $routeMatch = $this->event->getRouter()->match($this->request); - $this->event->setRouteMatch($routeMatch); - - $moduleRouteListener = new ModuleRouteListener; - $moduleRouteListener->onRoute($this->event); - - $this->controller->dispatch($this->request, $this->response); - $prgResultRoute = $this->controller->fileprg($this->form); - - $this->assertInstanceOf('Zend\Http\Response', $prgResultRoute); - $this->assertTrue($prgResultRoute->getHeaders()->has('Location')); - $this->assertEquals($expects, $prgResultRoute->getHeaders()->get('Location')->getUri(), 'redirect to the same url'); - $this->assertEquals(303, $prgResultRoute->getStatusCode()); - } - - public function testCollectionInputFilterIsInitializedBeforePluginRetrievesIt() - { - $fieldset = new TestAsset\InputFilterProviderFieldset(); - $collectionSpec = [ - 'name' => 'test_collection', - 'type' => 'collection', - 'options' => [ - 'target_element' => $fieldset - ], - ]; - - $form = new Form(); - $form->add($collectionSpec); - - $postData = [ - 'test_collection' => [ - [ - 'test_field' => 'foo' - ], - [ - 'test_field' => 'bar' - ] - ] - ]; - - // test POST - $request = new Request(); - $request->setMethod('POST'); - $request->setPost(new Parameters($postData)); - $this->controller->dispatch($request, $this->response); - - $this->controller->fileprg($form, '/someurl', true); - - $data = $form->getData(); - - $this->assertArrayHasKey(0, $data['test_collection']); - $this->assertArrayHasKey(1, $data['test_collection']); - - $this->assertSame('FOO', $data['test_collection'][0]['test_field']); - $this->assertSame('BAR', $data['test_collection'][1]['test_field']); - - // now test GET with a brand new form instance - $form = new Form(); - $form->add($collectionSpec); - - $request = new Request(); - $this->controller->dispatch($request, $this->response); - - $this->controller->fileprg($form, '/someurl', true); - - $data = $form->getData(); - - $this->assertArrayHasKey(0, $data['test_collection']); - $this->assertArrayHasKey(1, $data['test_collection']); - - $this->assertSame('FOO', $data['test_collection'][0]['test_field']); - $this->assertSame('BAR', $data['test_collection'][1]['test_field']); - } - - public function testCorrectInputDataMerging() - { - require_once __DIR__ . '/TestAsset/DisablePhpUploadChecks.php'; - require_once __DIR__ . '/TestAsset/DisablePhpMoveUploadedFileChecks.php'; - - $form = new Form(); - $form->add([ - 'name' => 'collection', - 'type' => 'collection', - 'options' => [ - 'target_element' => new TestAsset\TestFieldset('target'), - 'count' => 2, - ] - ]); - - copy(__DIR__ . '/TestAsset/nullfile', __DIR__ . '/TestAsset/nullfile_copy'); - - $request = $this->request; - $request->setMethod('POST'); - $request->setPost(new Parameters([ - 'collection' => [ - 0 => [ - 'text' => 'testvalue1', - ], - 1 => [ - 'text' => '', - ] - ] - ])); - $request->setFiles(new Parameters([ - 'collection' => [ - 0 => [ - 'file' => [ - 'name' => 'test.jpg', - 'type' => 'image/jpeg', - 'size' => 20480, - 'tmp_name' => __DIR__ . '/TestAsset/nullfile_copy', - 'error' => UPLOAD_ERR_OK - ], - ], - ] - ])); - - $this->controller->dispatch($this->request, $this->response); - $this->controller->fileprg($form, '/test/getPage', true); - - $this->assertFalse($form->isValid()); - $data = $form->getData(); - - $this->assertEquals([ - 'collection' => [ - 0 => [ - 'text' => 'testvalue1', - 'file' => [ - 'name' => 'test.jpg', - 'type' => 'image/jpeg', - 'size' => 20480, - 'tmp_name' => __DIR__ . DIRECTORY_SEPARATOR . 'TestAsset' . DIRECTORY_SEPARATOR . 'testfile.jpg', - 'error' => 0 - ], - ], - 1 => [ - 'text' => null, - 'file' => null, - ] - ] - ], $data); - - $this->assertFileExists($data['collection'][0]['file']['tmp_name']); - - unlink($data['collection'][0]['file']['tmp_name']); - - $messages = $form->getMessages(); - $this->assertTrue(isset($messages['collection'][1]['text'][NotEmpty::IS_EMPTY])); - - $requiredFound = false; - foreach ($messages['collection'][1]['file'] as $message) { - if (strpos($message, 'Value is required') === 0) { - $requiredFound = true; - break; - } - } - $this->assertTrue($requiredFound, '"Required" message was not found in validation failure messages'); - } -} diff --git a/test/Controller/Plugin/FlashMessengerTest.php b/test/Controller/Plugin/FlashMessengerTest.php deleted file mode 100644 index 4953aa134..000000000 --- a/test/Controller/Plugin/FlashMessengerTest.php +++ /dev/null @@ -1,293 +0,0 @@ -helper = new FlashMessenger(); - } - - public function seedMessages() - { - $helper = new FlashMessenger(); - $helper->addMessage('foo'); - $helper->addMessage('bar'); - $helper->addInfoMessage('bar-info'); - $helper->addSuccessMessage('bar-success'); - $helper->addErrorMessage('bar-error'); - unset($helper); - } - - public function testComposesSessionManagerByDefault() - { - $helper = new FlashMessenger(); - $session = $helper->getSessionManager(); - $this->assertInstanceOf('Zend\Session\SessionManager', $session); - } - - public function testSessionManagerIsMutable() - { - $session = $this->getMock('Zend\Session\ManagerInterface'); - $currentSessionManager = $this->helper->getSessionManager(); - - $this->helper->setSessionManager($session); - $this->assertSame($session, $this->helper->getSessionManager()); - $this->assertNotSame($currentSessionManager, $this->helper->getSessionManager()); - } - - public function testUsesContainerNamedAfterClass() - { - $container = $this->helper->getContainer(); - $this->assertEquals('FlashMessenger', $container->getName()); - } - - public function testUsesNamespaceNamedDefaultWithNoConfiguration() - { - $this->assertEquals('default', $this->helper->getNamespace()); - } - - public function testNamespaceIsMutable() - { - $this->helper->setNamespace('foo'); - $this->assertEquals('foo', $this->helper->getNamespace()); - } - - public function testMessengerIsEmptyByDefault() - { - $this->assertFalse($this->helper->hasMessages()); - $this->assertFalse($this->helper->hasMessages(FlashMessenger::NAMESPACE_INFO)); - } - - public function testCanAddMessages() - { - $this->helper->addMessage('foo'); - $this->assertTrue($this->helper->hasCurrentMessages()); - - $this->helper->addMessage('bar-info', FlashMessenger::NAMESPACE_INFO); - $this->assertTrue($this->helper->hasCurrentMessages(FlashMessenger::NAMESPACE_INFO)); - } - - public function testAddMessagesDoesNotChangeNamespace() - { - $this->helper->setNamespace('foo'); - $this->helper->addMessage('bar-info', FlashMessenger::NAMESPACE_INFO); - $this->assertEquals('foo', $this->helper->getNamespace()); - } - - public function testAddingMessagesDoesNotChangeCount() - { - $this->assertEquals(0, count($this->helper)); - $this->helper->addMessage('foo'); - $this->assertEquals(0, count($this->helper)); - } - - public function testCanClearMessages() - { - $this->seedMessages(); - $this->assertTrue($this->helper->hasMessages()); - $this->assertTrue($this->helper->hasInfoMessages()); - $this->assertTrue($this->helper->hasMessages(FlashMessenger::NAMESPACE_INFO)); - $this->assertTrue($this->helper->hasSuccessMessages()); - $this->assertTrue($this->helper->hasMessages(FlashMessenger::NAMESPACE_SUCCESS)); - $this->assertTrue($this->helper->hasErrorMessages()); - $this->assertTrue($this->helper->hasMessages(FlashMessenger::NAMESPACE_ERROR)); - - $this->helper->clearMessages(); - $this->assertFalse($this->helper->hasMessages()); - $this->assertTrue($this->helper->hasInfoMessages()); - $this->assertTrue($this->helper->hasMessages(FlashMessenger::NAMESPACE_INFO)); - $this->assertTrue($this->helper->hasSuccessMessages()); - $this->assertTrue($this->helper->hasMessages(FlashMessenger::NAMESPACE_SUCCESS)); - $this->assertTrue($this->helper->hasErrorMessages()); - $this->assertTrue($this->helper->hasMessages(FlashMessenger::NAMESPACE_ERROR)); - - $this->helper->clearMessagesFromNamespace(FlashMessenger::NAMESPACE_INFO); - $this->assertFalse($this->helper->hasInfoMessages()); - $this->assertFalse($this->helper->hasMessages(FlashMessenger::NAMESPACE_INFO)); - - $this->helper->clearMessages(FlashMessenger::NAMESPACE_SUCCESS); - $this->assertFalse($this->helper->hasSuccessMessages()); - $this->assertFalse($this->helper->hasMessages(FlashMessenger::NAMESPACE_SUCCESS)); - - $this->helper->clearMessagesFromContainer(); - $this->assertFalse($this->helper->hasMessages()); - $this->assertFalse($this->helper->hasInfoMessages()); - $this->assertFalse($this->helper->hasMessages(FlashMessenger::NAMESPACE_INFO)); - $this->assertFalse($this->helper->hasSuccessMessages()); - $this->assertFalse($this->helper->hasMessages(FlashMessenger::NAMESPACE_SUCCESS)); - $this->assertFalse($this->helper->hasErrorMessages()); - $this->assertFalse($this->helper->hasMessages(FlashMessenger::NAMESPACE_ERROR)); - } - - public function testCanRetrieveMessages() - { - $this->seedMessages(); - $this->assertTrue($this->helper->hasMessages()); - $messages = $this->helper->getMessages(); - $this->assertEquals(2, count($messages)); - $this->assertContains('foo', $messages); - $this->assertContains('bar', $messages); - - $messages = $this->helper->getInfoMessages(); - $this->assertEquals(1, count($messages)); - $this->assertContains('bar-info', $messages); - - $messages = $this->helper->getMessagesFromNamespace(FlashMessenger::NAMESPACE_INFO); - $this->assertEquals(1, count($messages)); - $this->assertContains('bar-info', $messages); - - $messages = $this->helper->getMessages(FlashMessenger::NAMESPACE_INFO); - $this->assertEquals(1, count($messages)); - $this->assertContains('bar-info', $messages); - - $messages = $this->helper->getSuccessMessages(); - $this->assertEquals(1, count($messages)); - $this->assertContains('bar-success', $messages); - - $messages = $this->helper->getMessagesFromNamespace(FlashMessenger::NAMESPACE_SUCCESS); - $this->assertEquals(1, count($messages)); - $this->assertContains('bar-success', $messages); - - $messages = $this->helper->getMessages(FlashMessenger::NAMESPACE_SUCCESS); - $this->assertEquals(1, count($messages)); - $this->assertContains('bar-success', $messages); - - $messages = $this->helper->getErrorMessages(); - $this->assertEquals(1, count($messages)); - $this->assertContains('bar-error', $messages); - - $messages = $this->helper->getMessagesFromNamespace(FlashMessenger::NAMESPACE_ERROR); - $this->assertEquals(1, count($messages)); - $this->assertContains('bar-error', $messages); - - $messages = $this->helper->getMessages(FlashMessenger::NAMESPACE_ERROR); - $this->assertEquals(1, count($messages)); - $this->assertContains('bar-error', $messages); - } - - public function testCanRetrieveCurrentMessages() - { - $this->seedMessages(); - $messages = $this->helper->getCurrentMessages(); - $this->assertEquals(2, count($messages)); - $this->assertContains('foo', $messages); - $this->assertContains('bar', $messages); - - $messages = $this->helper->getCurrentInfoMessages(); - $this->assertEquals(1, count($messages)); - $this->assertContains('bar-info', $messages); - - $messages = $this->helper->getCurrentMessagesFromNamespace(FlashMessenger::NAMESPACE_INFO); - $this->assertEquals(1, count($messages)); - $this->assertContains('bar-info', $messages); - - $messages = $this->helper->getCurrentMessages(FlashMessenger::NAMESPACE_INFO); - $this->assertEquals(1, count($messages)); - $this->assertContains('bar-info', $messages); - - $messages = $this->helper->getCurrentSuccessMessages(); - $this->assertEquals(1, count($messages)); - $this->assertContains('bar-success', $messages); - - $messages = $this->helper->getCurrentMessagesFromNamespace(FlashMessenger::NAMESPACE_SUCCESS); - $this->assertEquals(1, count($messages)); - $this->assertContains('bar-success', $messages); - - $messages = $this->helper->getCurrentMessages(FlashMessenger::NAMESPACE_SUCCESS); - $this->assertEquals(1, count($messages)); - $this->assertContains('bar-success', $messages); - - $messages = $this->helper->getCurrentErrorMessages(); - $this->assertEquals(1, count($messages)); - $this->assertContains('bar-error', $messages); - - $messages = $this->helper->getCurrentMessagesFromNamespace(FlashMessenger::NAMESPACE_ERROR); - $this->assertEquals(1, count($messages)); - $this->assertContains('bar-error', $messages); - - $messages = $this->helper->getCurrentMessages(FlashMessenger::NAMESPACE_ERROR); - $this->assertEquals(1, count($messages)); - $this->assertContains('bar-error', $messages); - } - - public function testCanClearCurrentMessages() - { - $this->helper->addMessage('foo'); - $this->assertTrue($this->helper->hasCurrentMessages()); - $this->helper->clearCurrentMessages(); - $this->assertFalse($this->helper->hasCurrentMessages()); - - $this->seedMessages(); - $this->assertTrue($this->helper->hasCurrentMessages()); - $this->assertTrue($this->helper->hasCurrentInfoMessages()); - $this->assertTrue($this->helper->hasCurrentMessages(FlashMessenger::NAMESPACE_INFO)); - $this->assertTrue($this->helper->hasCurrentSuccessMessages()); - $this->assertTrue($this->helper->hasCurrentMessages(FlashMessenger::NAMESPACE_SUCCESS)); - $this->assertTrue($this->helper->hasCurrentErrorMessages()); - $this->assertTrue($this->helper->hasCurrentMessages(FlashMessenger::NAMESPACE_ERROR)); - - $this->helper->clearCurrentMessages(); - $this->assertFalse($this->helper->hasCurrentMessages()); - $this->assertTrue($this->helper->hasCurrentInfoMessages()); - $this->assertTrue($this->helper->hasCurrentMessages(FlashMessenger::NAMESPACE_INFO)); - $this->assertTrue($this->helper->hasCurrentSuccessMessages()); - $this->assertTrue($this->helper->hasCurrentMessages(FlashMessenger::NAMESPACE_SUCCESS)); - $this->assertTrue($this->helper->hasCurrentErrorMessages()); - $this->assertTrue($this->helper->hasCurrentMessages(FlashMessenger::NAMESPACE_ERROR)); - - $this->helper->clearCurrentMessagesFromNamespace(FlashMessenger::NAMESPACE_INFO); - $this->assertFalse($this->helper->hasCurrentInfoMessages()); - $this->assertFalse($this->helper->hasCurrentMessages(FlashMessenger::NAMESPACE_INFO)); - - $this->helper->clearCurrentMessages(FlashMessenger::NAMESPACE_SUCCESS); - $this->assertFalse($this->helper->hasCurrentSuccessMessages()); - $this->assertFalse($this->helper->hasCurrentMessages(FlashMessenger::NAMESPACE_SUCCESS)); - - $this->helper->clearCurrentMessagesFromContainer(); - $this->assertFalse($this->helper->hasCurrentMessages()); - $this->assertFalse($this->helper->hasCurrentInfoMessages()); - $this->assertFalse($this->helper->hasCurrentMessages(FlashMessenger::NAMESPACE_INFO)); - $this->assertFalse($this->helper->hasCurrentSuccessMessages()); - $this->assertFalse($this->helper->hasCurrentMessages(FlashMessenger::NAMESPACE_SUCCESS)); - $this->assertFalse($this->helper->hasCurrentErrorMessages()); - $this->assertFalse($this->helper->hasCurrentMessages(FlashMessenger::NAMESPACE_ERROR)); - } - - public function testIterationOccursOverMessages() - { - $this->seedMessages(); - $test = []; - foreach ($this->helper as $message) { - $test[] = $message; - } - $this->assertEquals(['foo', 'bar'], $test); - } - - public function testCountIsOfMessages() - { - $this->seedMessages(); - $this->assertEquals(2, count($this->helper)); - } - - public function testAddMessageWithLoops() - { - $helper = new FlashMessenger(); - $helper->addMessage('foo'); - $helper->addMessage('bar', null, 2); - $helper->addMessage('baz', null, 5); - $this->assertEquals('3', count($helper->getCurrentMessages())); - $helper->clearCurrentMessages(); - $this->assertEquals('0', count($helper->getCurrentMessages())); - } -} diff --git a/test/Controller/Plugin/IdentityTest.php b/test/Controller/Plugin/IdentityTest.php deleted file mode 100644 index dca7a590d..000000000 --- a/test/Controller/Plugin/IdentityTest.php +++ /dev/null @@ -1,42 +0,0 @@ -setUsername('a username'); - $identity->setPassword('a password'); - - $authenticationService = new AuthenticationService(new NonPersistentStorage, new TestAsset\AuthenticationAdapter); - - $identityPlugin = new IdentityPlugin; - $identityPlugin->setAuthenticationService($authenticationService); - - $this->assertNull($identityPlugin()); - - $this->assertFalse($authenticationService->hasIdentity()); - - $authenticationService->getAdapter()->setIdentity($identity); - $result = $authenticationService->authenticate(); - $this->assertTrue($result->isValid()); - - $this->assertEquals($identity, $identityPlugin()); - } -} diff --git a/test/Controller/Plugin/TestAsset/AuthenticationAdapter.php b/test/Controller/Plugin/TestAsset/AuthenticationAdapter.php deleted file mode 100644 index b17a74e74..000000000 --- a/test/Controller/Plugin/TestAsset/AuthenticationAdapter.php +++ /dev/null @@ -1,28 +0,0 @@ -identity = $identity; - } - - public function authenticate() - { - return new Result(Result::SUCCESS, $this->identity); - } -} diff --git a/test/Controller/Plugin/TestAsset/DisablePhpMoveUploadedFileChecks.php b/test/Controller/Plugin/TestAsset/DisablePhpMoveUploadedFileChecks.php deleted file mode 100644 index d1aec3635..000000000 --- a/test/Controller/Plugin/TestAsset/DisablePhpMoveUploadedFileChecks.php +++ /dev/null @@ -1,15 +0,0 @@ -password = (string) $password; - } - - /** - * @return string|null - */ - public function getPassword() - { - return $this->password; - } - - /** - * @param string $username - */ - public function setUsername($username) - { - $this->username = (string) $username; - } - - /** - * @return string|null - */ - public function getUsername() - { - return $this->username; - } -} diff --git a/test/Controller/Plugin/TestAsset/InputFilterProviderFieldset.php b/test/Controller/Plugin/TestAsset/InputFilterProviderFieldset.php deleted file mode 100644 index 886955c24..000000000 --- a/test/Controller/Plugin/TestAsset/InputFilterProviderFieldset.php +++ /dev/null @@ -1,36 +0,0 @@ -add(array( - 'name' => 'test_field', - )); - } - - public function getInputFilterSpecification() - { - return array( - 'test_field' => array( - 'filters' => array( - new \Zend\Filter\StringToUpper, - ), - ), - ); - } -} diff --git a/test/Controller/Plugin/TestAsset/LinksFieldset.php b/test/Controller/Plugin/TestAsset/LinksFieldset.php deleted file mode 100644 index ead24e33a..000000000 --- a/test/Controller/Plugin/TestAsset/LinksFieldset.php +++ /dev/null @@ -1,34 +0,0 @@ -add(array( - 'name' => 'foobar', - )); - } - - public function getInputFilterSpecification() - { - return array( - 'email' => array( - 'required' => false, - ), - ); - } -} diff --git a/test/Controller/Plugin/TestAsset/TestFieldset.php b/test/Controller/Plugin/TestAsset/TestFieldset.php deleted file mode 100644 index 50c5e494e..000000000 --- a/test/Controller/Plugin/TestAsset/TestFieldset.php +++ /dev/null @@ -1,52 +0,0 @@ -add(array( - 'name' => 'text', - 'type' => 'text', - )); - - $this->add(array( - 'name' => 'file', - 'type' => 'file', - )); - - } - - public function getInputFilterSpecification() - { - return array( - 'text' => array( - 'required' => true, - ), - 'file' => array( - 'required' => true, - 'filters' => array( - array( - 'name' => 'filerenameupload', - 'options' => array( - 'target' => __DIR__ . '/testfile.jpg', - 'overwrite' => true, - ) - ) - ), - ), - ); - } -} diff --git a/test/Controller/Plugin/TestAsset/nullfile b/test/Controller/Plugin/TestAsset/nullfile deleted file mode 100644 index e69de29bb..000000000 diff --git a/test/Controller/PluginManagerTest.php b/test/Controller/PluginManagerTest.php index 7f72f8dd0..0d4857e14 100644 --- a/test/Controller/PluginManagerTest.php +++ b/test/Controller/PluginManagerTest.php @@ -10,9 +10,7 @@ namespace ZendTest\Mvc\Controller; use PHPUnit_Framework_TestCase as TestCase; -use Zend\Authentication\AuthenticationService; use Zend\Mvc\Controller\PluginManager; -use Zend\ServiceManager\Config; use Zend\ServiceManager\Factory\InvokableFactory; use Zend\ServiceManager\ServiceManager; use ZendTest\Mvc\Controller\TestAsset\SampleController; @@ -72,26 +70,6 @@ public function testGetWithConstructorAndOptions() $this->assertEquals($plugin->getBar(), ['foo']); } - public function testDefinesFactoryForIdentityPlugin() - { - $pluginManager = new PluginManager(new ServiceManager()); - $this->assertTrue($pluginManager->has('identity')); - } - - public function testIdentityFactoryCanInjectAuthenticationServiceIfInParentServiceManager() - { - $services = new ServiceManager(); - (new Config([ - 'factories' => [ - AuthenticationService::class => InvokableFactory::class, - ], - ]))->configureServiceManager($services); - $pluginManager = new PluginManager($services); - $identity = $pluginManager->get('identity'); - $expected = $services->get(AuthenticationService::class); - $this->assertSame($expected, $identity->getAuthenticationService()); - } - public function testCanCreateByFactory() { $pluginManager = new PluginManager(new ServiceManager(), [