From b8212210fbe644a3185a25b542309997e4f084d8 Mon Sep 17 00:00:00 2001 From: Adam Lundrigan Date: Wed, 28 Jan 2015 23:18:18 -0330 Subject: [PATCH 1/8] Remove repository sync tabs from zfc-user/user/index.phtml --- module/User/view/zfc-user/user/index.phtml | 98 ++++++++-------------- 1 file changed, 36 insertions(+), 62 deletions(-) diff --git a/module/User/view/zfc-user/user/index.phtml b/module/User/view/zfc-user/user/index.phtml index ad179ce0..0746c0ed 100644 --- a/module/User/view/zfc-user/user/index.phtml +++ b/module/User/view/zfc-user/user/index.phtml @@ -1,69 +1,43 @@ -
-
-
-
- -
-
- flashMessenger()->getMessages() as $message): ?> -

- - +
+ <?php echo $this->zfcUserDisplayName() ?> +

Hello, zfcUserDisplayName() ?>!

+

We should fill this space with some useful information...

+
+
+ +flashMessenger()->getMessages() as $message): ?> +

+ -
-
- listModule(['user' => true]); - if (empty($modules)) { - ?> -
No modules was submitted yet
- moduleView([ - 'owner' => $module->getOwner(), - 'name' => $module->getName(), - 'created_at' => $module->getCreatedAt(), - 'url' => $module->getUrl(), - 'photo_url' => $module->getPhotoUrl(), - 'description' => $module->getDescription(), - ], 'remove'); - } - ?> -
-
-
Synchronizing with Github loading
-
+ -
- userOrganizations() ?> -
-
+
+
+ listModule(['user' => true]); + if (empty($modules)) { + ?> +
translate('You have not added any modules'); ?>
+ moduleView([ + 'owner' => $module->getOwner(), + 'name' => $module->getName(), + 'created_at' => $module->getCreatedAt(), + 'url' => $module->getUrl(), + 'photo_url' => $module->getPhotoUrl(), + 'description' => $module->getDescription(), + ], 'remove'); + } + ?>
-
- +
+
-url('zf-module'); -$this->inlineScript()->appendScript(<< Date: Sat, 31 Jan 2015 15:37:01 -0330 Subject: [PATCH 2/8] Fix usage of short echo tags --- module/User/view/zfc-user/user/index.phtml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/module/User/view/zfc-user/user/index.phtml b/module/User/view/zfc-user/user/index.phtml index 0746c0ed..61e3fbc3 100644 --- a/module/User/view/zfc-user/user/index.phtml +++ b/module/User/view/zfc-user/user/index.phtml @@ -11,8 +11,8 @@
@@ -21,7 +21,7 @@ $modules = $this->listModule(['user' => true]); if (empty($modules)) { ?> -
translate('You have not added any modules'); ?>
+
translate('You have not added any modules'); ?>
Date: Mon, 2 Feb 2015 22:14:02 -0330 Subject: [PATCH 3/8] Rejig routes to separate "My Profile" page from ZfcUser/ScnSocialAuth --- config/application.config.php | 2 +- config/autoload/global.php | 3 +- config/autoload/zfcuser.global.php | 2 +- .../view/layout/layout-small-header.phtml | 4 +- module/Application/view/layout/layout.phtml | 4 +- module/User/config/module.config.php | 29 ++++++++- .../src/User/Controller/IndexController.php | 16 +++++ .../Controller/IndexControllerFactory.php | 15 +++++ .../Controller/IndexControllerTest.php | 60 +++++++++++++++++++ .../{zfc-user/user => user/index}/index.phtml | 0 10 files changed, 127 insertions(+), 8 deletions(-) create mode 100644 module/User/src/User/Controller/IndexController.php create mode 100644 module/User/src/User/Controller/IndexControllerFactory.php create mode 100644 module/User/test/UserTest/Integration/Controller/IndexControllerTest.php rename module/User/view/{zfc-user/user => user/index}/index.phtml (100%) diff --git a/config/application.config.php b/config/application.config.php index 790e1bba..57810862 100644 --- a/config/application.config.php +++ b/config/application.config.php @@ -5,13 +5,13 @@ 'modules' => [ 'ZF\DevelopmentMode', 'AssetManager', + 'EdpModuleLayouts', 'ZfcBase', 'ZfcUser', 'ScnSocialAuth', 'EdpGithub', 'Application', 'User', - 'EdpModuleLayouts', 'ZfModule', ], 'module_listener_options' => [ diff --git a/config/autoload/global.php b/config/autoload/global.php index e4c99b48..d9495399 100644 --- a/config/autoload/global.php +++ b/config/autoload/global.php @@ -1,7 +1,8 @@ [ - 'ZfcUser' => 'layout/layout-small-header.phtml', + 'ZfcUser' => 'layout/layout-small-header.phtml', + 'User' => 'layout/layout-small-header.phtml', 'ZfModule' => 'layout/layout-small-header.phtml', ], 'asset_manager' => [ diff --git a/config/autoload/zfcuser.global.php b/config/autoload/zfcuser.global.php index ea40f743..98de5710 100644 --- a/config/autoload/zfcuser.global.php +++ b/config/autoload/zfcuser.global.php @@ -142,7 +142,7 @@ * Accepted values: A valid route name within your application * */ - //'login_redirect_route' => 'zfcuser', + 'login_redirect_route' => 'user', /** * Logout Redirect Route diff --git a/module/Application/view/layout/layout-small-header.phtml b/module/Application/view/layout/layout-small-header.phtml index 4d502c0a..e3ca18bd 100644 --- a/module/Application/view/layout/layout-small-header.phtml +++ b/module/Application/view/layout/layout-small-header.phtml @@ -33,13 +33,13 @@
  • |
  • |
  • Logout
  • diff --git a/module/Application/view/layout/layout.phtml b/module/Application/view/layout/layout.phtml index 8f70f01a..4a3c67cc 100644 --- a/module/Application/view/layout/layout.phtml +++ b/module/Application/view/layout/layout.phtml @@ -35,12 +35,12 @@ ?>
  • |
  • |
  • Logout
  • diff --git a/module/User/config/module.config.php b/module/User/config/module.config.php index 3f11544a..c7d44109 100644 --- a/module/User/config/module.config.php +++ b/module/User/config/module.config.php @@ -16,9 +16,36 @@ __DIR__ . '/../view', ], ], + 'router' => [ + 'routes' => [ + 'zfcuser' => [ + 'options' => [ + 'route' => '/auth', + ], + ], + 'scn-social-auth-user' => [ + 'options' => [ + 'route' => '/auth', + 'defaults' => [ + 'controller' => 'User\Controller\Index', + ], + ], + ], + 'user' => [ + 'type' => 'Segment', + 'options' => [ + 'route' => '/user', + 'defaults' => [ + 'controller' => 'User\Controller\Index', + 'action' => 'index', + ], + ], + ], + ], + ], 'controllers' => [ 'invokables' => [ - 'User\Controller\Module' => 'User\Controller\ModuleController', + 'User\Controller\Index' => 'User\Controller\IndexController', ], ], 'view_helpers' => [ diff --git a/module/User/src/User/Controller/IndexController.php b/module/User/src/User/Controller/IndexController.php new file mode 100644 index 00000000..605f1e26 --- /dev/null +++ b/module/User/src/User/Controller/IndexController.php @@ -0,0 +1,16 @@ +setApplicationConfig(Bootstrap::getConfig()); + $this->getApplicationServiceLocator()->setAllowOverride(true); + + $mockTotalModules = $this->getMockBuilder('ZfModule\View\Helper\TotalModules') + ->disableOriginalConstructor() + ->getMock(); + + $mockListModule = $this->getMockBuilder('ZfModule\View\Helper\ListModule') + ->disableOriginalConstructor() + ->getMock(); + + $this->viewHelperManager = $this->getApplicationServiceLocator()->get('ViewHelperManager'); + $this->viewHelperManager->setService('totalModules', $mockTotalModules); + $this->viewHelperManager->setService('listModule', $mockListModule); + + $mockAuthService = $this->getMockBuilder('Zend\Authentication\AuthenticationService') + ->disableOriginalConstructor() + ->getMock(); + $mockAuthService->expects($this->any()) + ->method('hasIdentity') + ->will($this->returnValue(true)); + $mockAuthService->expects($this->any()) + ->method('getIdentity') + ->will($this->returnValue(new UserEntity())); + + $this->getApplicationServiceLocator()->setService('zfcuser_auth_service', $mockAuthService); + $this->viewHelperManager->get('zfcUserIdentity')->setAuthService($mockAuthService); + } + + public function testIndexActionCanBeAccessed() + { + $mockListModule = $this->viewHelperManager->get('listModule'); + $mockListModule->expects($this->once()) + ->method('__invoke') + ->will($this->returnValue([])); + + $this->dispatch('/user'); + + $this->assertControllerName('User\Controller\Index'); + $this->assertActionName('index'); + $this->assertTemplateName('user/index/index'); + $this->assertResponseStatusCode(HttpResponse::STATUS_CODE_200); + } +} diff --git a/module/User/view/zfc-user/user/index.phtml b/module/User/view/user/index/index.phtml similarity index 100% rename from module/User/view/zfc-user/user/index.phtml rename to module/User/view/user/index/index.phtml From b42bec69ca370b7ce13f3c158f7c8b2a86c88cba Mon Sep 17 00:00:00 2001 From: Adam Lundrigan Date: Mon, 2 Feb 2015 23:11:23 -0330 Subject: [PATCH 4/8] Remove old routes and controller actions for syncing repositories --- module/ZfModule/config/module.config.php | 43 ----- .../ZfModule/Controller/IndexController.php | 177 ------------------ .../Controller/IndexControllerFactory.php | 6 - 3 files changed, 226 deletions(-) diff --git a/module/ZfModule/config/module.config.php b/module/ZfModule/config/module.config.php index 1f7b2f83..af20525d 100644 --- a/module/ZfModule/config/module.config.php +++ b/module/ZfModule/config/module.config.php @@ -24,49 +24,6 @@ ], ], ], - 'zf-module' => [ - 'type' => 'Segment', - 'options' => [ - 'route' => '/module', - 'defaults' => [ - 'controller' => Controller\IndexController::class, - 'action' => 'index', - ], - ], - 'may_terminate' => true, - 'child_routes' => [ - 'list' => [ - 'type' => 'Segment', - 'options' => [ - 'route' => '/list[/:owner]', - 'constrains' => [ - 'owner' => '[a-zA-Z][a-zA-Z0-9_-]*', - ], - 'defaults' => [ - 'action' => 'organization', - ], - ], - ], - 'add' => [ - 'type' => 'Literal', - 'options' => [ - 'route' => '/add', - 'defaults' => [ - 'action' => 'add', - ], - ], - ], - 'remove' => [ - 'type' => 'Literal', - 'options' => [ - 'route' => '/remove', - 'defaults' => [ - 'action' => 'remove', - ], - ], - ], - ], - ], ], ], 'view_manager' => [ diff --git a/module/ZfModule/src/ZfModule/Controller/IndexController.php b/module/ZfModule/src/ZfModule/Controller/IndexController.php index 5431a979..9157bec8 100644 --- a/module/ZfModule/src/ZfModule/Controller/IndexController.php +++ b/module/ZfModule/src/ZfModule/Controller/IndexController.php @@ -3,12 +3,9 @@ namespace ZfModule\Controller; use Application\Service\RepositoryRetriever; -use EdpGithub\Collection\RepositoryCollection; -use Zend\Http; use Zend\Mvc\Controller\AbstractActionController; use Zend\View\Model\ViewModel; use ZfModule\Mapper; -use ZfModule\Service; class IndexController extends AbstractActionController { @@ -17,11 +14,6 @@ class IndexController extends AbstractActionController */ private $moduleMapper; - /** - * @var Service\Module - */ - private $moduleService; - /** * @var RepositoryRetriever */ @@ -29,16 +21,13 @@ class IndexController extends AbstractActionController /** * @param Mapper\Module $moduleMapper - * @param Service\Module $moduleService * @param RepositoryRetriever $repositoryRetriever */ public function __construct( Mapper\Module $moduleMapper, - Service\Module $moduleService, RepositoryRetriever $repositoryRetriever ) { $this->moduleMapper = $moduleMapper; - $this->moduleService = $moduleService; $this->repositoryRetriever = $repositoryRetriever; } @@ -74,170 +63,4 @@ public function viewAction() return $viewModel; } - - public function indexAction() - { - if (!$this->zfcUserAuthentication()->hasIdentity()) { - return $this->redirect()->toRoute('zfcuser/login'); - } - - $params = [ - 'type' => 'all', - 'per_page' => 100, - 'sort' => 'updated', - 'direction' => 'desc', - ]; - - $repos = $this->repositoryRetriever->getAuthenticatedUserRepositories($params); - $repositories = $this->fetchModules($repos); - - $viewModel = new ViewModel(['repositories' => $repositories]); - $viewModel->setTerminal(true); - - return $viewModel; - } - - public function organizationAction() - { - if (!$this->zfcUserAuthentication()->hasIdentity()) { - return $this->redirect()->toRoute('zfcuser/login'); - } - - $owner = $this->params()->fromRoute('owner', null); - $params = [ - 'per_page' => 100, - 'sort' => 'updated', - 'direction' => 'desc', - ]; - - $repos = $this->repositoryRetriever->getUserRepositories($owner, $params); - $repositories = $this->fetchModules($repos); - - $viewModel = new ViewModel(['repositories' => $repositories]); - $viewModel->setTerminal(true); - $viewModel->setTemplate('zf-module/index/index.phtml'); - - return $viewModel; - } - - /** - * @param RepositoryCollection $repos - * @return array - */ - private function fetchModules(RepositoryCollection $repos) - { - $repositories = []; - - foreach ($repos as $repo) { - $isModule = $this->moduleService->isModule($repo); - if (!$repo->fork && $repo->permissions->push && $isModule && !$this->moduleMapper->findByName($repo->name)) { - $repositories[] = $repo; - } - } - - return $repositories; - } - - /** - * This function is used to submit a module from the site - * @throws Exception\UnexpectedValueException - * @return - **/ - public function addAction() - { - if (!$this->zfcUserAuthentication()->hasIdentity()) { - return $this->redirect()->toRoute('zfcuser/login'); - } - - $request = $this->getRequest(); - if ($request->isPost()) { - $repo = $request->getPost()->get('repo'); - $owner = $request->getPost()->get('owner'); - - $repository = $this->repositoryRetriever->getUserRepositoryMetadata($owner, $repo); - - if (!($repository instanceof \stdClass)) { - throw new Exception\RuntimeException( - 'Not able to fetch the repository from github due to an unknown error.', - Http\Response::STATUS_CODE_500 - ); - } - - if (!$repository->fork && $repository->permissions->push) { - if ($this->moduleService->isModule($repository)) { - $module = $this->moduleService->register($repository); - $this->flashMessenger()->addMessage($module->getName() . ' has been added to ZF Modules'); - } else { - throw new Exception\UnexpectedValueException( - $repository->name . ' is not a Zend Framework Module', - Http\Response::STATUS_CODE_403 - ); - } - } else { - throw new Exception\UnexpectedValueException( - 'You have no permission to add this module. The reason might be that you are' . - 'neither the owner nor a collaborator of this repository.', - Http\Response::STATUS_CODE_403 - ); - } - } else { - throw new Exception\UnexpectedValueException( - 'Something went wrong with the post values of the request...' - ); - } - - return $this->redirect()->toRoute('zfcuser'); - } - - /** - * This function is used to remove a module from the site - * @throws Exception\UnexpectedValueException - * @return - **/ - public function removeAction() - { - if (!$this->zfcUserAuthentication()->hasIdentity()) { - return $this->redirect()->toRoute('zfcuser/login'); - } - - $request = $this->getRequest(); - if ($request->isPost()) { - $repo = $request->getPost()->get('repo'); - $owner = $request->getPost()->get('owner'); - - $repository = $this->repositoryRetriever->getUserRepositoryMetadata($owner, $repo); - - if (!$repository instanceof \stdClass) { - throw new Exception\RuntimeException( - 'Not able to fetch the repository from github due to an unknown error.', - Http\Response::STATUS_CODE_500 - ); - } - - if (!$repository->fork && $repository->permissions->push) { - $module = $this->moduleMapper->findByUrl($repository->html_url); - if ($module instanceof \ZfModule\Entity\Module) { - $this->moduleMapper->delete($module); - $this->flashMessenger()->addMessage($repository->name . ' has been removed from ZF Modules'); - } else { - throw new Exception\UnexpectedValueException( - $repository->name . ' was not found', - Http\Response::STATUS_CODE_403 - ); - } - } else { - throw new Exception\UnexpectedValueException( - 'You have no permission to add this module. The reason might be that you are' . - 'neither the owner nor a collaborator of this repository.', - Http\Response::STATUS_CODE_403 - ); - } - } else { - throw new Exception\UnexpectedValueException( - 'Something went wrong with the post values of the request...' - ); - } - - return $this->redirect()->toRoute('zfcuser'); - } } diff --git a/module/ZfModule/src/ZfModule/Controller/IndexControllerFactory.php b/module/ZfModule/src/ZfModule/Controller/IndexControllerFactory.php index f5ee3cd4..bfef465d 100644 --- a/module/ZfModule/src/ZfModule/Controller/IndexControllerFactory.php +++ b/module/ZfModule/src/ZfModule/Controller/IndexControllerFactory.php @@ -3,11 +3,9 @@ namespace ZfModule\Controller; use Application\Service\RepositoryRetriever; -use Zend\Mvc\Controller\ControllerManager; use Zend\ServiceManager\FactoryInterface; use Zend\ServiceManager\ServiceLocatorInterface; use ZfModule\Mapper; -use ZfModule\Service; class IndexControllerFactory implements FactoryInterface { @@ -23,15 +21,11 @@ public function createService(ServiceLocatorInterface $controllerManager) /* @var Mapper\Module $moduleMapper */ $moduleMapper = $serviceManager->get('zfmodule_mapper_module'); - /* @var Service\Module $moduleService */ - $moduleService = $serviceManager->get('zfmodule_service_module'); - /* @var RepositoryRetriever $repositoryRetriever */ $repositoryRetriever = $serviceManager->get(RepositoryRetriever::class); return new IndexController( $moduleMapper, - $moduleService, $repositoryRetriever ); } From 6cf45d08988dfe988aede6954f6d0e695a974a56 Mon Sep 17 00:00:00 2001 From: Adam Lundrigan Date: Tue, 3 Feb 2015 21:33:30 -0330 Subject: [PATCH 5/8] User module must be loaded after ZfModule due to the latter's catch-all route --- config/application.config.php | 2 +- .../view/user/index/render-module-list.phtml | 43 +++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 module/User/view/user/index/render-module-list.phtml diff --git a/config/application.config.php b/config/application.config.php index 57810862..afc736eb 100644 --- a/config/application.config.php +++ b/config/application.config.php @@ -11,8 +11,8 @@ 'ScnSocialAuth', 'EdpGithub', 'Application', - 'User', 'ZfModule', + 'User', ], 'module_listener_options' => [ 'config_glob_paths' => [ diff --git a/module/User/view/user/index/render-module-list.phtml b/module/User/view/user/index/render-module-list.phtml new file mode 100644 index 00000000..61e3fbc3 --- /dev/null +++ b/module/User/view/user/index/render-module-list.phtml @@ -0,0 +1,43 @@ + +
    + <?php echo $this->zfcUserDisplayName() ?> +

    Hello, zfcUserDisplayName() ?>!

    +

    We should fill this space with some useful information...

    +
    +
    + +flashMessenger()->getMessages() as $message): ?> +

    + + + + +
    +
    + listModule(['user' => true]); + if (empty($modules)) { + ?> +
    translate('You have not added any modules'); ?>
    + moduleView([ + 'owner' => $module->getOwner(), + 'name' => $module->getName(), + 'created_at' => $module->getCreatedAt(), + 'url' => $module->getUrl(), + 'photo_url' => $module->getPhotoUrl(), + 'description' => $module->getDescription(), + ], 'remove'); + } + ?> +
    +
    + +
    +
    + From ec27d0faf99522ad521baac6d5d4898d6d476e82 Mon Sep 17 00:00:00 2001 From: Adam Lundrigan Date: Tue, 3 Feb 2015 21:40:17 -0330 Subject: [PATCH 6/8] Dropped direct rendering of user's module list from within the view - Provide separate controller action for rendering list (renderModuleListAction) - Inject module list (via child model) rather than relying on view helper to load it - Update module-view helper view script to correct route add/delete references --- module/User/config/module.config.php | 48 ++++++++++++++- .../src/User/Controller/IndexController.php | 30 ++++++++++ .../Controller/IndexControllerFactory.php | 14 ++++- .../Controller/IndexControllerTest.php | 44 ++++++++++---- module/User/view/user/index/index.phtml | 19 +----- .../view/user/index/render-module-list.phtml | 60 ++++++------------- .../view/zf-module/helper/module-view.phtml | 4 +- 7 files changed, 139 insertions(+), 80 deletions(-) diff --git a/module/User/config/module.config.php b/module/User/config/module.config.php index c7d44109..fbdcf864 100644 --- a/module/User/config/module.config.php +++ b/module/User/config/module.config.php @@ -32,7 +32,7 @@ ], ], 'user' => [ - 'type' => 'Segment', + 'type' => 'Literal', 'options' => [ 'route' => '/user', 'defaults' => [ @@ -40,12 +40,54 @@ 'action' => 'index', ], ], + 'may_terminate' => true, + 'child_routes' => [ + 'module' => [ + 'type' => 'Literal', + 'options' => [ + 'route' => '/module', + ], + 'may_terminate' => false, + 'child_routes' => [ + 'list' => [ + 'type' => 'Literal', + 'options' => [ + 'route' => '/render-list', + 'defaults' => [ + 'action' => 'render-module-list', + ], + ], + ], + 'add' => [ + 'type' => 'Literal', + 'options' => [ + 'route' => '/add', + 'defaults' => [ + 'action' => 'add', + ], + ], + ], + 'remove' => [ + 'type' => 'Segment', + 'options' => [ + 'route' => '/:module_id/remove', + 'constraints' => [ + 'module_id' => '[0-9]+', + ], + 'defaults' => [ + 'action' => 'remove', + ], + ], + ], + ], + ], + ], ], ], ], 'controllers' => [ - 'invokables' => [ - 'User\Controller\Index' => 'User\Controller\IndexController', + 'factories' => [ + 'User\Controller\Index' => 'User\Controller\IndexControllerFactory', ], ], 'view_helpers' => [ diff --git a/module/User/src/User/Controller/IndexController.php b/module/User/src/User/Controller/IndexController.php index 605f1e26..3ac40170 100644 --- a/module/User/src/User/Controller/IndexController.php +++ b/module/User/src/User/Controller/IndexController.php @@ -4,12 +4,42 @@ use Zend\Mvc\Controller\AbstractActionController; use Zend\View\Model\ViewModel; +use ZfModule\Mapper\Module as ModuleMapper; class IndexController extends AbstractActionController { + /** + * @var ModuleMapper + */ + protected $moduleMapper; + + /** + * @param ModuleMapper $mapper + */ + public function __construct(ModuleMapper $mapper) + { + $this->moduleMapper = $mapper; + } + public function indexAction() { + $registeredModules = $this->renderModuleListAction(); + $registeredModules->setTerminal(false); + + $vm = new ViewModel(); + $vm->addChild($registeredModules, 'registered_modules'); + + return $vm; + } + + public function renderModuleListAction() + { + $modules = $this->moduleMapper->findByOwner($this->zfcUserAuthentication()->getIdentity()->getId()); + $vm = new ViewModel(); + $vm->setTemplate('user/index/render-module-list'); + $vm->setVariable('modules', $modules); + $vm->setTerminal(true); return $vm; } diff --git a/module/User/src/User/Controller/IndexControllerFactory.php b/module/User/src/User/Controller/IndexControllerFactory.php index 864a887b..68698e92 100644 --- a/module/User/src/User/Controller/IndexControllerFactory.php +++ b/module/User/src/User/Controller/IndexControllerFactory.php @@ -2,6 +2,10 @@ namespace User\Controller; +use Zend\ServiceManager\FactoryInterface; +use Zend\ServiceManager\ServiceLocatorInterface; +use ZfModule\Mapper\Module as ModuleMapper; + class IndexControllerFactory implements FactoryInterface { /** @@ -10,6 +14,14 @@ class IndexControllerFactory implements FactoryInterface */ public function createService(ServiceLocatorInterface $controllerManager) { - return new IndexController(); + /* @var ServiceLocatorInterface $controllerManager */ + $serviceManager = $controllerManager->getServiceLocator(); + + /* @var ModuleMapper $moduleMapper */ + $moduleMapper = $serviceManager->get('zfmodule_mapper_module'); + + return new IndexController( + $moduleMapper + ); } } diff --git a/module/User/test/UserTest/Integration/Controller/IndexControllerTest.php b/module/User/test/UserTest/Integration/Controller/IndexControllerTest.php index ecf0975e..f4d88eba 100644 --- a/module/User/test/UserTest/Integration/Controller/IndexControllerTest.php +++ b/module/User/test/UserTest/Integration/Controller/IndexControllerTest.php @@ -4,8 +4,14 @@ use ApplicationTest\Integration\Util\Bootstrap; use User\Entity\User as UserEntity; +use Zend\Authentication\AuthenticationService; +use Zend\Db\ResultSet\HydratingResultSet; use Zend\Http\Response as HttpResponse; +use Zend\Stdlib\Hydrator\ClassMethods; use Zend\Test\PHPUnit\Controller\AbstractHttpControllerTestCase; +use ZfModule\Entity\Module as ModuleEntity; +use ZfModule\Mapper\Module as ModuleMapper; +use ZfModule\View\Helper\TotalModules; class IndexControllerTest extends AbstractHttpControllerTestCase { @@ -17,19 +23,14 @@ protected function setUp() $this->setApplicationConfig(Bootstrap::getConfig()); $this->getApplicationServiceLocator()->setAllowOverride(true); - $mockTotalModules = $this->getMockBuilder('ZfModule\View\Helper\TotalModules') + $mockTotalModules = $this->getMockBuilder(TotalModules::class) ->disableOriginalConstructor() ->getMock(); - $mockListModule = $this->getMockBuilder('ZfModule\View\Helper\ListModule') - ->disableOriginalConstructor() - ->getMock(); - $this->viewHelperManager = $this->getApplicationServiceLocator()->get('ViewHelperManager'); $this->viewHelperManager->setService('totalModules', $mockTotalModules); - $this->viewHelperManager->setService('listModule', $mockListModule); - $mockAuthService = $this->getMockBuilder('Zend\Authentication\AuthenticationService') + $mockAuthService = $this->getMockBuilder(AuthenticationService::class) ->disableOriginalConstructor() ->getMock(); $mockAuthService->expects($this->any()) @@ -38,17 +39,32 @@ protected function setUp() $mockAuthService->expects($this->any()) ->method('getIdentity') ->will($this->returnValue(new UserEntity())); - $this->getApplicationServiceLocator()->setService('zfcuser_auth_service', $mockAuthService); $this->viewHelperManager->get('zfcUserIdentity')->setAuthService($mockAuthService); + + $mockMapper = $this->getMockBuilder(ModuleMapper::class) + ->disableOriginalConstructor() + ->getMock(); + $this->getApplicationServiceLocator()->setService('zfmodule_mapper_module', $mockMapper); } - public function testIndexActionCanBeAccessed() + /** + * @group integration + */ + public function testIndexActionRendersUserModuleList() { - $mockListModule = $this->viewHelperManager->get('listModule'); - $mockListModule->expects($this->once()) - ->method('__invoke') - ->will($this->returnValue([])); + $mockResultSet = new HydratingResultSet(new ClassMethods(false), new ModuleEntity()); + $mockResultSet->initialize([[ + 'id' => 123, + 'name' => 'FooModule', + 'description' => 'some random module', + 'url' => 'https://github.com/zendframework/modules.zendframework.com', + ]]); + + $mockMapper = $this->getApplicationServiceLocator()->get('zfmodule_mapper_module'); + $mockMapper->expects($this->once()) + ->method('findByOwner') + ->willReturn($mockResultSet); $this->dispatch('/user'); @@ -56,5 +72,7 @@ public function testIndexActionCanBeAccessed() $this->assertActionName('index'); $this->assertTemplateName('user/index/index'); $this->assertResponseStatusCode(HttpResponse::STATUS_CODE_200); + $this->assertContains('FooModule', $this->getResponse()->getContent()); + $this->assertContains('/user/module/123/remove', $this->getResponse()->getContent()); } } diff --git a/module/User/view/user/index/index.phtml b/module/User/view/user/index/index.phtml index 61e3fbc3..bf287c79 100644 --- a/module/User/view/user/index/index.phtml +++ b/module/User/view/user/index/index.phtml @@ -17,24 +17,7 @@
    - listModule(['user' => true]); - if (empty($modules)) { - ?> -
    translate('You have not added any modules'); ?>
    - moduleView([ - 'owner' => $module->getOwner(), - 'name' => $module->getName(), - 'created_at' => $module->getCreatedAt(), - 'url' => $module->getUrl(), - 'photo_url' => $module->getPhotoUrl(), - 'description' => $module->getDescription(), - ], 'remove'); - } - ?> + registered_modules; ?>
    diff --git a/module/User/view/user/index/render-module-list.phtml b/module/User/view/user/index/render-module-list.phtml index 61e3fbc3..a39b3b74 100644 --- a/module/User/view/user/index/render-module-list.phtml +++ b/module/User/view/user/index/render-module-list.phtml @@ -1,43 +1,17 @@ - -
    - <?php echo $this->zfcUserDisplayName() ?> -

    Hello, zfcUserDisplayName() ?>!

    -

    We should fill this space with some useful information...

    -
    -
    - -flashMessenger()->getMessages() as $message): ?> -

    - - - - -
    -
    - listModule(['user' => true]); - if (empty($modules)) { - ?> -
    translate('You have not added any modules'); ?>
    - moduleView([ - 'owner' => $module->getOwner(), - 'name' => $module->getName(), - 'created_at' => $module->getCreatedAt(), - 'url' => $module->getUrl(), - 'photo_url' => $module->getPhotoUrl(), - 'description' => $module->getDescription(), - ], 'remove'); - } - ?> -
    -
    - -
    -
    - +modules->count() === 0) { + ?> +
    translate('You have not added any modules'); ?>
    + modules as $module) { + echo $this->moduleView([ + 'id' => $module->getId(), + 'owner' => $module->getOwner(), + 'name' => $module->getName(), + 'created_at' => $module->getCreatedAt(), + 'url' => $module->getUrl(), + 'photo_url' => $module->getPhotoUrl(), + 'description' => $module->getDescription(), + ], 'remove'); +} diff --git a/module/ZfModule/view/zf-module/helper/module-view.phtml b/module/ZfModule/view/zf-module/helper/module-view.phtml index 4b82fae5..24f163f9 100644 --- a/module/ZfModule/view/zf-module/helper/module-view.phtml +++ b/module/ZfModule/view/zf-module/helper/module-view.phtml @@ -26,13 +26,13 @@

    -
    +
    -
    + From 8b6e4a647e1a294c65c80deaace77ab254ce08f5 Mon Sep 17 00:00:00 2001 From: Adam Lundrigan Date: Tue, 3 Feb 2015 21:40:43 -0330 Subject: [PATCH 7/8] ZfModule\Mapper\Module::findByOwner should not ignore $owner parameter --- module/ZfModule/src/ZfModule/Mapper/Module.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/module/ZfModule/src/ZfModule/Mapper/Module.php b/module/ZfModule/src/ZfModule/Mapper/Module.php index b493d381..ffb6f053 100644 --- a/module/ZfModule/src/ZfModule/Mapper/Module.php +++ b/module/ZfModule/src/ZfModule/Mapper/Module.php @@ -87,12 +87,12 @@ public function findByLike($query, $limit = null, $orderBy = null, $sort = 'ASC' return $entity; } - /** - * @SuppressWarnings(PHPMD.UnusedFormalParameter) - */ public function findByOwner($owner, $limit = null, $orderBy = null, $sort = 'ASC') { $select = $this->getSelect(); + if ($owner) { + $select->where(['owner' => $owner]); + } if ($orderBy) { $select->order($orderBy . ' ' . $sort); From db98c5f1d4bc995a927f02548d00886b7aa0b80f Mon Sep 17 00:00:00 2001 From: Adam Lundrigan Date: Tue, 3 Feb 2015 21:56:32 -0330 Subject: [PATCH 8/8] Remove some unused test cases orphaned by b42bec6 --- .../Controller/IndexControllerTest.php | 23 ------------------- 1 file changed, 23 deletions(-) diff --git a/module/ZfModule/test/ZfModuleTest/Integration/Controller/IndexControllerTest.php b/module/ZfModule/test/ZfModuleTest/Integration/Controller/IndexControllerTest.php index 5c5e51c3..78654f36 100644 --- a/module/ZfModule/test/ZfModuleTest/Integration/Controller/IndexControllerTest.php +++ b/module/ZfModule/test/ZfModuleTest/Integration/Controller/IndexControllerTest.php @@ -18,29 +18,6 @@ protected function setUp() $this->setApplicationConfig(Bootstrap::getConfig()); } - public function testIndexActionCanBeAccessed() - { - $this->dispatch('/module'); - - $this->assertControllerName(Controller\IndexController::class); - $this->assertActionName('index'); - } - - public function testOrganizationActionCanBeAccessed() - { - $owner = 'foo'; - - $url = sprintf( - '/module/list/%s', - $owner - ); - - $this->dispatch($url); - - $this->assertControllerName(Controller\IndexController::class); - $this->assertActionName('organization'); - } - public function testViewActionCanBeAccessed() { $vendor = 'foo';