public function testResolveBreadCrumbViewForDetailsControllerAction() { TestHelpers::createControllerAndModuleByRoute('accounts/default'); $controller = Yii::app()->getController(); $model = new Account(); //Test when there is not a stickyLoadUrl $stickySearchKey = 'abc'; $view = StickySearchUtil::resolveBreadCrumbViewForDetailsControllerAction($controller, $stickySearchKey, $model); $this->assertTrue($view instanceof StickyDetailsAndRelationsBreadCrumbView); $content = $view->render(); $this->assertNotContains('stickyModelId', $content); //Test when there is a stickyLoadUrl $stickySearchKey = 'abc'; Yii::app()->user->setState($stickySearchKey, serialize(array('a', 'b'))); $_GET['stickyOffset'] = '5'; $view = StickySearchUtil::resolveBreadCrumbViewForDetailsControllerAction($controller, $stickySearchKey, $model); $this->assertTrue($view instanceof StickyDetailsAndRelationsBreadCrumbView); $content = $view->render(); $this->assertContains('stickyListLoadingArea', $content); }
public function testResolveAccessCanCurrentUserReadModel() { Yii::app()->user->userModel = User::getByUsername('super'); $accounts = Account::getByName('Supermart'); $this->assertEquals(1, count($accounts)); $betty = User::getByUsername('betty'); Yii::app()->user->userModel = $betty; TestHelpers::createControllerAndModuleByRoute('accounts/default'); $this->startOutputBuffer(); try { ControllerSecurityUtil::resolveAccessCanCurrentUserReadModel($accounts[0], true); $this->endPrintOutputBufferAndFail(); } catch (ExitException $e) { $content = $this->endAndGetOutputBuffer(); $this->assertEquals('failure', $content); } $this->startOutputBuffer(); try { ControllerSecurityUtil::resolveAccessCanCurrentUserReadModel($accounts[0], false); $this->endPrintOutputBufferAndFail(); } catch (ExitException $e) { $compareString = 'You have tried to access a page you do not have access to'; $this->assertContains($compareString, $this->endAndGetOutputBuffer()); } Yii::app()->user->userModel = User::getByUsername('super'); $account = AccountTestHelper::createAccountByNameForOwner('BettyInc', $betty); $this->startOutputBuffer(); try { ControllerSecurityUtil::resolveAccessCanCurrentUserReadModel($account, true); ControllerSecurityUtil::resolveAccessCanCurrentUserReadModel($account, false); $content = $this->endAndGetOutputBuffer(); $this->assertEquals(null, $content); } catch (ExitException $e) { $this->endPrintOutputBufferAndFail(); } }