public function testGetPostsFor() { $getPostsCall = []; $getPosts = function ($args) use(&$getPostsCall) { $getPostsCall[] = $args; return 'list of posts'; }; $postsProvider = new BibCnrsPostsProvider(null, null, $getPosts); $posts = $postsProvider->getPostsFor((object) ['slug' => 'mySlug']); $this->assertEquals([['category_name' => 'mySlug']], $getPostsCall); $this->assertEquals('list of posts', $posts); }
Timber::render('singlelist.twig', $context); } else { require 'models/BibCnrsCategoriesProvider.php'; $categoriesProvider = new BibCnrsCategoriesProvider(get_the_category, get_category_by_slug, wp_get_current_user); $current_url = "//" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; $categoryRetrieve = explode('category=', $current_url); if ($categoryRetrieve[1]) { $currentCategory = get_category_by_slug($categoryRetrieve[1]); } else { $currentCategory = $multicat[0]; } $userCategory = $categoriesProvider->getUserCategory(); require 'models/BibCnrsPostsProvider.php'; $getPosts = function ($args) { return Timber::get_posts($args); }; $postsProvider = new BibCnrsPostsProvider($config['category']['domains'], get_category_by_slug, $getPosts, TimberPost); /* Display */ $preferences = "pref-" . $currentCategory->slug; $context['pref'] = Timber::get_posts(array('category_name' => $preferences)); $context['currentCategory'] = $currentCategory; $context['userCategory'] = $userCategory; $domain = $config['profile_map'][$currentCategory->description]; $dbUrl = $language === 'fr' ? '\\/bases-de-donnees\\/' : '\\/data-bases\\/'; $context['ebsco_widget'] = sprintf('[ebsco_widget domain="%s" language="%s" db_url="%s"]', $domain, $language, $dbUrl); $context['post'] = new TimberPost(); $context['page'] = "single"; $context['categoryPosts'] = $postsProvider->getPostsFor($currentCategory, 5); $context['allOtherPosts'] = $postsProvider->getPostsNotIn($currentCategory, 5); Timber::render('single.twig', $context); }