//adding the config require_once __DIR__ . "/config.php"; $app = new Silex\Application(); $app['debug'] = true; $app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . '/../views')); $app->register(new Silex\Provider\UrlGeneratorServiceProvider()); use Symfony\Component\HttpFoundation\Request; Request::enableHttpMethodParameterOverride(); require_once __DIR__ . "/routes/questionsController.php"; require_once __DIR__ . "/routes/adminController.php"; // INDEX.HTML.TWIG // home page displays list of topics, popular promptrs, and option to create a new promptr $app->get("/", function () use($app) { $topics = Topic::getAll(); $promptrs = Promptr::getAll(); $pop_promptrs = Promptr::getTrendingPromptrs(); return $app['twig']->render('index.html.twig', array('topics' => $topics, 'promptrs' => $promptrs, 'pop_promptrs' => $pop_promptrs)); }); $app->get("/topic/{id}", function ($id) use($app) { $topic = Topic::find($id); $promptrs = $topic->getPromptrs(); return $app['twig']->render("topic.html.twig", array('topic' => $topic, 'promptrs' => $promptrs)); }); $app->post("/topic/{id}", function ($id) use($app) { $topic = Topic::find($id); $name = $_POST['name']; $promptr = new Promptr($name, $topic->getId()); $promptr->save(); $promptrs = Promptr::getAll(); return $app['twig']->render('topic.html.twig', array('topic' => $topic, 'promptrs' => $promptrs)); });
function test_getTrendingPromptrs() { $name = "mikes 5 top interview questions"; $topic_id = 5; $trending_index = 3; $test_promptr = new Promptr($name, $topic_id, $trending_index); $test_promptr->save(); $name2 = "mikes 50 top interview questions"; $trending_index2 = 4; $test_promptr2 = new Promptr($name2, $topic_id, $trending_index2); $test_promptr2->save(); $name3 = "mikes 500 top interview questions"; $trending_index3 = 5; $test_promptr3 = new Promptr($name3, $topic_id, $trending_index3); $test_promptr3->save(); $name4 = "mikes 5000 top interview questions"; $trending_index4 = 6; $test_promptr4 = new Promptr($name4, $topic_id, $trending_index4); $test_promptr4->save(); $name5 = "mikes 50000 top interview questions"; $trending_index5 = 7; $test_promptr5 = new Promptr($name5, $topic_id, $trending_index5); $test_promptr5->save(); $name6 = "mikes 500000 top interview questions"; $trending_index6 = 8; $test_promptr6 = new Promptr($name6, $topic_id, $trending_index6); $test_promptr6->save(); //Act $result = Promptr::getTrendingPromptrs(); //Assert $this->assertEquals([$test_promptr6, $test_promptr5, $test_promptr4, $test_promptr3, $test_promptr2], $result); }