/** * Test if objects are being passed the service locator */ function testServiceLocatorAwareMustBeGivenServiceLocator() { $this->request->setPost(new Parameters(array('extAction' => 'KJSenchaTestAsset.Direct.ServiceAction', 'extMethod' => 'getServiceResult', 'extTID' => 0, 'extModule' => null))); $this->controller->setDebugMode(true); $result = $this->controller->dispatch($this->request); $this->assertEquals('pong!', $result->result); }
/** * @covers \KJSencha\Controller\DirectController::setDebugMode * @covers \KJSencha\Controller\DirectController::isDebugMode */ function testShowErrorResponseWhenDebugModeIsOn() { $this->request->setPost(new Parameters(array('extAction' => 'KJSenchaTestAsset.Direct.ErrorGenerator', 'extMethod' => 'throwException', 'extTID' => 0, 'extModule' => null))); $this->controller->setDebugMode(true); $result = $this->controller->dispatch($this->request); $this->assertEquals('exception', $result->type); $this->assertEquals('Exception!', $result->message); $this->assertNotEmpty($result->where); }
public function testGridData() { $entityClassName = '\\SynergyDataGridTest\\Entity\\TestBrand'; $this->_grid->setGridIdentity($entityClassName); $this->_grid->setCustomQueryBuilder(new QueryBuilder($this->_grid->getModel()->getEntityManager())); $this->_grid->setDatatype('local'); $this->_grid->getOptions(); $params = array('page' => 1, 'rows' => 25, 'sord' => 'asc', 'sidx' => 'id', BaseGrid::GRID_IDENTIFIER => $this->_grid->getId(), BaseGrid::ENTITY_IDENTFIER => $this->_grid->getEntity()); $request = new Request(); $parameters = new Parameters($params); $request->setPost($parameters); $this->_grid->prepareGridData($request); /** @var $viewHelper \SynergyDataGrid\View\Helper\DisplayGrid */ $viewHelper = $this->_serviceManager->get('viewhelpermanager')->get('displayGrid'); $viewHelper->setView(new PhpRenderer()); $data = $viewHelper($this->_grid, false); $this->assertArrayHasKey('html', $data); $this->assertArrayHasKey('js', $data); $this->assertArrayHasKey('onLoad', $data); }
public function testIndexAction_WithValidPostRequest() { $postData = array('name' => uniqid('name'), 'email' => uniqid('email') . '@' . uniqid('host') . '.com.pl'); $request = new Request(); $request->setMethod(Request::METHOD_POST); $request->setPost(new Parameters($postData)); $this->formMock->expects($this->once())->method('setData')->with($postData); $this->formMock->expects($this->once())->method('isValid')->willReturn(true); $registerInputFilter = new RegisterInputFilter(); $registerInputFilter->add(array('name' => 'captcha')); $this->formMock->expects($this->once())->method('getInputFilter')->willReturn($registerInputFilter); $this->serviceMock->expects($this->once())->method('proceed'); $result = $this->controller->dispatch($request); $expected = array('form' => $this->formMock); $this->assertResponseStatusCode(Response::STATUS_CODE_200); $this->assertSame($expected, $result); // TODO: reactivate //$fm = $this->controller->flashMessenger(); //$fm->setNamespace(Notification::NAMESPACE_SUCCESS); //$expectedMessages = array( // 'An Email with an activation link has been sent, please try to check your email box' //); //$this->assertSame($expectedMessages, $fm->getCurrentMessages()); }
public function testRetrievingASingleValueForParameters() { $request = new Request(); $p = new \Zend\Stdlib\Parameters(array('foo' => 'bar')); $request->setQuery($p); $request->setPost($p); $request->setFiles($p); $request->setServer($p); $request->setEnv($p); $this->assertSame('bar', $request->getQuery('foo')); $this->assertSame('bar', $request->getPost('foo')); $this->assertSame('bar', $request->getFiles('foo')); $this->assertSame('bar', $request->getServer('foo')); $this->assertSame('bar', $request->getEnv('foo')); $headers = new Headers(); $h = new GenericHeader('foo', 'bar'); $headers->addHeader($h); $request->setHeaders($headers); $this->assertSame($headers, $request->getHeaders()); $this->assertSame($h, $request->getHeaders()->get('foo')); $this->assertSame($h, $request->getHeader('foo')); }
/** * @param $request * @return array|mixed|User * @throws \Exception */ public function login($request) { $adapter = $this->getAuthPlugin()->getAuthAdapter(); $pin = $request->get('pin'); $accountId = $request->get('accountId'); if (!empty($pin)) { $user = $this->getUserByPin($pin, $accountId); $credentials = array('username' => $user->getUsername(), 'password' => $user->getPassword()); } else { $credentials = array('username' => $request->get('username'), 'password' => $request->get('password')); } $params = new Parameters(); $params->set('identity', $credentials['username']); $params->set('credential', $credentials['password']); $emulatedRequest = new Request(); $emulatedRequest->setPost($params); $result = $adapter->prepareForAuthentication($emulatedRequest); if ($result instanceof Response) { return $result; } $auth = $this->getAuthPlugin()->getAuthService()->authenticate($adapter); if (!$auth->isValid()) { $isRegistered = $this->isRegistered($credentials); $accountUser = $this->getAccountUsersByParams($params); if ($accountUser != null && !$isRegistered) { if ($this->getAgencyIsDeleted($accountUser->getAccountId())) { throw new \Exception(self::AGENCY_DELETED_MESSAGE); } return $this->createUserFromAccountUsers($accountUser); } $account = $this->getAccountByParams($params); if ($account != null && !$isRegistered) { return $this->createUserFromAccount($account); } if ($accountUser != null && $isRegistered) { return $this->updateUser($accountUser); } $result = $auth->getMessages(); $message = "Bad request."; if (isset($result[0])) { $message = $result[0]; } throw new \Exception($message); } $accountUser = $this->getAccountUsersByParams($params); if ($this->getAgencyIsDeleted($accountUser->getAccountId())) { throw new \Exception(self::AGENCY_DELETED_MESSAGE); } if ($this->getUserIsDeleted($credentials['username'])) { throw new \Exception(self::USER_DELETED_MESSAGE); } $user = $this->getAuthPlugin()->getIdentity(); return $user; }
public function testIndexAction_WithPostRequest() { $postData = array('identity' => uniqid('identity')); $request = new Request(); $request->setMethod(Request::METHOD_POST); $request->setPost(new Parameters($postData)); $this->formMock->expects($this->once())->method('setData')->with($postData); $this->formMock->expects($this->once())->method('isValid')->willReturn(true); $this->formMock->expects($this->once())->method('getInputFilter')->willReturn(new ForgotPasswordInputFilter()); $this->serviceMock->expects($this->once())->method('proceed'); $result = $this->controller->dispatch($request); $expected = array('form' => $this->formMock); $this->assertResponseStatusCode(Response::STATUS_CODE_200); $this->assertSame($expected, $result); //$fm = $this->controller->flashMessenger(); //$fm->setNamespace(Notification::NAMESPACE_SUCCESS); //$expectedMessages = array( // 'Mail with link for reset password has been sent, please try to check your email box' //); //$this->assertSame($expectedMessages, $fm->getCurrentMessages()); }
public function testIndexAction_WithPostRequest() { $postData = array('valid data'); $request = new Request(); $request->setMethod(Request::METHOD_POST); $request->setPost(new Parameters($postData)); $userEntity = UserEntityProvider::createEntityWithRandomData(); $this->authenticationServiceMock->expects($this->once())->method('getUser')->willReturn($userEntity); $this->formMock->expects($this->once())->method('bind')->with($userEntity); $this->formMock->expects($this->once())->method('setData')->with($postData); $this->formMock->expects($this->once())->method('isValid')->willReturn(true); $this->repositoriesMock->expects($this->once())->method('store')->with($userEntity); $result = $this->controller->dispatch($request); $expected = array('valid' => true, 'form' => $this->formMock); $this->assertResponseStatusCode(Response::STATUS_CODE_200); $this->assertSame($expected, $result); }
public function initGrid(BaseGrid $grid) { $html = array(); $js = array(); $onLoad = array(); $postCommand = array(); $showToolbar = false; $jsPager = ''; $htmlPager = ''; $config = $grid->getConfig(); $gridId = $grid->getId(); $grid->setActionsColumn($config['add_action_column']); $grid->setGridColumns()->setGridDisplayOptions()->setAllowEditForm($config['allow_form_edit']); $onLoad[] = 'var ' . $grid->getLastSelectVariable() . '; '; $onLoad[] = sprintf('var obj_%s = jQuery("#%s").addClass("synergy-grid").data("padding", %d);', $gridId, $gridId, $grid->getJsCode()->getPadding()); $onLoad[] = sprintf('obj_%s.parent().addClass("%s");', $gridId, $grid->getJsCode()->getContainerClass()); $onLoad[] = sprintf('obj_%s.data("lastsel", 0);', $gridId); if (!$grid->getEditurl()) { $grid->setEditurl($grid->getUrl()); } //add custom toolbar buttons list(, $toolbarPosition) = $grid->getToolbar(); if (!($showToolbar = ($config['toolbar_buttons']['global'] or isset($config['toolbar_buttons']['specific'][$grid->getEntityId()])))) { $grid->setToolbar(false); } //get previous sort order from cookie if set $grid->prepareSorting(); //get number per page if set in cookie $grid->preparePaging(); //load first data for main grid and not subgrids if ($config['first_data_as_local'] and !$grid->getIsDetailGrid()) { $grid->setDatatype('local'); $gridOptions = $grid->getOptions(); $params = array('page' => 1, 'rows' => $gridOptions['rowNum'], $grid::GRID_IDENTIFIER => $grid->getId(), $grid::ENTITY_IDENTFIER => $grid->getEntity()); if ($grid->getIsTreeGrid()) { $grid->setSortname('lft'); $params['displayTree'] = true; if (isset($gridOptions['postData'])) { $params = array_merge($params, $gridOptions['postData']); } } $request = new Request(); $parameters = new Parameters($params); $request->setPost($parameters); $initialData = $grid->getFirstDataAsLocal($request, true); $postCommand[] = sprintf('obj_%s.jqGrid("setGridParam", {datatype:"json", treedatatype : "json"});', $gridId, $grid->getEditurl()); $postCommand[] = sprintf('obj_%s[0].addJSONData(%s) ;', $gridId, Json::encode($initialData)); } $grid->getJsCode()->prepareAfterInsertRow(); $grid->getJsCode()->prepareAfterSaveRow(); $grid->getJsCode()->prepareOnEditRow(); $grid->getJsCode()->prepareAfterRestoreRow(); if ($grid->getAllowResizeColumns()) { $grid->prepareColumnSizes(); } //Add subgrid as grid data. This will override any subgrid if ($grid instanceof SubGridAwareInterface and $subGrids = $grid->getSubGridsAsGrid()) { $l = $s = $h = array(); foreach ($subGrids as $subGrid) { list($l[], $s[], $h[]) = $this->initGrid($subGrid); } $expandFunction = new Expr(sprintf("function(subgrid_id, row_id) {\n jQuery('#'+subgrid_id).html('%s');\n %s\n %s\n }", implode("<hr />", $h), implode("\n", $l), implode("\n", $s))); /** @var $grid \SynergyDataGrid\Grid\GridType\BaseGrid */ $grid->setSubGridRowExpanded($expandFunction); } $onLoad[] = $grid->getJsCode()->prepareSetColumnsOrderingCookie(); $grid->reorderColumns(); $onLoad[] = sprintf('obj_%s.jqGrid(%s);', $gridId, Json::encode($grid->getOptions(), false, array('enableJsonExprFinder' => true))); $datePicker = $grid->getDatePicker()->prepareDatepicker(); $js = array_merge($js, $datePicker); $html[] = '<table id="' . $gridId . '"></table>'; if ($grid->getNavGridEnabled()) { if ($grid->getIsDetailGrid()) { $grid->getNavGrid()->setSearch(false); } $options = $grid->getNavGrid()->getOptions() ?: new \stdClass(); $prmEdit = $grid->getNavGrid()->getEditParameters() ?: new \stdClass(); $prmAdd = $grid->getNavGrid()->getAddParameters() ?: new \stdClass(); $prmDel = $grid->getNavGrid()->getDeleteParameters() ?: new \stdClass(); $prmSearch = $grid->getNavGrid()->getSearchParameters() ?: new \stdClass(); $prmView = $grid->getNavGrid()->getViewParameters() ?: new \stdClass(); $jsPager = sprintf('obj_%s.jqGrid("navGrid","#%s",%s,%s,%s,%s,%s,%s);', $gridId, $grid->getPager(), Json::encode($options, false, array('enableJsonExprFinder' => true)), Json::encode($prmEdit, false, array('enableJsonExprFinder' => true)), Json::encode($prmAdd, false, array('enableJsonExprFinder' => true)), Json::encode($prmDel, false, array('enableJsonExprFinder' => true)), Json::encode($prmSearch, false, array('enableJsonExprFinder' => true)), Json::encode($prmView, false, array('enableJsonExprFinder' => true))); //display filter toolbar if ($config['filter_toolbar']['enabled']) { $onLoad[] = sprintf('obj_%s.jqGrid("filterToolbar",%s);', $gridId, Json::encode($config['filter_toolbar']['options'], false, array('enableJsonExprFinder' => true))); if (!$config['filter_toolbar']['showOnLoad']) { $onLoad[] = sprintf('obj_%s[0].toggleToolbar();', $gridId); } } $navButtons = $grid->getNavButtons(); if (is_array($navButtons)) { foreach ($navButtons as $title => $button) { $jsPager .= sprintf('obj_%s.navButtonAdd("#%s",{ caption: "%s", title: "%s", buttonicon: "%s", onClickButton: %s, position: "%s", cursor: "%s", id: "%s" }); ', $gridId, $grid->getPager(), $button['caption'], $title, $button['icon'], $button['action'], $button['position'], $button['cursor'], $button['id']); } } $htmlPager = '<div id="' . $grid->getPager() . '"></div>'; } $onLoad[] = $jsPager; $html[] = $htmlPager; //setup inline navigation if ($grid->getInlineNavEnabled() and $grid->getInlineNav()) { $jsInline = sprintf('obj_%s.jqGrid("inlineNav", "#%s",%s)', $gridId, $grid->getPager(), Json::encode($grid->getInlineNav()->getOptions(), false, array('enableJsonExprFinder' => true))); $jsInline .= ';'; $onLoad[] = $jsInline; $onLoad[] = $grid->getProcessAfterSubmit(); if (!$htmlPager) { $html[] = '<div id="' . $grid->getPager() . '"></div>'; } } //add custom toolbar buttons if ($showToolbar) { if ($toolbarPosition == Toolbar::POSITION_BOTH) { $toolbars[] = new Toolbar($grid, $config['toolbar_buttons'], Toolbar::POSITION_BOTTOM, $toolbarPosition); $toolbars[] = new Toolbar($grid, $config['toolbar_buttons'], Toolbar::POSITION_TOP, $toolbarPosition); } elseif ($toolbarPosition == Toolbar::POSITION_BOTTOM) { $toolbars[] = new Toolbar($grid, $config['toolbar_buttons'], Toolbar::POSITION_BOTTOM, $toolbarPosition); } else { $toolbars[] = new Toolbar($grid, $config['toolbar_buttons'], Toolbar::POSITION_TOP, $toolbarPosition); } $onLoad[] = sprintf("; synergyDataGrid['%s'] = obj_%s;", $gridId, $gridId); /** @var $toolbar \SynergyDataGrid\Grid\Toolbar */ foreach ($toolbars as $toolbar) { $toolbarId = $toolbar->getId(); $toolbarPosition = $toolbar->getPosition(); $onLoad[] = sprintf("var %s = jQuery('#%s');", $toolbarId, $toolbarId); $onLoad[] = sprintf("; %s.addClass('grid-toolbar btn-group grid-toolbar-%s');", $toolbarId, $toolbarPosition); /** @var $toolbarButton \SynergyDataGrid\Grid\Toolbar\Item */ foreach ($toolbar->getItems() as $toolbarButton) { $buttonPosition = $toolbarButton->getPosition(); if ($buttonPosition == Toolbar::POSITION_BOTH or $buttonPosition == $toolbarPosition) { $onLoad[] = sprintf("%s.append(\"<button data-grid-id='%s' data-toolbar-id='%s' id='%s' title='%s' class='%s' %s><i class='icon %s'></i> %s</button>\");\n jQuery('#%s', '#%s').bind('click', %s);", $toolbarId, $gridId, $toolbarId, $toolbarButton->getId(), $toolbarButton->getTitle(), $toolbarButton->getClass(), $toolbarButton->getAttributes(), $toolbarButton->getIcon(), $toolbarButton->getTitle(), $toolbarButton->getId(), $toolbar->getId(), Json::encode($toolbarButton->getCallback(), false, array('enableJsonExprFinder' => true))); if ($init = $toolbarButton->getOnLoad()) { $onLoad[] = Json::encode($init, false, array('enableJsonExprFinder' => true)); } } } } } $onLoad = array_merge($onLoad, $postCommand); $onLoad = array_filter($onLoad); foreach ($grid->getJsCode()->getCustomScripts() as $script) { $onLoad[] = Json::encode($script, false, array('enableJsonExprFinder' => true)); } $onLoad[] = sprintf("; synergyResizeGrid('#%s', '.%s');", $grid->getId(), $grid->getJsCode()->getContainerClass()); $html = array_merge($html, $grid->getHtml()); $js = array_merge($js, $grid->getJs()); $js[] = $grid->getJsCode()->renderActionsFormatter(); $onLoad = array_merge($onLoad, $grid->getOnload()); if ($config['compress_script']) { $onLoad = $this->compressJavaScriptScript($onLoad); $js = $this->compressJavaScriptScript($js); } return array(implode("\n", $onLoad), implode("\n", $js), implode("", $html)); }