Exemplo n.º 1
0
 /**
  * test for getting the select input for all the images that are used from all products
  * NOTE: By adding or removing a category in the database, this test will no longer work
  *      unless $expectedResult is changed based on ChangeCategory::getCategoriesWithProducts's
  *      new output
  */
 public function testGetCategoriesWithProducts()
 {
     // Arrange
     $changeCategory = new ChangeCategory();
     $connection = open_database_connection();
     $expectedResult = '<input type="hidden" id="productCat1" value="1" />
     <input type="hidden" id="productCat2" value="1" />
     <input type="hidden" id="productCat3" value="1" />
     <input type="hidden" id="productCat4" value="1" />
     <input type="hidden" id="productCat5" value="1" />
     ';
     // Act
     $result = $changeCategory->getCategoriesWithProducts($connection);
     // Assert
     $this->assertEquals($result, $expectedResult);
 }
Exemplo n.º 2
0
 /**
  * Action for selecting a category to change, edit or delete.
  *
  * Action for route: /adminChangeCategory
  *
  * @param Request $request
  * @param Application $app
  * @return \Symfony\Component\HttpFoundation\RedirectResponse
  */
 public function changeCategoryAction(Request $request, Application $app)
 {
     // test if 'username' stored in session ...
     $username = getAuthenticatedUserName($app);
     // check we are authenticated --------
     $isAuthenticated = null != $username;
     if (!$isAuthenticated) {
         // not authenticated, so redirect to LOGIN page
         return $app->redirect('/login');
     }
     $connection = open_database_connection();
     $menuCategoryRepository = new MenuCategoryRepository();
     $changeCategoryObject = new ChangeCategory();
     // $categoryInputSelection = $changeCategoryObject->getCategoriesForSelection($connection);
     // store username into args array
     $argsArray = array('title' => "Admin Change Categories", 'username' => $username, 'categories' => $menuCategoryRepository->getAllMenuCategories(), 'productCategoriesData' => $changeCategoryObject->getCategoriesWithProducts($connection));
     close_database_connection($connection);
     // render (draw) template
     // ------------
     $templateName = 'admin/changeCategory';
     return $app['twig']->render($templateName . '.html.twig', $argsArray);
 }