Skip to content
This repository was archived by the owner on May 1, 2019. It is now read-only.

Commit 4cd2096

Browse files
committed
Rejig routes to separate "My Profile" page from ZfcUser/ScnSocialAuth
1 parent 06245f1 commit 4cd2096

File tree

10 files changed

+127
-8
lines changed

10 files changed

+127
-8
lines changed

config/application.config.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
'modules' => [
66
'ZF\DevelopmentMode',
77
'AssetManager',
8+
'EdpModuleLayouts',
89
'ZfcBase',
910
'ZfcUser',
1011
'ScnSocialAuth',
1112
'EdpGithub',
1213
'Application',
1314
'User',
14-
'EdpModuleLayouts',
1515
'ZfModule',
1616
],
1717
'module_listener_options' => [

config/autoload/global.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
<?php
22
return [
33
'module_layouts' => [
4-
'ZfcUser' => 'layout/layout-small-header.phtml',
4+
'ZfcUser' => 'layout/layout-small-header.phtml',
5+
'User' => 'layout/layout-small-header.phtml',
56
'ZfModule' => 'layout/layout-small-header.phtml',
67
],
78
'asset_manager' => [

config/autoload/zfcuser.global.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@
142142
* Accepted values: A valid route name within your application
143143
*
144144
*/
145-
//'login_redirect_route' => 'zfcuser',
145+
'login_redirect_route' => 'user',
146146

147147
/**
148148
* Logout Redirect Route

module/Application/view/layout/layout-small-header.phtml

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@
3333
<li class="sep">|</li>
3434
<li class="user-info">
3535
<div class="gravatar-container"><a class="login" href="<?php
36-
echo $this->url('zfcuser');
36+
echo $this->url('user');
3737
?>" title="My profile">
3838
<img src="<?php
3939
echo $this->escapeHtmlAttr($this->zfcUserIdentity()->getPhotoUrl());
4040
?>" alt="<?php echo $this->escapeHtmlAttr($this->zfcUserDisplayName());
4141
?>" style="width:23px;height:23px;" />
42-
</a></div><a class="login" href="<?php echo $this->url('zfcuser') ?>" title="My profile"> Hello <?php echo $this->escapeHtml(ucfirst($userDisplayName)); ?></a>
42+
</a></div><a class="login" href="<?php echo $this->url('user') ?>" title="My profile"> Hello <?php echo $this->escapeHtml(ucfirst($userDisplayName)); ?></a>
4343
</li>
4444
<li class="sep">|</li>
4545
<li ><a href="<?php echo $this->url('zfcuser/logout'); ?>">Logout</a></li>

module/Application/view/layout/layout.phtml

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@
3535
?>
3636
<li class="sep">|</li>
3737
<li class="user-info">
38-
<div class="gravatar-container"><a class="login" href="<?php echo $this->url('zfcuser') ?>" title="My profile">
38+
<div class="gravatar-container"><a class="login" href="<?php echo $this->url('user') ?>" title="My profile">
3939
<img src="<?php
4040
echo $this->escapeHtmlAttr($this->zfcUserIdentity()->getPhotoUrl());
4141
?>" alt="<?php echo $this->escapeHtmlAttr($this->zfcUserDisplayName());
4242
?>" style="width:23px;height:23px;" />
43-
</a></div><a class="login" href="<?php echo $this->url('zfcuser') ?>" title="My profile"> Hello <?php echo $this->escapeHtml(ucfirst($userDisplayName)) ?></a>
43+
</a></div><a class="login" href="<?php echo $this->url('user') ?>" title="My profile"> Hello <?php echo $this->escapeHtml(ucfirst($userDisplayName)) ?></a>
4444
</li>
4545
<li class="sep">|</li>
4646
<li ><a href="<?php echo $this->url('zfcuser/logout') ?>">Logout</a></li>

module/User/config/module.config.php

+28-1
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,36 @@
1616
__DIR__ . '/../view',
1717
],
1818
],
19+
'router' => [
20+
'routes' => [
21+
'zfcuser' => [
22+
'options' => [
23+
'route' => '/auth',
24+
],
25+
],
26+
'scn-social-auth-user' => [
27+
'options' => [
28+
'route' => '/auth',
29+
'defaults' => [
30+
'controller' => 'User\Controller\Index',
31+
],
32+
],
33+
],
34+
'user' => [
35+
'type' => 'Segment',
36+
'options' => [
37+
'route' => '/user',
38+
'defaults' => [
39+
'controller' => 'User\Controller\Index',
40+
'action' => 'index',
41+
],
42+
],
43+
],
44+
],
45+
],
1946
'controllers' => [
2047
'invokables' => [
21-
'User\Controller\Module' => 'User\Controller\ModuleController',
48+
'User\Controller\Index' => 'User\Controller\IndexController',
2249
],
2350
],
2451
'view_helpers' => [
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
namespace User\Controller;
4+
5+
use Zend\Mvc\Controller\AbstractActionController;
6+
use Zend\View\Model\ViewModel;
7+
8+
class IndexController extends AbstractActionController
9+
{
10+
public function indexAction()
11+
{
12+
$vm = new ViewModel();
13+
14+
return $vm;
15+
}
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
namespace User\Controller;
4+
5+
class IndexControllerFactory implements FactoryInterface
6+
{
7+
/**
8+
* @param ServiceLocatorInterface $controllerManager
9+
* @return IndexController
10+
*/
11+
public function createService(ServiceLocatorInterface $controllerManager)
12+
{
13+
return new IndexController();
14+
}
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
3+
namespace UserTest\Integration\Controller;
4+
5+
use ApplicationTest\Integration\Util\Bootstrap;
6+
use User\Entity\User as UserEntity;
7+
use Zend\Http\Response as HttpResponse;
8+
use Zend\Test\PHPUnit\Controller\AbstractHttpControllerTestCase;
9+
10+
class IndexControllerTest extends AbstractHttpControllerTestCase
11+
{
12+
protected $viewHelperManager;
13+
14+
protected function setUp()
15+
{
16+
parent::setUp();
17+
$this->setApplicationConfig(Bootstrap::getConfig());
18+
$this->getApplicationServiceLocator()->setAllowOverride(true);
19+
20+
$mockTotalModules = $this->getMockBuilder('ZfModule\View\Helper\TotalModules')
21+
->disableOriginalConstructor()
22+
->getMock();
23+
24+
$mockListModule = $this->getMockBuilder('ZfModule\View\Helper\ListModule')
25+
->disableOriginalConstructor()
26+
->getMock();
27+
28+
$this->viewHelperManager = $this->getApplicationServiceLocator()->get('ViewHelperManager');
29+
$this->viewHelperManager->setService('totalModules', $mockTotalModules);
30+
$this->viewHelperManager->setService('listModule', $mockListModule);
31+
32+
$mockAuthService = $this->getMockBuilder('Zend\Authentication\AuthenticationService')
33+
->disableOriginalConstructor()
34+
->getMock();
35+
$mockAuthService->expects($this->any())
36+
->method('hasIdentity')
37+
->will($this->returnValue(true));
38+
$mockAuthService->expects($this->any())
39+
->method('getIdentity')
40+
->will($this->returnValue(new UserEntity()));
41+
42+
$this->getApplicationServiceLocator()->setService('zfcuser_auth_service', $mockAuthService);
43+
$this->viewHelperManager->get('zfcUserIdentity')->setAuthService($mockAuthService);
44+
}
45+
46+
public function testIndexActionCanBeAccessed()
47+
{
48+
$mockListModule = $this->viewHelperManager->get('listModule');
49+
$mockListModule->expects($this->once())
50+
->method('__invoke')
51+
->will($this->returnValue([]));
52+
53+
$this->dispatch('/user');
54+
55+
$this->assertControllerName('User\Controller\Index');
56+
$this->assertActionName('index');
57+
$this->assertTemplateName('user/index/index');
58+
$this->assertResponseStatusCode(HttpResponse::STATUS_CODE_200);
59+
}
60+
}

0 commit comments

Comments
 (0)