public function testDeleteCategory() { // Arrange $changeCategory = new ChangeCategory(); $connection = open_database_connection(); $expectedResult = $changeCategory->addCategory($connection, "PHP Unit Test Category", "", "", "PHP Unit Test Summary"); // Act $result = $changeCategory->deleteCategory($connection, "PHP Unit Test Category"); // Assert $this->assertEquals($result, $expectedResult); }
/** * Action for adding a category to the database. This function gets the data from * the form, and executes the function in the ChangeCategory class. * * Action for route: /adminAddCategory * * @param Request $request * @param Application $app * @return \Symfony\Component\HttpFoundation\RedirectResponse */ public function addCategoryAction(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'); } $resultMessage = ""; $connection = open_database_connection(); $changeCategoryObject = new ChangeCategory(); if (isset($_GET['submit'])) { // then we are coming from a request from this page to make a new category $resultMessage = $changeCategoryObject->addCategory($connection, $_GET['categoryName'], $_GET['categoryImageURL1'], $_GET['categoryImageURL2'], $_GET['categorySummary']); } $categoryImageSelection = $changeCategoryObject->getCategoriesForSelection($connection, "addCategory"); close_database_connection($connection); if ($resultMessage == "Success!") { return $app->redirect("/adminChangeCategory"); } $changeItemURL = $_SERVER['REQUEST_URI'] . $_SERVER['QUERY_STRING']; // store username into args array $argsArray = array('title' => 'Add new category', 'username' => $username, 'categoryImageSelection' => $categoryImageSelection, 'resultMessage' => $resultMessage, 'changeItemURL' => $changeItemURL); // render (draw) template // ------------ $templateName = 'admin/addCategory'; return $app['twig']->render($templateName . '.html.twig', $argsArray); }