How to use setPermissions method of controller class

Best Atoum code snippet using controller.setPermissions

AbstractTableControllerTest.php

Source:AbstractTableControllerTest.php Github

copy

Full Screen

...83 */84 public function check_magic_create_call_unauthorized()85 {86 $this->expectException(UnauthorizedException::class);87 $this->controller->setPermissions('unauthorized');88 $this->controller->handleCreate($this->createRequest());89 }90 /**91 * @test92 */93 public function check_magic_create_call_permission_denied()94 {95 $this->expectException(PermissionDenied::class);96 $this->controller->crud()->actions()->find('create')->check(function () {97 return false;98 });99 $this->controller->handleCreate($this->createRequest());100 }101 /**102 * @test103 */104 public function check_magic_create_call_unauthorized_response()105 {106 $this->controller->setPermissions('unauthorized');107 $response = $this->controller->create($this->createRequest());108 $this->assertEquals(109 $this->controller->createUnauthorizedResponse($this->createRequest(), UnauthorizedException::forPermissions(['create'])),110 $response111 );112 }113 /**114 * @test115 */116 public function check_magic_list_call()117 {118 $baseView = $this->controller->handleList($this->createRequest());119 $magicView = $this->controller->list($this->createRequest());120 $this->assertInstanceOf(View::class, $magicView);121 $this->assertEquals($baseView, $magicView);122 }123 /**124 * @test125 */126 public function check_magic_list_call_unauthorized()127 {128 $this->expectException(UnauthorizedException::class);129 $this->controller->setPermissions('unauthorized');130 $this->controller->handleList($this->createRequest());131 }132 /**133 * @test134 */135 public function check_magic_list_call_unauthorized_response()136 {137 $this->controller->setPermissions('unauthorized');138 $response = $this->controller->list($this->createRequest());139 $this->assertEquals(140 $this->controller->createUnauthorizedResponse($this->createRequest(), UnauthorizedException::forPermissions(['list'])),141 $response142 );143 }144 /**145 * @test146 */147 public function check_magic_search_call()148 {149 $baseRedirect = $this->controller->handleSearch($this->createRequest());150 $magicRedirect = $this->controller->search($this->createRequest());151 $this->assertInstanceOf(RedirectResponse::class, $baseRedirect);152 $this->assertEquals($baseRedirect->header('date', 'Fri, 01 Jan 1990 00:00:00 GMT'), $magicRedirect->header('date', 'Fri, 01 Jan 1990 00:00:00 GMT'));153 }154 /**155 * @test156 */157 public function check_magic_search_call_unauthorized()158 {159 $this->expectException(UnauthorizedException::class);160 $this->controller->setPermissions('unauthorized');161 $this->controller->handleSearch($this->createRequest());162 }163 /**164 * @test165 */166 public function check_magic_search_call_unauthorized_response()167 {168 $this->controller->setPermissions('unauthorized');169 $response = $this->controller->search($this->createRequest());170 $this->assertEquals(171 $this->controller->createUnauthorizedResponse($this->createRequest(), UnauthorizedException::forPermissions(['search'])),172 $response173 );174 }175 /**176 * @test177 */178 public function check_magic_store_call()179 {180 $baseRedirect = $this->controller->handleStore($this->createRequest());181 $magicRedirect = $this->controller->store($this->createRequest());182 $this->assertInstanceOf(RedirectResponse::class, $baseRedirect);183 $this->assertEquals($baseRedirect->header('date', 'Fri, 01 Jan 1990 00:00:00 GMT'), $magicRedirect->header('date', 'Fri, 01 Jan 1990 00:00:00 GMT'));184 }185 /**186 * @test187 */188 public function check_magic_store_call_permission_denied()189 {190 $this->expectException(PermissionDenied::class);191 $this->controller->crud()->actions()->find('create')->check(function () {192 return false;193 });194 $this->controller->handleStore($this->createRequest());195 }196 /**197 * @test198 */199 public function check_magic_store_call_unauthorized()200 {201 $this->expectException(UnauthorizedException::class);202 $this->controller->setPermissions('unauthorized');203 $this->controller->handleStore($this->createRequest());204 }205 /**206 * @test207 */208 public function check_magic_store_call_unauthorized_response()209 {210 $this->controller->setPermissions('unauthorized');211 $response = $this->controller->store($this->createRequest());212 $this->assertEquals(213 $this->controller->createUnauthorizedResponse($this->createRequest(), UnauthorizedException::forPermissions(['store'])),214 $response215 );216 }217 /**218 * @test219 */220 public function check_magic_edit_call()221 {222 $model = Model::first();223 $baseView = $this->controller->handleEdit($this->createRequest(), $model->id);224 $magicView = $this->controller->edit($this->createRequest(), $model->id);225 $this->assertInstanceOf(View::class, $baseView);226 $this->assertEquals($baseView, $magicView);227 }228 /**229 * @test230 */231 public function check_magic_edit_call_permission_denied()232 {233 $this->expectException(PermissionDenied::class);234 $model = Model::first();235 $this->controller->crud()->actions()->find('edit')->check(function () {236 return false;237 });238 $this->controller->handleEdit($this->createRequest(), $model->id);239 }240 /**241 * @test242 */243 public function check_magic_edit_call_unauthorized()244 {245 $this->expectException(UnauthorizedException::class);246 $model = Model::first();247 $this->controller->setPermissions('unauthorized');248 $this->controller->handleEdit($this->createRequest(), $model->id);249 }250 /**251 * @test252 */253 public function check_magic_edit_call_unauthorized_response()254 {255 $this->controller->setPermissions('unauthorized');256 $model = Model::first();257 $response = $this->controller->edit($this->createRequest(), $model->id);258 $this->assertEquals(259 $this->controller->createUnauthorizedResponse($this->createRequest(), UnauthorizedException::forPermissions(['edit'])),260 $response261 );262 }263 /**264 * @test265 */266 public function check_magic_update_call()267 {268 $model = Model::first();269 $baseRedirect = $this->controller->handleUpdate($this->createRequest(), $model->id);270 $magicRedirect = $this->controller->update($this->createRequest(), $model->id);271 $this->assertInstanceOf(RedirectResponse::class, $baseRedirect);272 $this->assertEquals($baseRedirect->header('date', 'Fri, 01 Jan 1990 00:00:00 GMT'), $magicRedirect->header('date', 'Fri, 01 Jan 1990 00:00:00 GMT'));273 }274 /**275 * @test276 */277 public function check_magic_update_call_permission_denied()278 {279 $this->expectException(PermissionDenied::class);280 $model = Model::first();281 $this->controller->crud()->actions()->find('edit')->check(function () {282 return false;283 });284 $this->controller->handleUpdate($this->createRequest(), $model->id);285 }286 /**287 * @test288 */289 public function check_magic_update_call_unauthorized()290 {291 $this->expectException(UnauthorizedException::class);292 $model = Model::first();293 $this->controller->setPermissions('unauthorized');294 $this->controller->handleUpdate($this->createRequest(), $model->id);295 }296 /**297 * @test298 */299 public function check_magic_update_call_unauthorized_response()300 {301 $this->controller->setPermissions('unauthorized');302 $model = Model::first();303 $response = $this->controller->update($this->createRequest(), $model->id);304 $this->assertEquals(305 $this->controller->createUnauthorizedResponse($this->createRequest(), UnauthorizedException::forPermissions(['update'])),306 $response307 );308 }309 /**310 * @test311 */312 public function check_magic_delete_call()313 {314 $baseRedirect = $this->controller->handleDelete($this->createRequest(), Model::first()->id);315 $magicRedirect = $this->controller->delete($this->createRequest(), Model::first()->id);316 $this->assertInstanceOf(JsonResponse::class, $baseRedirect);317 $this->assertInstanceOf(JsonResponse::class, $magicRedirect);318 }319 /**320 * @test321 */322 public function check_magic_delete_call_unauthorized()323 {324 $this->expectException(UnauthorizedException::class);325 $model = Model::first();326 $this->controller->setPermissions('unauthorized');327 $this->controller->handleDelete($this->createRequest(), $model->id);328 }329 /**330 * @test331 */332 public function check_magic_delete_call_permission_denied()333 {334 $this->expectException(PermissionDenied::class);335 $model = Model::first();336 $this->controller->crud()->actions()->find('delete')->check(function () {337 return false;338 });339 $this->controller->handleDelete($this->createRequest(), $model->id);340 }341 /**342 * @test343 */344 public function check_magic_delete_call_unauthorized_response()345 {346 $this->controller->setPermissions('unauthorized');347 $model = Model::first();348 $response = $this->controller->delete($this->createRequest(), $model->id);349 $this->assertEquals(350 $this->controller->createUnauthorizedResponse($this->createRequest(), UnauthorizedException::forPermissions(['delete'])),351 $response352 );353 }354 /**355 * @test356 */357 public function check_unavailable_magic_call()358 {359 $magicRedirect = $this->controller->notexistedmethod($this->createRequest());360 $this->assertInstanceOf(RedirectResponse::class, $magicRedirect);361 $this->assertEquals(session()->get('jarboe_notifications.big'), [[362 'title' => 'RuntimeException',363 'content' => 'Invalid method notexistedmethod',364 'color' => '#C46A69',365 'icon' => 'fa fa-warning shake animated',366 'timeout' => 0,367 ]]);368 }369 /**370 * @test371 */372 public function check_magic_restore_call()373 {374 $model = Model::first();375 $baseResponse = $this->controller->handleRestore($this->createRequest(), $model->id);376 $magicResponse = $this->controller->restore($this->createRequest(), $model->id);377 $this->assertInstanceOf(JsonResponse::class, $baseResponse);378 $this->assertEquals(Response::HTTP_OK, $magicResponse->getStatusCode());379 $this->assertEquals($baseResponse->header('date', 'Fri, 01 Jan 1990 00:00:00 GMT'), $magicResponse->header('date', 'Fri, 01 Jan 1990 00:00:00 GMT'));380 }381 /**382 * @test383 */384 public function check_magic_restore_call_unsuccessful()385 {386 Model::restoring(function ($model) {387 return false;388 });389 $model = Model::first();390 $baseResponse = $this->controller->handleRestore($this->createRequest(), $model->id);391 $magicResponse = $this->controller->restore($this->createRequest(), $model->id);392 $this->assertInstanceOf(JsonResponse::class, $baseResponse);393 $this->assertEquals(Response::HTTP_UNPROCESSABLE_ENTITY, $magicResponse->getStatusCode());394 $this->assertEquals($baseResponse->header('date', 'Fri, 01 Jan 1990 00:00:00 GMT'), $magicResponse->header('date', 'Fri, 01 Jan 1990 00:00:00 GMT'));395 }396 /**397 * @test398 */399 public function check_magic_restore_call_unauthorized()400 {401 $this->expectException(UnauthorizedException::class);402 $model = Model::first();403 $this->controller->setPermissions('unauthorized');404 $this->controller->handleRestore($this->createRequest(), $model->id);405 }406 /**407 * @test408 */409 public function check_magic_restore_call_permission_denied()410 {411 $this->expectException(PermissionDenied::class);412 $this->controller->disableSoftDelete();413 $this->controller->handleRestore($this->createRequest(), 1);414 }415 /**416 * @test417 */418 public function check_magic_restore_call_permission_denied_by_action()419 {420 $this->expectException(PermissionDenied::class);421 $this->controller->crud()->actions()->find('restore')->check(function () {422 return false;423 });424 $this->controller->handleRestore($this->createRequest(), 1);425 }426 /**427 * @test428 */429 public function check_magic_restore_call_unauthorized_response()430 {431 $this->controller->setPermissions('unauthorized');432 $model = Model::first();433 $response = $this->controller->restore($this->createRequest(), $model->id);434 $this->assertEquals(435 $this->controller->createUnauthorizedResponse($this->createRequest(), UnauthorizedException::forPermissions(['restore'])),436 $response437 );438 }439 /**440 * @test441 */442 public function check_magic_force_delete_call()443 {444 $model = Model::first();445 $model->delete();446 $baseResponse = $this->controller->handleForceDelete($this->createRequest(), $model->id);447 $model = Model::first();448 $model->delete();449 $magicResponse = $this->controller->forceDelete($this->createRequest(), $model->id);450 $this->assertInstanceOf(JsonResponse::class, $baseResponse);451 $this->assertInstanceOf(JsonResponse::class, $magicResponse);452 }453 /**454 * @test455 */456 public function check_magic_force_delete_call_unauthorized()457 {458 $this->expectException(UnauthorizedException::class);459 $model = Model::first();460 $model->delete();461 $this->controller->setPermissions('unauthorized');462 $this->controller->handleForceDelete($this->createRequest(), $model->id);463 }464 /**465 * @test466 */467 public function check_magic_force_delete_permission_denied_by_action()468 {469 $this->expectException(PermissionDenied::class);470 $model = Model::first();471 $model->delete();472 $this->controller->crud()->actions()->find('force-delete')->check(function () {473 return false;474 });475 $this->controller->handleForceDelete($this->createRequest(), $model->id);476 }477 /**478 * @test479 */480 public function check_magic_force_delete_non_trashed_model_call_permission_denied()481 {482 $this->expectException(PermissionDenied::class);483 $model = Model::first();484 $this->controller->handleForceDelete($this->createRequest(), $model->id);485 }486 /**487 * @test488 */489 public function check_magic_force_delete_non_soft_delete_crud_call_permission_denied()490 {491 $this->expectException(PermissionDenied::class);492 $this->controller->disableSoftDelete();493 $model = Model::first();494 $model->delete();495 $this->controller->handleForceDelete($this->createRequest(), $model->id);496 }497 /**498 * @test499 */500 public function check_magic_force_delete_call_unauthorized_response()501 {502 $this->controller->setPermissions('unauthorized');503 $model = Model::first();504 $model->delete();505 $response = $this->controller->forceDelete($this->createRequest(), $model->id);506 $this->assertEquals(507 $this->controller->createUnauthorizedResponse($this->createRequest(), UnauthorizedException::forPermissions(['force-delete'])),508 $response509 );510 }511 /**512 * @test513 */514 public function check_magic_inline_call()515 {516 $model = Model::first();517 $data = [518 '_pk' => $model->id,519 '_value' => 'text',520 '_name' => 'title',521 ];522 $baseResponse = $this->controller->handleInline($this->createRequest($data));523 $this->app->offsetSet('request', $this->createRequest($data));524 $magicResponse = $this->controller->inline();525 $this->assertInstanceOf(JsonResponse::class, $baseResponse);526 $this->assertEquals($baseResponse->header('date', 'Fri, 01 Jan 1990 00:00:00 GMT'), $magicResponse->header('date', 'Fri, 01 Jan 1990 00:00:00 GMT'));527 }528 /**529 * @test530 */531 public function check_magic_inline_call_unauthorized()532 {533 $this->expectException(UnauthorizedException::class);534 $this->controller->setPermissions('unauthorized');535 $this->controller->handleInline($this->createRequest());536 }537 /**538 * @test539 */540 public function check_magic_inline_call_unauthorized_response()541 {542 $this->controller->setPermissions('unauthorized');543 $response = $this->controller->inline($this->createRequest());544 $this->assertEquals(545 $this->controller->createUnauthorizedResponse($this->createRequest(), UnauthorizedException::forPermissions(['inline'])),546 $response547 );548 }549 /**550 * @test551 */552 public function add_tools_helper()553 {554 $tools = [555 new ShowHideColumnsTool(),556 new MassDeleteTool(),557 ];558 $controller = new class extends AbstractTableController {559 public function init()560 {561 $this->setModel(Model::class);562 $this->softDeletes();563 $this->filter(function ($model) {564 $model->withTrashed();565 });566 $this->addFields([567 Text::make('title')->inline(),568 Text::make('description'),569 ]);570 $this->addTools([571 new ShowHideColumnsTool(),572 new MassDeleteTool(),573 ]);574 }575 public function crud(): CRUD576 {577 return $this->crud;578 }579 public function bound()580 {581 parent::bound();582 }583 };584 $controller->init();585 $controller->bound();586 $tools[0]->setCrud($controller->crud());587 $tools[1]->setCrud($controller->crud());588 $this->assertEquals($tools[0], $controller->crud()->getTool($tools[0]->identifier()));589 $this->assertEquals($tools[1], $controller->crud()->getTool($tools[1]->identifier()));590 $this->assertEquals(591 [592 $tools[0]->identifier() => $tools[0],593 $tools[1]->identifier() => $tools[1],594 ],595 $controller->crud()->getTools()596 );597 }598 /**599 * @test600 */601 public function add_tool_helper()602 {603 $tool = new ShowHideColumnsTool();604 $controller = new class extends AbstractTableController {605 public function init()606 {607 $this->setModel(Model::class);608 $this->softDeletes();609 $this->filter(function ($model) {610 $model->withTrashed();611 });612 $this->addFields([613 Text::make('title')->inline(),614 Text::make('description'),615 ]);616 $this->addTool(new ShowHideColumnsTool());617 }618 public function crud(): CRUD619 {620 return $this->crud;621 }622 public function bound()623 {624 parent::bound();625 }626 };627 $controller->init();628 $controller->bound();629 $tool->setCrud($controller->crud());630 $this->assertEquals($tool, $controller->crud()->getTool($tool->identifier()));631 $this->assertEquals(632 [633 $tool->identifier() => $tool,634 ],635 $controller->crud()->getTools()636 );637 }638 /**639 * @test640 */641 public function check_per_page_is_setted()642 {643 $this->controller->perPage(420);644 $this->assertEquals(420, $this->controller->crud()->getPerPageParam());645 }646 /**647 * @test648 */649 public function check_order_by_is_setted()650 {651 $response = $this->controller->orderBy('title', 'desc');652 $this->assertInstanceOf(RedirectResponse::class, $response);653 $this->assertEquals('desc', $this->controller->crud()->getOrderFilterParam('title'));654 $this->assertNull($this->controller->crud()->getOrderFilterParam('none'));655 }656 /**657 * @test658 */659 public function check_can_without_permissions()660 {661 $this->assertTrue($this->controller->can('some_permission'));662 }663 /**664 * @test665 */666 public function check_notify()667 {668 $this->controller->notify('title small', 'content small', 1200, '#bbbccc', 'fa fa-users', 'small');669 $this->controller->notify('title big', 'content big', 1000, '#bbbccc', 'fa fa-users', 'big');670 $this->assertEquals(671 [672 [673 'title' => 'title small',674 'content' => 'content small',675 'color' => '#bbbccc',676 'icon' => 'fa fa-users',677 'timeout' => 1200,678 ],679 ],680 session('jarboe_notifications.small')681 );682 $this->assertEquals(683 [684 [685 'title' => 'title big',686 'content' => 'content big',687 'color' => '#bbbccc',688 'icon' => 'fa fa-users',689 'timeout' => 1000,690 ],691 ],692 session('jarboe_notifications.big')693 );694 session()->flush();695 $this->controller->notifySmall('title small', 'content small', 1200, '#bbbccc', 'fa fa-users');696 $this->controller->notifyBig('title big', 'content big', 1000, '#bbbccc', 'fa fa-users');697 $this->assertEquals(698 [699 [700 'title' => 'title small',701 'content' => 'content small',702 'color' => '#bbbccc',703 'icon' => 'fa fa-users',704 'timeout' => 1200,705 ],706 ],707 session('jarboe_notifications.small')708 );709 $this->assertEquals(710 [711 [712 'title' => 'title big',713 'content' => 'content big',714 'color' => '#bbbccc',715 'icon' => 'fa fa-users',716 'timeout' => 1000,717 ],718 ],719 session('jarboe_notifications.big')720 );721 session()->flush();722 $this->controller->notifySmallSuccess('title small', 'content small', 1234);723 $this->controller->notifySmallDanger('title small', 'content small', 12345);724 $this->controller->notifySmallWarning('title small', 'content small', 12346);725 $this->controller->notifySmallInfo('title small', 'content small', 12347);726 $this->controller->notifyBigSuccess('title big', 'content big', 43214);727 $this->controller->notifyBigDanger('title big', 'content big', 43213);728 $this->controller->notifyBigWarning('title big', 'content big', 43212);729 $this->controller->notifyBigInfo('title big', 'content big', 43211);730 $this->assertEquals(731 [732 [733 'title' => 'title small',734 'content' => 'content small',735 'color' => '#739E73',736 'icon' => 'fa fa-check',737 'timeout' => 1234,738 ],739 [740 'title' => 'title small',741 'content' => 'content small',742 'color' => '#C46A69',743 'icon' => 'fa fa-warning shake animated',744 'timeout' => 12345,745 ],746 [747 'title' => 'title small',748 'content' => 'content small',749 'color' => '#C79121',750 'icon' => 'fa fa-shield fadeInLeft animated',751 'timeout' => 12346,752 ],753 [754 'title' => 'title small',755 'content' => 'content small',756 'color' => '#3276B1',757 'icon' => 'fa fa-bell swing animated',758 'timeout' => 12347,759 ],760 ],761 session('jarboe_notifications.small')762 );763 $this->assertEquals(764 [765 [766 'title' => 'title big',767 'content' => 'content big',768 'color' => '#739E73',769 'icon' => 'fa fa-check',770 'timeout' => 43214,771 ],772 [773 'title' => 'title big',774 'content' => 'content big',775 'color' => '#C46A69',776 'icon' => 'fa fa-warning shake animated',777 'timeout' => 43213,778 ],779 [780 'title' => 'title big',781 'content' => 'content big',782 'color' => '#C79121',783 'icon' => 'fa fa-shield fadeInLeft animated',784 'timeout' => 43212,785 ],786 [787 'title' => 'title big',788 'content' => 'content big',789 'color' => '#3276B1',790 'icon' => 'fa fa-bell swing animated',791 'timeout' => 43211,792 ],793 ],794 session('jarboe_notifications.big')795 );796 session()->flush();797 }798 /**799 * @test800 */801 public function check_default_additional_views()802 {803 $this->assertIsArray($this->controller->getListViewsAbove());804 $this->assertEmpty($this->controller->getListViewsAbove());805 $this->assertIsArray($this->controller->getListViewsBelow());806 $this->assertEmpty($this->controller->getListViewsBelow());807 $this->assertIsArray($this->controller->getEditViewsAbove());808 $this->assertEmpty($this->controller->getEditViewsAbove());809 $this->assertIsArray($this->controller->getEditViewsBelow());810 $this->assertEmpty($this->controller->getEditViewsBelow());811 $this->assertIsArray($this->controller->getCreateViewsAbove());812 $this->assertEmpty($this->controller->getCreateViewsAbove());813 $this->assertIsArray($this->controller->getCreateViewsBelow());814 $this->assertEmpty($this->controller->getCreateViewsBelow());815 }816 /**817 * @test818 */819 public function check_permissions()820 {821 $this->assertTrue($this->controller->can('any'));822 $this->controller->setPermissions([823 'existed' => 'permission',824 ]);825 $this->assertTrue($this->controller->can('any'));826 $this->assertFalse($this->controller->can('existed'));827 $this->controller->setPermissions('existed');828 $this->assertTrue($this->controller->can('list'));829 $this->assertFalse($this->controller->can('delete'));830 $this->assertFalse($this->controller->can('notexisted'));831 }832 /**833 * @test834 */835 public function check_unauthorized_response()836 {837 $exception = UnauthorizedException::forPermissions(['hey']);838 $request = $this->createRequest();839 $request->headers->set('Accept', 'text/json');840 $response = $this->controller->createUnauthorizedResponse($request, $exception);841 $this->assertInstanceOf(JsonResponse::class, $response);842 $response = $this->controller->createUnauthorizedResponse($this->createRequest(), $exception);843 $this->assertInstanceOf(View::class, $response);844 }845 /**846 * @test847 */848 public function check_validation_exception_should_be_validation_exception()849 {850 $this->expectException(ValidationException::class);851 $this->controller->overrideListMethodToThrowValidationException();852 $this->controller->list($this->createRequest());853 }854 /**855 * @test856 */857 public function check_breadcrumbs()858 {859 $this->controller->breadcrumbs()->add(Crumb::make('hai'));860 $this->controller->bound();861 $this->assertInstanceOf(BreadcrumbsInterface::class, $this->controller->breadcrumbs());862 $view = view('jarboe::crud.list');863 $view->getFactory()->callComposer($view);864 $this->assertEquals($this->controller->breadcrumbs(), $view->breadcrumbs);865 $view = view('jarboe::crud.create');866 $view->getFactory()->callComposer($view);867 $this->assertEquals($this->controller->breadcrumbs(), $view->breadcrumbs);868 $view = view('jarboe::crud.edit');869 $view->getFactory()->callComposer($view);870 $this->assertEquals($this->controller->breadcrumbs(), $view->breadcrumbs);871 }872 /**873 * @test874 */875 public function check_locales_alias()876 {877 $locales = [878 'en' => 'EN',879 'JP' => 'JP',880 ];881 $this->controller->locales($locales);882 $this->assertEquals($locales, $this->controller->crud()->getLocales());883 $locales = [884 'en',885 'JP',886 ];887 $this->controller->locales($locales);888 $this->assertEquals(array_combine($locales, $locales), $this->controller->crud()->getLocales());889 }890 /**891 * @test892 */893 public function check_add_column_alias_by_field()894 {895 $columns = $this->controller->crud()->getColumns();896 $this->assertEmpty($columns);897 $this->assertIsArray($columns);898 $this->assertEquals(899 $this->controller->crud()->getFields(),900 $this->controller->crud()->getColumnsAsFields()901 );902 $field = Text::make('title');903 $this->controller->addColumn($field);904 $columns = $this->controller->crud()->getColumns();905 $this->assertEquals([$field], $columns);906 }907 /**908 * @test909 */910 public function check_add_column_alias_by_identifier()911 {912 $columns = $this->controller->crud()->getColumns();913 $this->assertEmpty($columns);914 $this->assertIsArray($columns);915 $this->controller->init();916 $this->controller->bound();917 $this->controller->addColumn('description');918 $this->assertEquals(919 [$this->controller->crud()->getFieldByName('description')],920 $this->controller->crud()->getColumnsAsFields()921 );922 }923 /**924 * @test925 */926 public function check_add_column_alias_by_new_identifier()927 {928 $columns = $this->controller->crud()->getColumns();929 $this->assertEmpty($columns);930 $this->assertIsArray($columns);931 $this->controller->init();932 $this->controller->bound();933 $this->controller->addColumn('hi');934 $this->assertNull($this->controller->crud()->getFieldByName('hi'));935 $this->assertEquals(936 [Text::make('hi')],937 $this->controller->crud()->getColumnsAsFields()938 );939 }940 /**941 * @test942 */943 public function check_add_columns_alias()944 {945 $fields = [946 Text::make('title'),947 Textarea::make('description'),948 'hi',949 ];950 $this->controller->addColumns($fields);951 $this->assertNull($this->controller->crud()->getFieldByName('hi'));952 array_pop($fields);953 $fields[] = Text::make('hi');954 $this->assertEquals(955 $fields,956 $this->controller->crud()->getColumnsAsFields()957 );958 }959 /**960 * @test961 */962 public function check_field_extraction()963 {964 $text = Text::make('title');965 $textarea = Textarea::make('description');966 $select = Select::make('select');967 $checkbox = Checkbox::make('checkbox');968 $fields = [969 $text,970 RowMarkup::make()->fields([971 $select,972 $checkbox,973 ]),974 $textarea,975 ];976 $this->controller->addFields($fields);977 $this->assertEquals(978 [979 $text,980 $select,981 $checkbox,982 $textarea,983 ],984 $this->controller->crud()->getFieldsWithoutMarkup()985 );986 }987 /**988 * @test989 */990 public function check_fields_with_no_filter()991 {992 $this->controller->init();993 $this->controller->bound();994 $field = Text::make('title');995 $this->controller->addField($field);996 $this->assertFalse($this->controller->crud()->hasAnyFieldFilter());997 }998 /**999 * @test1000 */1001 public function check_fields_with_filter()1002 {1003 $this->controller->init();1004 $this->controller->bound();1005 $field = Text::make('title')->filter(TextFilter::make());1006 $this->controller->addField($field);1007 $this->assertTrue($this->controller->crud()->hasAnyFieldFilter());1008 }1009 /**1010 * @test1011 */1012 public function check_getting_columns_without_related_fields()1013 {1014 $this->controller->init();1015 $this->controller->bound();1016 $field = Text::make('schwifty');1017 $this->controller->addColumn($field);1018 $this->assertEquals([$field], $this->controller->crud()->getColumnsWithoutRelatedField());1019 }1020 /**1021 * @test1022 */1023 public function check_sortable_weight_is_not_set()1024 {1025 $this->assertFalse($this->controller->crud()->isSortableByWeight());1026 $this->assertNull($this->controller->crud()->getSortableWeightFieldName());1027 }1028 /**1029 * @test1030 */1031 public function check_sortable_weight_is_set()1032 {1033 $this->controller->sortable('sortme');1034 $this->assertTrue($this->controller->crud()->isSortableByWeight());1035 $this->assertEquals('sortme', $this->controller->crud()->getSortableWeightFieldName());1036 }1037 /**1038 * @test1039 */1040 public function check_urls()1041 {1042 $this->assertEquals('http://localhost', $this->controller->crud()->baseUrl());1043 $this->assertEquals('http://localhost/~/42', $this->controller->crud()->editUrl(42));1044 $this->assertEquals('http://localhost/~/create', $this->controller->crud()->createUrl());1045 $this->assertEquals('http://localhost/~/42/delete', $this->controller->crud()->deleteUrl(42));1046 $this->assertEquals('http://localhost/~/42/restore', $this->controller->crud()->restoreUrl(42));1047 $this->assertEquals('http://localhost/~/42/force-delete', $this->controller->crud()->forceDeleteUrl(42));1048 $this->assertEquals('http://localhost/~/toolbar/sometool', $this->controller->crud()->toolbarUrl('sometool'));1049 $this->assertEquals('http://localhost/~/per-page/42', $this->controller->crud()->perPageUrl(42));1050 $this->assertEquals('http://localhost/~/search', $this->controller->crud()->searchUrl());1051 $this->assertEquals('http://localhost/~/search/relation', $this->controller->crud()->relationSearchUrl());1052 $this->assertEquals('http://localhost/~/order/price/desc', $this->controller->crud()->orderUrl('price', 'desc'));1053 $this->assertEquals('http://localhost/~/reorder/switch', $this->controller->crud()->reorderUrl());1054 $this->assertEquals('http://localhost/~/reorder/move/42', $this->controller->crud()->reorderMoveItemUrl(42));1055 }1056 /**1057 * @test1058 */1059 public function check_single_per_page()1060 {1061 $this->assertNull($this->controller->crud()->getRawPerPage());1062 $this->controller->paginate(42);1063 $this->assertEquals(42, $this->controller->crud()->getRawPerPage());1064 $this->assertEquals(42, $this->controller->crud()->getPerPageParam());1065 $perPage = [1066 10,1067 20,1068 30,1069 ];1070 $this->controller->paginate($perPage);1071 $this->assertEquals($perPage, $this->controller->crud()->getRawPerPage());1072 // cuz it's stored1073 $this->assertEquals(42, $this->controller->crud()->getPerPageParam());1074 }1075 /**1076 * @test1077 */1078 public function check_array_per_page()1079 {1080 $this->assertNull($this->controller->crud()->getRawPerPage());1081 $perPage = [1082 10,1083 20,1084 30,1085 ];1086 $this->controller->paginate($perPage);1087 $this->assertEquals($perPage, $this->controller->crud()->getRawPerPage());1088 $this->assertEquals(10, $this->controller->crud()->getPerPageParam());1089 }1090 /**1091 * @test1092 */1093 public function check_batch_checkboxes()1094 {1095 $this->assertFalse($this->controller->crud()->isBatchCheckboxesEnabled());1096 $this->controller->enableBatchCheckboxes(true);1097 $this->assertTrue($this->controller->crud()->isBatchCheckboxesEnabled());1098 }1099 /**1100 * @test1101 */1102 public function check_sortable_state()1103 {1104 $this->assertFalse($this->controller->crud()->preferences()->isSortableByWeightActive('table'));1105 $this->controller->crud()->preferences()->setSortableOrderState('table', true);1106 $this->assertTrue($this->controller->crud()->preferences()->isSortableByWeightActive('table'));1107 $this->controller->crud()->preferences()->setSortableOrderState('table', false);1108 $this->assertFalse($this->controller->crud()->preferences()->isSortableByWeightActive('table'));1109 }1110 /**1111 * @test1112 */1113 public function check_locale()1114 {1115 $this->assertNull($this->controller->crud()->preferences()->getCurrentLocale('table'));1116 $this->controller->crud()->preferences()->saveCurrentLocale('table', 'en');1117 $this->assertEquals('en', $this->controller->crud()->preferences()->getCurrentLocale('table'));1118 }1119 /**1120 * @test1121 */1122 public function check_before_init()1123 {1124 $this->assertNull($this->controller->crud()->getRawPerPage());1125 $perPage = [1126 10,1127 20,1128 30,1129 ];1130 $closure = function () use ($perPage) {1131 $this->paginate($perPage);1132 };1133 $this->controller->setBeforeInitClosure($closure->bindTo($this->controller));1134 // to trigger beforeInit()1135 $this->controller->list($this->createRequest());1136 $this->assertEquals($perPage, $this->controller->crud()->getRawPerPage());1137 $this->assertEquals(10, $this->controller->crud()->getPerPageParam());1138 }1139 /**1140 * @test1141 */1142 public function check_magic_history_call()1143 {1144 $this->controller->overrideModel(VersionableModel::class);1145 $this->controller->crud()->actions()->add(new HistoryAction());1146 $model = VersionableModel::first();1147 $baseView = $this->controller->handleHistory($this->createRequest(), $model->id);1148 $magicView = $this->controller->history($this->createRequest(), $model->id);1149 $this->assertInstanceOf(View::class, $magicView);1150 $this->assertEquals($baseView, $magicView);1151 }1152 /**1153 * @test1154 */1155 public function check_magic_history_call_without_action_button()1156 {1157 $this->expectException(PermissionDenied::class);1158 $this->controller->overrideModel(VersionableModel::class);1159 $model = VersionableModel::first();1160 $this->controller->handleHistory($this->createRequest(), $model->id);1161 }1162 /**1163 * @test1164 */1165 public function check_magic_history_call_unauthorized()1166 {1167 $this->expectException(UnauthorizedException::class);1168 $this->controller->setPermissions('unauthorized');1169 $this->controller->crud()->actions()->add(new HistoryAction());1170 $this->controller->overrideModel(VersionableModel::class);1171 $model = VersionableModel::first();1172 $this->controller->handleHistory($this->createRequest(), $model->id);1173 }1174 /**1175 * @test1176 */1177 public function check_magic_history_call_unauthorized_response()1178 {1179 $this->controller->overrideModel(VersionableModel::class);1180 $this->controller->setPermissions('unauthorized');1181 $this->controller->crud()->actions()->add(new HistoryAction());1182 $model = VersionableModel::first();1183 $response = $this->controller->history($this->createRequest(), $model->id);1184 $this->assertEquals(1185 $this->controller->createUnauthorizedResponse($this->createRequest(), UnauthorizedException::forPermissions(['history'])),1186 $response1187 );1188 }1189 /**1190 * @test1191 */1192 public function check_magic_revert_call()1193 {1194 // to prevent cli output of dump() helper1195 $_SERVER['VAR_DUMPER_FORMAT'] = 'html';1196 $this->controller->overrideModel(VersionableModel::class);1197 $this->controller->crud()->actions()->add(new HistoryAction());1198 $model = VersionableModel::first();1199 $baseResponse = $this->controller->handleRevert($this->createRequest([1200 'version' => $model->previousVersion()->version_id,1201 ]), $model->id);1202 $request = $this->createRequest([1203 'version' => $model->previousVersion()->version_id,1204 ]);1205 Container::getInstance()->request = $request;1206 $magicResponse = $this->controller->revert($request, $model->id);1207 $this->assertInstanceOf(JsonResponse::class, $magicResponse);1208 $this->assertInstanceOf(JsonResponse::class, $baseResponse);1209 unset($_SERVER['VAR_DUMPER_FORMAT']);1210 }1211 /**1212 * @test1213 */1214 public function check_magic_revert_call_without_version()1215 {1216 $this->expectException(\RuntimeException::class);1217 $this->controller->overrideModel(VersionableModel::class);1218 $this->controller->crud()->actions()->add(new HistoryAction());1219 $this->controller->handleRevert($this->createRequest(), VersionableModel::first()->id);1220 }1221 /**1222 * @test1223 */1224 public function check_magic_revert_call_unauthorized()1225 {1226 $this->expectException(UnauthorizedException::class);1227 $this->controller->overrideModel(VersionableModel::class);1228 $this->controller->crud()->actions()->add(new HistoryAction());1229 $model = VersionableModel::first();1230 $this->controller->setPermissions('unauthorized');1231 $this->controller->handleRevert($this->createRequest([1232 'version' => VersionableModel::first()->previousVersion()->version_id,1233 ]), $model->id);1234 }1235 /**1236 * @test1237 */1238 public function check_magic_revert_call_permission_denied()1239 {1240 $this->expectException(PermissionDenied::class);1241 $this->controller->overrideModel(VersionableModel::class);1242 $model = VersionableModel::first();1243 $this->controller->crud()->actions()->add(1244 HistoryAction::make()->check(function () {...

Full Screen

Full Screen

cogumeloScript.NOC.php

Source:cogumeloScript.NOC.php Github

copy

Full Screen

...31}32if( $argc > 1 ) {33 //parameters handler34 switch( $argv[1] ) {35 case 'setPermissions': // set the files/folders permission36 setPermissions();37 break;38 case 'setPermissionsDevel': // set the files/folders permission39 setPermissionsDevel();40 break;41 case 'makeAppPaths': // Prepare folders42 makeAppPaths();43 break;44 case 'createDB': // create database45 if( Cogumelo::getSetupValue('db:name') ) {46 ( IS_DEVEL_ENV ) ? setPermissionsDevel() : setPermissions();47 backupDB();48 createDB();49 }50 else {51 echo "\n\nDDBB not defined !!!\n - - - EXIT - - - \n\n\n";52 }53 break;54 case 'generateModel':55 if( Cogumelo::getSetupValue('db:name') ) {56 ( IS_DEVEL_ENV ) ? setPermissionsDevel() : setPermissions();57 backupDB();58 createRelSchemes();59 generateModel();60 flushAll();61 }62 else {63 echo "\n\nDDBB not defined !!!\n - - - EXIT - - - \n\n\n";64 }65 break;66 case 'deploy':67 if( Cogumelo::getSetupValue('db:name') ) {68 ( IS_DEVEL_ENV ) ? setPermissionsDevel() : setPermissions();69 backupDB();70 createRelSchemes();71 deploy();72 flushAll();73 }74 else {75 echo "\n\nDDBB not defined !!!\n - - - EXIT - - - \n\n\n";76 }77 break;78 case 'simulateDeploy':79 simulateDeploy();80 break;81 case 'createRelSchemes':82 if( Cogumelo::getSetupValue('db:name') ) {83 ( IS_DEVEL_ENV ) ? setPermissionsDevel() : setPermissions();84 createRelSchemes();85 ( IS_DEVEL_ENV ) ? setPermissionsDevel() : setPermissions();86 }87 else {88 echo "\n\nDDBB not defined !!!\n - - - EXIT - - - \n\n\n";89 }90 break;91 case 'bckDB': // do the backup of the db92 case 'backupDB': // do the backup of the db93 if( Cogumelo::getSetupValue('db:name') ) {94 ( IS_DEVEL_ENV ) ? setPermissionsDevel() : setPermissions();95 $file = ( $argc > 2 ) ? $argv[2].'.sql' : false;96 backupDB( $file );97 }98 else {99 echo "\n\nDDBB not defined !!!\n - - - EXIT - - - \n\n\n";100 }101 break;102 case 'restoreDB': // restore the backup of a given db103 if( Cogumelo::getSetupValue('db:name') ) {104 if( $argc > 2 ) {105 $file = $argv[2]; //name of the backup file106 restoreDB( $file );107 }108 else {109 echo "You must specify the file to restore\n";110 }111 }112 else {113 echo "\n\nDDBB not defined !!!\n - - - EXIT - - - \n\n\n";114 }115 break;116 case 'prepareDependences':117 Cogumelo::load('coreController/DependencesController.php');118 $dependencesControl = new DependencesController();119 $dependencesControl->prepareDependences();120 break;121 case 'updateDependences':122 Cogumelo::load('coreController/DependencesController.php');123 $dependencesControl = new DependencesController();124 $dependencesControl->installDependences();125 break;126 case 'installDependences':127 Cogumelo::load('coreController/DependencesController.php');128 $dependencesControl = new DependencesController();129 $dependencesControl->prepareDependences();130 Cogumelo::load('coreController/DependencesController.php');131 $dependencesControl = new DependencesController();132 $dependencesControl->installDependences();133 break;134 case 'generateFrameworkTranslations':135 Cogumelo::load('coreController/i18nScriptController.php');136 $i18nscriptController = new i18nScriptController();137 $i18nscriptController->setEnviroment();138 $i18nscriptController->c_i18n_getSystemTranslations();139 echo "The files.po are ready to be edited!\n";140 break;141 case 'generateAppTranslations':142 Cogumelo::load('coreController/i18nScriptController.php');143 $i18nscriptController = new i18nScriptController();144 $i18nscriptController->setEnviroment();145 $i18nscriptController->c_i18n_getAppTranslations();146 echo "The files.po are ready to be edited!\n";147 break;148 case 'removeAllTranslations':149 Cogumelo::load('coreController/i18nScriptController.php');150 $i18nscriptController = new i18nScriptController();151 $i18nscriptController->c_i18n_removeTranslations();152 break;153 case 'precompileTranslations':154 actionPrecompileTranslations();155 break;156 case 'compileTranslations':157 actionCompileTranslations();158 break;159 case 'jsonTranslations':160 Cogumelo::load('coreController/i18nScriptController.php');161 $i18nscriptController = new i18nScriptController();162 $i18nscriptController->c_i18n_json();163 echo "The files.json are ready to be used!\n";164 break;165 /* We execute this two actions from web as we need to operate with the apache permissions*/166 case 'flush': // delete temporary files167 flushAll();168 echo "\n --- Flush DONE\n";169 break;170 // case 'rotateLogs':171 // actionRotateLogs();172 // break;173 case 'generateClientCaches':174 actionGenerateClientCaches();175 break;176 case 'garbageCollection':177 garbageCollection();178 break;179 default:180 echo "Invalid parameter;try:";181 printOptions();182 break;183 }//end switch184}//end parameters handler185else{186 echo "You have to write an option:";187 printOptions();188}189function printOptions(){190 echo "\n191 + Permissions and dependences192 * flush Remove temporary files193 * setPermissions(Devel) Set the files/folders permission194 * makeAppPaths Prepare folders195 * generateClientCaches Cache all js, css, compiled less and other client files196 * installDependences Exec prepareDependences and then exec updateDependences197 * prepareDependences Generate JSON's dependences198 * updateDependences Install all modules dependencies199 + Database200 * createDB Create a database201 * generateModel Initialize database202 * deploy Deploy203 * createRelSchemes Create JSON Model Rel Schemes204 * simulateDeploy simulate deploy SQL codes205 206 * resetModules207 - resetModuleVersions208 * backupDB Do a DB backup (optional arg: filename)209 * restoreDB Restore a database210 + Internationalization211 * generateFrameworkTranslations Update text to translate in cogumelo and geozzy modules212 * generateAppTranslations Get text to translate in the app213 * precompileTranslations Generate the intermediate POs(geozzy, cogumelo and app)214 * compileTranslations Mix geozzy, cogumelo and app POS in one and compile it to get the translations ready215 \n\n";216}217function actionPrecompileTranslations() {218 Cogumelo::load('coreController/i18nScriptController.php');219 $i18nscriptController = new i18nScriptController();220 $i18nscriptController->c_i18n_precompile();221 echo "\nThe intermediate .po are ready\n\n";222}223function actionCompileTranslations() {224 Cogumelo::load('coreController/i18nScriptController.php');225 $i18nscriptController = new i18nScriptController();226 /*$i18nscriptController->setEnviroment();*/227 $i18nscriptController->c_i18n_compile();228 /* generate json for js */229 $i18nscriptController->c_i18n_json();230 echo "\nThe files.mo are ready to be used!\n\n";231}232function generateModel() {233 $develdbcontrol = new DevelDBController();234 $develdbcontrol->scriptGenerateModel();235}236function deploy() {237 $develdbcontrol = new DevelDBController();238 $develdbcontrol->scriptDeploy();239}240function simulateDeploy() {241 ob_start(); // Start output buffering242 $fvotdbcontrol = new DevelDBController();243 $fvotdbcontrol->deploy();244 $ret= ob_get_contents(); // Store buffer in variable245 ob_end_clean(); // End buffering and clean up246 var_dump( [$ret] );247}248function createRelSchemes() {249 echo "\nCreating relationship schemes\n";250 global $C_ENABLED_MODULES;251 foreach( $C_ENABLED_MODULES as $moduleName ) {252 require_once( ModuleController::getRealFilePath( $moduleName.'.php' , $moduleName) );253 }254 Cogumelo::load('coreModel/VOUtils.php');255 VOUtils::createModelRelTreeFiles();256}257function flushAll() {258 echo "\n --- setPermissions:\n";259 ( IS_DEVEL_ENV ) ? setPermissionsDevel() : setPermissions();260 echo "\n --- actionFlush:\n";261 actionFlush();262 // echo "\n --- actionCompileTranslations:\n";263 // actionCompileTranslations();264 echo "\n --- actionGenerateClientCaches:\n";265 if( Cogumelo::getSetupValue( 'mod:mediaserver:productionMode' ) ) {266 actionGenerateClientCaches();267 }268 else {269 echo "\nPasamos porque no estamos en PRODUCTION MODE\n";270 }271 echo "\n --- setPermissions:\n";272 ( IS_DEVEL_ENV ) ? setPermissionsDevel() : setPermissions();273}274function actionFlush() {275 // Def: app/tmp/templates_c276 rmdirRec( Cogumelo::getSetupValue('smarty:compilePath'), false );277 // Def: httpdocs/cgmlImg278 rmdirRec( Cogumelo::getSetupValue('mod:filedata:cachePath'), false );279 // Def: httpdocs/mediaCache280 rmdirRec( Cogumelo::getSetupValue('mod:mediaserver:tmpCachePath'), false );281 echo ' - Cogumelo File cache flush DONE'."\n";282 require_once( COGUMELO_LOCATION.'/coreClasses/coreController/Cache.php' );283 $cacheCtrl = new Cache();284 $cacheCtrl->flush();285 echo ' - Cogumelo Memory Cache flush DONE'."\n";286 $scriptCogumeloServerUrl = Cogumelo::getSetupValue( 'script:cogumeloServerUrl' );287 if( !empty( $scriptCogumeloServerUrl ) ) {288 echo ' - Cogumelo PHP cache flush...'."\n";289 // TODO: EVITAMOS CONTROLES HTTPS290 $contextOptions = stream_context_create( [291 "ssl" => [292 "verify_peer" => false,293 "verify_peer_name" => false,294 ],295 ] );296 echo $scriptCogumeloServerUrl . '?q=flush';297 echo file_get_contents( $scriptCogumeloServerUrl . '?q=flush', false, $contextOptions );298 }299 else {300 echo ' - Cogumelo PHP cache flush DESCARTADO.'."\n";301 }302 echo "\nCogumelo caches deleted!\n\n";303}304// function actionRotateLogs() {305// echo file_get_contents( Cogumelo::getSetupValue( 'script:cogumeloServerUrl' ) . '?q=rotate_logs' );306// echo "\nRotate Logs DONE!\n\n";307// }308function actionGenerateClientCaches() {309 require_once( ModuleController::getRealFilePath( 'mediaserver.php', 'mediaserver' ) );310 mediaserver::autoIncludes();311 CacheUtilsController::generateAllCaches();312 // $ctx = stream_context_create( ['http'=> ['timeout' => 1200 ] ] ); //1200 Seconds is 20 Minutes313 // echo("Calling ".Cogumelo::getSetupValue( 'script:cogumeloServerUrl' ) . '?q=client_caches ... If you have any problem in less compilation, execute this url in browser');314 // file_get_contents( Cogumelo::getSetupValue( 'script:cogumeloServerUrl' ) . '?q=client_caches', false, $ctx);315 echo "\nClient caches generated\n\n";316}317function createDB(){318 echo "\nDatabase configuration\n";319 $user = false;320 $fileConnectionsInfo = APP_BASE_PATH.'/conf/inc/default-connections-info.php';321 if( file_exists( $fileConnectionsInfo ) ) {322 include $fileConnectionsInfo;323 if( defined( 'DDBB_PRIV_USER' ) && defined( 'DDBB_PRIV_PASS' ) ) {324 $user = DDBB_PRIV_USER;325 $passwd = DDBB_PRIV_PASS;326 }327 }328 if( !$user ) {329 $user = ReadStdin( "Enter an user with privileges:\n", '' );330 fwrite( STDOUT, "Enter the password:\n" );331 $passwd = getPassword( true );332 fwrite( STDOUT, "\n--\n" );333 }334 $develdbcontrol = new DevelDBController( $user, $passwd );335 $develdbcontrol->createSchemaDB();336 echo "\nDatase created!\n";337}338function makeAppPaths() {339 echo "makeAppPaths\n";340 // global $lc;341 $dirList = array( APP_TMP_PATH,342 Cogumelo::getSetupValue( 'smarty:configPath' ), Cogumelo::getSetupValue( 'smarty:compilePath' ),343 Cogumelo::getSetupValue( 'smarty:cachePath' ), Cogumelo::getSetupValue( 'smarty:tmpPath' ),344 Cogumelo::getSetupValue( 'mod:mediaserver:tmpCachePath' ),345 // WEB_BASE_PATH.'/'.Cogumelo::getSetupValue( 'mod:mediaserver:path' ),346 WEB_BASE_PATH.'/'.Cogumelo::getSetupValue( 'mod:mediaserver:cachePath' ),347 Cogumelo::getSetupValue( 'logs:path' ),348 Cogumelo::getSetupValue( 'session:savePath' ),349 Cogumelo::getSetupValue( 'mod:form:tmpPath' ),350 Cogumelo::getSetupValue( 'mod:filedata:filePath' ),351 Cogumelo::getSetupValue( 'mod:filedata:cachePath' ),352 Cogumelo::getSetupValue( 'script:backupPath' ),353 Cogumelo::getSetupValue( 'i18n:path' ), Cogumelo::getSetupValue( 'i18n:localePath' )354 );355 foreach( Cogumelo::getSetupValue( 'lang:available' ) as $lang ) {356 $dirList[] = Cogumelo::getSetupValue( 'i18n:localePath' ).'/'.$lang['i18n'].'/LC_MESSAGES';357 }358 $sessionSavePath = Cogumelo::getSetupValue('session:savePath');359 if( !empty( $sessionSavePath ) ) {360 $dirList[] = $sessionSavePath;361 }362 // echo "\n\nMKDIR\n".json_encode($dirList)."\n\n";363 foreach( $dirList as $dir ) {364 if( $dir && $dir !== '' && !is_dir( $dir ) ) {365 if( !mkdir( $dir, 0750, true ) ) {366 echo 'ERROR: Imposible crear el dirirectorio: '.$dir."\n";367 }368 }369 }370 echo "makeAppPaths DONE.\n";371}372function setPermissions( $devel = false ) {373 makeAppPaths();374 $extPerms = $devel ? ',ugo+rX' : '';375 $sudo = 'sudo ';376 $sudoAllowed = Cogumelo::getSetupValue('script:sudoAllowed');377 echo( "setPermissions ".($devel ? 'DEVEL' : '')."\n" );378 $prjLivePath = Cogumelo::getSetupValue('setup:prjLivePath');379 if( IS_DEVEL_ENV || $sudoAllowed ) {380 $dirsString =381 WEB_BASE_PATH.' '.APP_BASE_PATH.' '.APP_TMP_PATH.' '.382 Cogumelo::getSetupValue( 'smarty:configPath' ).' '.Cogumelo::getSetupValue( 'smarty:compilePath' ).' '.383 Cogumelo::getSetupValue( 'smarty:cachePath' ).' '.Cogumelo::getSetupValue( 'smarty:tmpPath' ).' '.384 Cogumelo::getSetupValue( 'mod:mediaserver:tmpCachePath' ).' '.385 WEB_BASE_PATH.'/'.Cogumelo::getSetupValue( 'mod:mediaserver:cachePath' ).' '.386 Cogumelo::getSetupValue( 'logs:path' ).' '.387 Cogumelo::getSetupValue( 'mod:form:tmpPath' ).' '.388 Cogumelo::getSetupValue( 'mod:filedata:filePath' ).' '.389 Cogumelo::getSetupValue( 'i18n:path' ).' '.Cogumelo::getSetupValue( 'i18n:localePath' )390 ;391 echo( " - Executamos chgrp general \n" );392 if( $prjLivePath ) {393 exec( $sudo.' chgrp www-data '.$prjLivePath );394 }395 $fai = 'chgrp -R www-data '.$dirsString;396 exec( $sudo.$fai );397 }398 else {399 echo( " - NON se executa chgrp general \n" );400 }401 if( IS_DEVEL_ENV || $sudoAllowed ) {402 $fai = 'chmod -R go-rwx,g+rX'.$extPerms.' '.WEB_BASE_PATH.' '.APP_BASE_PATH;403 echo( " - Executamos chmod WEB_BASE_PATH APP_BASE_PATH\n" );404 exec( $sudo.$fai );405 }406 else {407 echo( " - NON se executa chmod WEB_BASE_PATH APP_BASE_PATH\n" );408 }409 if( IS_DEVEL_ENV || $sudoAllowed ) {410 // Path que necesitan escritura Apache411 $fai = 'chmod -R ug+rwX'.$extPerms.' '.APP_TMP_PATH.' '.412 // Smarty413 Cogumelo::getSetupValue( 'smarty:configPath' ).' '.Cogumelo::getSetupValue( 'smarty:compilePath' ).' '.414 Cogumelo::getSetupValue( 'smarty:cachePath' ).' '.Cogumelo::getSetupValue( 'smarty:tmpPath' ).' '.415 // Cogumelo mediaserver416 Cogumelo::getSetupValue( 'mod:mediaserver:tmpCachePath' ).' '.417 WEB_BASE_PATH.'/'.Cogumelo::getSetupValue( 'mod:mediaserver:cachePath' ).' '.418 // Form y Filedata419 Cogumelo::getSetupValue( 'mod:filedata:cachePath' ).' '. // cgmlImg420 Cogumelo::getSetupValue( 'mod:filedata:filePath' ).' '. // formFiles421 Cogumelo::getSetupValue( 'mod:form:tmpPath' ).' '. // tmp formFiles422 // Varios423 Cogumelo::getSetupValue( 'logs:path' ).' '.424 // Cogumelo::getSetupValue( 'session:savePath' ).' '.425 // Cogumelo::getSetupValue( 'i18n:path' ).' '.Cogumelo::getSetupValue( 'i18n:localePath' ).' '.426 ''427 ;428 echo( " - Executamos chmod APP_TMP_PATH\n" );429 if( $prjLivePath ) {430 exec( $sudo.' chmod ug+rwX'.$extPerms.' '.$prjLivePath );431 }432 exec( $sudo.$fai );433 }434 else {435 echo( " - NON se executa chmod APP_TMP_PATH\n" );436 }437 if( IS_DEVEL_ENV || $sudoAllowed ) {438 echo( " - Preparando [session:savePath] e [script:backupPath]\n" );439 // session:savePath tiene que mantener el usuario y grupo440 $sessionSavePath = Cogumelo::getSetupValue( 'session:savePath' );441 if( !empty($sessionSavePath) ) {442 $fai = 'chgrp -R www-data '.$sessionSavePath;443 echo( " - Executamos $fai\n" );444 exec( $sudo.$fai );445 $fai = 'chmod -R ug+rwX'.$extPerms.' '.$sessionSavePath;446 echo( " - Executamos $fai\n" );447 exec( $sudo.$fai );448 }449 // Solo usuario administrador450 $backupPath = Cogumelo::getSetupValue( 'script:backupPath' );451 if( !empty($backupPath) ) {452 $fai = 'chmod -R go-rwx '.$backupPath;453 echo( " - Executamos $fai\n" );454 exec( $sudo.$fai );455 }456 }457 else {458 echo( " - NON se preparan [session:savePath] e [script:backupPath]\n" );459 }460 echo( "setPermissions ".($devel ? 'DEVEL' : '')." DONE.\n" );461}462function setPermissionsDevel() {463 setPermissions( true );464}465function backupDB( $file = false ) {466 doBackup(467 Cogumelo::getSetupValue('db:name'),468 Cogumelo::getSetupValue('db:user'),469 Cogumelo::getSetupValue('db:password'),470 $file,471 Cogumelo::getSetupValue('db:hostname')472 );473}474function doBackup( $dbName, $user, $passwd, $file, $dbHost ) {475 if( empty( $file ) ) {476 $file = date('Ymd-His').'-'.$dbName.'.sql';477 }...

Full Screen

Full Screen

VendorsRoutes.php

Source:VendorsRoutes.php Github

copy

Full Screen

...22 $this->get['/api/example/vendors'] = (new Route())23 ->setEndpointType(Route::ENDPOINT_TYPE_LIST)24 ->setController(VendorController::class)25 ->setAction('getVendors')26 ->setPermissions(['example:read'])27 ->setRequestMapper(VendorFilteredRequestMapper::class)28 ->setResponseMapper(VendorMapper::class)29 ->setDocumentation(30 (new RouteDoc())31 ->setSummary('List all vendors')32 ->setExceptionsList([33 UnauthorizedApiException::class,34 ])35 )36 ;37 $this->get['/api/example/vendors/paginated'] = (new Route())38 ->setEndpointType(Route::ENDPOINT_TYPE_PAGINATED)39 ->setController(VendorController::class)40 ->setAction('getVendorsPaginated')41 ->setPermissions(['example:read'])42 ->setRequestMapper(VendorFilteredRequestMapper::class)43 ->setResponseMapper(VendorMapper::class)44 ->setDocumentation(45 (new RouteDoc())46 ->setSummary('List all vendors paginated')47 ->setExceptionsList([48 UnauthorizedApiException::class,49 ])50 )51 ;52 $this->get['/api/example/vendors/{vendor_id}'] = (new Route())53 ->setController(VendorController::class)54 ->setAction('getVendor')55 ->setPermissions(['example:read'])56 ->setResolvers([57 'vendor_id' => VendorResolver::class,58 ])59 ->setResponseMapper(VendorMapper::class)60 ->setDocumentation(61 (new RouteDoc())62 ->setSummary('Get vendor information')63 ->setExceptionsList([64 UnauthorizedApiException::class,65 NotFoundApiException::class => [66 ['code' => 'vendor_not_found', 'message' => 'Vendor not found'],67 ],68 ])69 )70 ;71 $this->post['/api/example/vendors'] = (new Route())72 ->setController(VendorController::class)73 ->setAction('createVendor')74 ->setPermissions(['example:create'])75 ->setRequestMapper(VendorMapper::class)76 ->setValidator(VendorValidator::class)77 ->setResponseMapper(VendorMapper::class)78 ->setDocumentation(79 (new RouteDoc())80 ->setSummary('Create vendor')81 ->setExceptionsList([82 UnauthorizedApiException::class,83 ])84 )85 ;86 $this->put['/api/example/vendors/{vendor_id}'] = (new Route())87 ->setController(VendorController::class)88 ->setAction('updateVendor')89 ->setPermissions(['example:update'])90 ->setRequestMapper(VendorMapper::class)91 ->setValidator(VendorValidator::class)92 ->setResolvers([93 'vendor_id' => VendorResolver::class,94 ])95 ->setResponseMapper(VendorMapper::class)96 ->setDocumentation(97 (new RouteDoc())98 ->setSummary('Update vendor')99 ->setExceptionsList([100 UnauthorizedApiException::class,101 NotFoundApiException::class => [102 ['code' => 'vendor_not_found', 'message' => 'Vendor not found'],103 ],104 ])105 )106 ;107 $this->delete['/api/example/vendors/{vendor_id}'] = (new Route())108 ->setController(VendorController::class)109 ->setAction('deleteVendor')110 ->setPermissions(['example:delete'])111 ->setResolvers([112 'vendor_id' => VendorResolver::class,113 ])114 ->setDocumentation(115 (new RouteDoc())116 ->setSummary('Delete vendor')117 ->setExceptionsList([118 UnauthorizedApiException::class,119 NotFoundApiException::class => [120 ['code' => 'vendor_not_found', 'message' => 'Vendor not found'],121 ],122 ])123 )124 ;...

Full Screen

Full Screen

setPermissions

Using AI Code Generation

copy

Full Screen

1$controller->setPermissions($permissions);2$controller->getPermissions();3$controller->addPermission($permissions);4$controller->removePermission($permissions);5$controller->hasPermission($permissions);6$controller->getPermissions();7$controller->removePermissions();8$controller->hasPermissions($permissions);9$controller->hasAnyPermission($permissions);10$controller->hasAllPermissions($permissions);11$controller->hasAnyPermissions($permissions);12$controller->hasAllPermissions($permissions);13$controller->setRoles($roles);14$controller->getRoles();15$controller->addRole($roles);16$controller->removeRole($roles);17$controller->hasRole($roles);18$controller->getRoles();19$controller->removeRoles();20$controller->hasRoles($roles);

Full Screen

Full Screen

setPermissions

Using AI Code Generation

copy

Full Screen

1$controller->setPermissions(array(2 'admin' => array('index'),3 'user' => array('index'),4 'guest' => array('index'),5 'all' => array('index')6));7$controller->setPermissions(array(8 'admin' => array('index', 'edit'),9 'user' => array('index'),10 'guest' => array('index'),11 'all' => array('index')12));13$controller->setPermissions(array(14 'admin' => array('index', 'edit'),15 'user' => array('index', 'edit'),16 'guest' => array('index'),17 'all' => array('index')18));19$controller->setPermissions(array(20 'admin' => array('index', 'edit'),21 'user' => array('index', 'edit'),22 'guest' => array('index', 'edit'),23 'all' => array('index')24));25$controller->setPermissions(array(26 'admin' => array('index', 'edit'),27 'user' => array('index', 'edit'),28 'guest' => array('index', 'edit'),29 'all' => array('index', 'edit')30));31$controller->setPermissions(array(32 'admin' => array('index', 'edit'),33 'user' => array('index', 'edit'),34 'guest' => array('index', 'edit'),35 'all' => array('index', 'edit')36));37$controller->setPermissions(array(38 'admin' => array('index', 'edit'),39 'user' => array('index', 'edit'),40 'guest' => array('index', 'edit'),41 'all' => array('index', 'edit')42));43$controller->setPermissions(array(

Full Screen

Full Screen

setPermissions

Using AI Code Generation

copy

Full Screen

1$controller->setPermissions($user_id, $permission_id);2$controller->getPermissions($user_id);3$controller->getPermissionsList();4$controller->getPermissions($user_id);5$controller->getUsersList();6$controller->getUsers($permission_id);7$controller->getPermissionsUsersList();8$controller->getPermissionsUsersList($group_id);9$controller->getPermissionsGroupsList($user_id);10$controller->getGroupsList();

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Atoum automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in controller

Trigger setPermissions code on LambdaTest Cloud Grid

Execute automation tests with setPermissions on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful