Passed
Branch develop (bae466)
by Paul
06:12
created

DefaultsTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 103
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 92
dl 0
loc 103
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A test_reviews_restrict() 0 57 1
A test_site_reviews_restrict() 0 42 1
1
<?php
2
3
namespace GeminiLabs\SiteReviews\Tests;
4
5
use GeminiLabs\SiteReviews\Defaults\ReviewsDefaults;
6
use GeminiLabs\SiteReviews\Defaults\SiteReviewsDefaults;
7
8
/**
9
 * Test case for the Plugin.
10
 * @group plugin
11
 */
12
class DefaultsTest extends \WP_UnitTestCase
0 ignored issues
show
Bug introduced by
The type WP_UnitTestCase was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
13
{
14
    public function test_reviews_restrict()
15
    {
16
        $postId = self::factory()->post->create();
17
        $termId = self::factory()->term->create(['taxonomy' => glsr()->taxonomy]);
18
        $userId = self::factory()->user->create();
19
        $args = [
20
            'assigned_to' => $postId,
21
            'block' => '',
22
            'category' => $termId,
23
            'class' => '',
24
            'display' => 1,
25
            'hide' => [],
26
            'id' => '',
27
            'offset' => '',
28
            'page' => 2,
29
            'pageUrl' => 'http://site-reviews.test/reviews/',
30
            'pagination' => 'ajax',
31
            'schema' => '',
32
            'terms' => '',
33
            'type' => 'local',
34
            'user' => $userId,
35
        ];
36
        $expected = [
37
            'assigned_posts' => [$postId],
38
            'assigned_posts_types' => [],
39
            'assigned_terms' => [$termId],
40
            'assigned_users' => [$userId],
41
            'content' => '',
42
            'date' => [
43
                'after' => '',
44
                'before' => '',
45
                'day' => '',
46
                'inclusive' => '',
47
                'month' => '',
48
                'year' => '',
49
            ],
50
            'email' => '',
51
            'integration' => '',
52
            'ip_address' => '',
53
            'offset' => 0,
54
            'order' => 'DESC',
55
            'orderby' => 'p.post_date',
56
            'page' => 2,
57
            'per_page' => 1,
58
            'post__in' => [],
59
            'post__not_in' => [],
60
            'rating' => 0,
61
            'rating_field' => 'rating',
62
            'status' => 1,
63
            'terms' => -1,
64
            'type' => 'local',
65
            'user__in' => [],
66
            'user__not_in' => [],
67
        ];
68
        $test = glsr()->args(glsr(ReviewsDefaults::class)->restrict($args));
69
        $this->assertEquals(count($test), count(glsr(ReviewsDefaults::class)->defaults()));
70
        $this->assertEquals($test->toArray(), $expected);
71
    }
72
73
    public function test_site_reviews_restrict()
74
    {
75
        $postId = self::factory()->post->create();
76
        $termId = self::factory()->term->create(['taxonomy' => glsr()->taxonomy]);
77
        $userId = self::factory()->user->create();
78
        $args = [
79
            'assigned_to' => $postId,
80
            'category' => $termId,
81
            'class' => '',
82
            'className' => '',
83
            'display' => 1,
84
            'hide' => '',
85
            'id' => '',
86
            'pagination' => 'ajax',
87
            'post_id' => 4466,
88
            'rating' => 3,
89
            'schema' => 1,
90
            'terms' => '',
91
            'type' => 'local',
92
            'user' => $userId,
93
        ];
94
        $test = glsr(SiteReviewsDefaults::class)->restrict($args);
95
        $this->assertEquals(count($test), count(glsr(SiteReviewsDefaults::class)->defaults()));
96
        $this->assertTrue(str_starts_with($test['id'], glsr()->prefix));
97
        unset($test['id']);
98
        $this->assertEquals($test, [
99
            'assigned_posts' => $postId,
100
            'assigned_terms' => $termId,
101
            'assigned_users' => $userId,
102
            'author' => 0,
103
            'class' => '',
104
            'debug' => false,
105
            'display' => 1,
106
            'hide' => [],
107
            'offset' => 0,
108
            'page' => 1,
109
            'pagination' => 'ajax',
110
            'rating' => 3,
111
            'rating_field' => 'rating',
112
            'schema' => true,
113
            'terms' => '',
114
            'type' => 'local',
115
       ]);
116
    }
117
}
118