Fixed Activity filter and added Activity Unit Test

This commit is contained in:
Justin Foell
2019-10-04 15:50:08 -05:00
parent 319b220aa3
commit 00812e55e8
11 changed files with 130 additions and 64 deletions
+57
View File
@@ -0,0 +1,57 @@
<?php
use \WP_Mock\Tools\TestCase;
class WPStrava_ActivityTest extends TestCase {
private $activity;
private $activities;
public function setUp() : void {
\WP_Mock::setUp();
$this->activity = new WPStrava_Activity();
$activity0 = new stdClass();
$activity1 = new stdClass();
$activity2 = new stdClass();
$activity0->distance = 100;
$activity1->distance = 1600;
$activity2->distance = 45000;
$this->activities = array(
$activity0,
$activity1,
$activity2,
);
}
public function tearDown() : void {
\WP_Mock::tearDown();
}
public function test_object() {
$this->assertInstanceOf( 'WPStrava_Activity', $this->activity );
}
/**
* Test that we only get the 45,000 meter activity when filtering greater than 10.00 kilometers.
*
* @author Justin Foell <justin@foell.org>
* @since 2.0.0
*/
public function test_get_activities_longer_than() {
\WP_Mock::userFunction(
'get_option',
array(
'args' => 'strava_som',
'times' => 1,
'return' => 'metric',
)
);
$expected = array( $this->activities[2] );
$actual = $this->activity->get_activities_longer_than( $this->activities, '10' );
$this->assertEquals( $expected, $actual );
}
}
+7 -3
View File
@@ -7,9 +7,14 @@ class WPStrava_SOMEnglishTest extends TestCase {
private $som;
public function setUp() : void {
\WP_Mock::setUp();
$this->som = new WPStrava_SOMEnglish();
}
public function tearDown() : void {
\WP_Mock::tearDown();
}
public function test_object() {
$this->assertInstanceOf( 'WPStrava_SOMEnglish', $this->som );
}
@@ -26,14 +31,13 @@ class WPStrava_SOMEnglishTest extends TestCase {
}
/**
* Test that 6.213712 miles is 10,000.00 meters using both string and float inputs.
* Test that 6.213712 miles is 10,000.00 meters using float input.
*
* @author Justin Foell <justin@foell.org>
* @since 1.7.1
*/
public function test_distance_inverse() {
$this->assertEquals( '10,000.00', $this->som->distance_inverse( '6.213712' ) );
$this->assertEquals( '10,000.00', $this->som->distance_inverse( 6.213712 ) );
$this->assertEquals( 10000.00, $this->som->distance_inverse( 6.213712 ) );
}
/**
+2 -3
View File
@@ -26,14 +26,13 @@ class WPStrava_SOMMetricTest extends TestCase {
}
/**
* Test that 42.195 km is 42,195.00 meters using both string and float inputs.
* Test that 42.195 km is 42,195.00 meters using float input.
*
* @author Justin Foell <justin@foell.org>
* @since 1.7.1
*/
public function test_distance_inverse() {
$this->assertEquals( '42,195.00', $this->som->distance_inverse( '42.195' ) );
$this->assertEquals( '42,195.00', $this->som->distance_inverse( 42.195 ) );
$this->assertEquals( 42195.00, $this->som->distance_inverse( 42.195 ) );
}
/**
+7
View File
@@ -8,3 +8,10 @@ require_once dirname( __FILE__ ) . '/../includes/autoload.php';
require_once dirname( __FILE__ ) . '/../vendor/autoload.php';
WP_Mock::bootstrap();
// Pseudo mocks for WP functions.
if ( ! function_exists( 'number_format_i18n' ) ) :
function number_format_i18n( $number, $decimals ) {
return number_format( $number, $decimals );
}
endif;