1+ <?php
2+
3+ namespace ShoppingFeed \ShoppingFeedWC \Tests \wpunit \Feed ;
4+
5+ use ShoppingFeed \ShoppingFeedWC \ShoppingFeedHelper ;
6+
7+ class HelperFunctionsTest extends \Codeception \TestCase \WPTestCase {
8+
9+ private static $ upload_dir ;
10+
11+ public static function setUpBeforeClass (): void {
12+ self ::$ upload_dir = wp_upload_dir ();
13+ }
14+
15+ public function test_get_feed_directory () {
16+ $ this ->assertEquals (
17+ self ::$ upload_dir ['basedir ' ] . '/shopping-feed ' ,
18+ ShoppingFeedHelper::get_feed_directory ()
19+ );
20+ }
21+
22+ public function test_get_feed_directory_filter () {
23+ $ custom_feed_directory = '/tmp/shopping-feed ' ;
24+
25+ add_filter (
26+ 'shopping_feed_feed_directory_path ' ,
27+ function ( $ dir ) use ( $ custom_feed_directory ) {
28+ return $ custom_feed_directory ;
29+ }
30+ );
31+
32+ $ this ->assertEquals (
33+ $ custom_feed_directory ,
34+ ShoppingFeedHelper::get_feed_directory ()
35+ );
36+ }
37+
38+ public function test_get_feed_part_directory () {
39+ $ this ->assertEquals (
40+ self ::$ upload_dir ['basedir ' ] . '/shopping-feed/parts ' ,
41+ ShoppingFeedHelper::get_feed_parts_directory ()
42+ );
43+ }
44+
45+ public function test_get_feed_part_directory_filter () {
46+ $ custom_feed_directory = '/tmp/shopping-feed-parts ' ;
47+
48+ add_filter (
49+ 'shopping_feed_feed_parts_directory_path ' ,
50+ function ( $ dir ) use ( $ custom_feed_directory ) {
51+ return $ custom_feed_directory ;
52+ }
53+ );
54+
55+ $ this ->assertEquals (
56+ $ custom_feed_directory ,
57+ ShoppingFeedHelper::get_feed_parts_directory ()
58+ );
59+ }
60+
61+ public function test_get_feed_filename () {
62+ $ this ->assertEquals (
63+ 'products ' ,
64+ ShoppingFeedHelper::get_feed_filename ()
65+ );
66+ }
67+
68+ public function test_get_feed_filename_filter () {
69+ $ custom_feed_filename = 'custom-products ' ;
70+
71+ add_filter (
72+ 'shopping_feed_feed_filename ' ,
73+ function ( $ filename ) use ( $ custom_feed_filename ) {
74+ return $ custom_feed_filename ;
75+ }
76+ );
77+
78+ $ this ->assertEquals (
79+ $ custom_feed_filename ,
80+ ShoppingFeedHelper::get_feed_filename ()
81+ );
82+ }
83+ }
0 commit comments