Skip to content

Commit

Permalink
adjust tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nateweller committed Jan 15, 2025
1 parent 82f6410 commit 12fa142
Showing 1 changed file with 48 additions and 50 deletions.
98 changes: 48 additions & 50 deletions projects/packages/protect-status/tests/php/test-status.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,31 @@ public function get_sample_api_response() {
public function get_sample_status() {
global $wp_version;

$sample_plugin_1 = new Extension_Model(
$vulnerability_1 = new Vulnerability_Model(
array(
'id' => 'test-vuln-1',
'title' => 'Test Vuln 1',
'fixed_in' => '1.0.0',
)
);

$vulnerability_2 = new Vulnerability_Model(
array(
'id' => 'test-vuln-2',
'title' => 'Test Vuln 2',
'fixed_in' => '2.0.0',
)
);

$vulnerability_3 = new Vulnerability_Model(
array(
'id' => 'test-vuln-3',
'title' => 'Test Vuln 3',
'fixed_in' => null,
)
);

$plugin_1 = new Extension_Model(
array(
'version' => '1.0.2',
'name' => 'Sample Plugin 1',
Expand All @@ -171,7 +195,7 @@ public function get_sample_status() {
)
);

$sample_theme_1 = new Extension_Model(
$theme_1 = new Extension_Model(
array(
'version' => '1.0.2',
'name' => 'Sample Theme 1',
Expand All @@ -181,7 +205,7 @@ public function get_sample_status() {
)
);

$sample_core = new Extension_Model(
$core = new Extension_Model(
array(
'version' => $wp_version,
'name' => 'WordPress',
Expand All @@ -191,37 +215,13 @@ public function get_sample_status() {
)
);

$vulnerability_1 = new Vulnerability_Model(
array(
'id' => 'test-vuln-1',
'title' => 'Test Vuln 1',
'fixed_in' => '1.0.0',
)
);

$vulnerability_2 = new Vulnerability_Model(
array(
'id' => 'test-vuln-2',
'title' => 'Test Vuln 2',
'fixed_in' => '2.0.0',
)
);

$vulnerability_3 = new Vulnerability_Model(
array(
'id' => 'test-vuln-3',
'title' => 'Test Vuln 3',
'fixed_in' => null,
)
);

$plugin_1_threat = new Threat_Model(
array(
'id' => 'plugins-plugin-1-1.0.2',
'title' => 'Vulnerable plugin: Sample Plugin 1 (version 1.0.2)',
'description' => 'The installed version of Sample Plugin 1 (1.0.2) has a known security vulnerability.',
'fixed_in' => '2.0.0',
'source' => null, // 'https://jetpack.com/redirect/?source=jetpack-protect-vul-info&site=example.org&path=test-vuln-1',
'source' => null,
'vulnerabilities' => array( $vulnerability_2 ),
)
);
Expand All @@ -232,7 +232,7 @@ public function get_sample_status() {
'title' => 'Vulnerable theme: Sample Theme 1 (version 1.0.2)',
'description' => 'The installed version of Sample Theme 1 (1.0.2) has a known security vulnerability.',
'fixed_in' => '1.0.0',
'source' => null, // 'https://jetpack.com/redirect/?source=jetpack-protect-vul-info&site=example.org&path=test-vuln-1',
'source' => null,
'vulnerabilities' => array( $vulnerability_1 ),
)
);
Expand All @@ -243,30 +243,28 @@ public function get_sample_status() {
'title' => 'Vulnerable WordPress (version ' . $wp_version . ')',
'description' => 'The installed version of WordPress (' . $wp_version . ') has a known security vulnerability.',
'fixed_in' => null,
'source' => null, // 'https://jetpack.com/redirect/?source=jetpack-protect-vul-info&site=example.org&path=test-vuln-3',
'source' => null,
'vulnerabilities' => array( $vulnerability_3 ),
)
);

$core_threat_extension = clone $core_threat;
$core_threat_extension->extension = $sample_core;
$core_threat_with_extension = clone $core_threat;
$core_threat_with_extension->extension = $core;

$plugin_1_threat_extension = clone $plugin_1_threat;
$plugin_1_threat_extension->extension = $sample_plugin_1;
$plugin_1_threat_with_extension = clone $plugin_1_threat;
$plugin_1_threat_with_extension->extension = $plugin_1;

$theme_1_threat_extension = clone $theme_1_threat;
$theme_1_threat_extension->extension = $sample_theme_1;
$theme_1_threat_with_extension = clone $theme_1_threat;
$theme_1_threat_with_extension->extension = $theme_1;

$sample_plugin_1_threats = clone $sample_plugin_1;
$sample_plugin_1_threats->threats = array( $plugin_1_threat );
unset( $sample_plugin_1_threats->extension );
$plugin_1_with_threats = clone $plugin_1;
$plugin_1_with_threats->threats = array( $plugin_1_threat );

$sample_theme_1_threats = clone $sample_theme_1;
$sample_theme_1_threats->threats = array( $theme_1_threat );
unset( $sample_theme_1_threats->extension );
$theme_1_with_threats = clone $theme_1;
$theme_1_with_threats->threats = array( $theme_1_threat );

$sample_core_threats = clone $sample_core;
$sample_core_threats->threats = array( $core_threat );
$core_with_threats = clone $core;
$core_with_threats->threats = array( $core_threat );

return new Status_Model(
array(
Expand All @@ -287,16 +285,16 @@ public function get_sample_status() {
'slug' => 'plugin-2',
)
),
$sample_plugin_1_threats,
$plugin_1_with_threats,
),
'themes' => array(
$sample_theme_1_threats,
$theme_1_with_threats,
),
'core' => $sample_core_threats,
'core' => $core_with_threats,
'threats' => array(
$theme_1_threat_extension,
$plugin_1_threat_extension,
$core_threat_extension,
$theme_1_threat_with_extension,
$plugin_1_threat_with_extension,
$core_threat_with_extension,
),
)
);
Expand Down

0 comments on commit 12fa142

Please sign in to comment.