-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #654 from weather-gov/eg-589-alert-description
Alert description parsing
- Loading branch information
Showing
4 changed files
with
108 additions
and
5 deletions.
There are no files selected for viewing
52 changes: 52 additions & 0 deletions
52
web/modules/weather_data/src/Service/Test/TryParsingDescriptionText.php.test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
|
||
namespace Drupal\weather_data\Service\Test; | ||
|
||
use Drupal\weather_data\Service\WeatherAlertTrait; | ||
|
||
final class TryParsingDescriptionTextTest extends Base | ||
{ | ||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
} | ||
|
||
/** | ||
* Test the tryParsingDescriptionText static method | ||
*/ | ||
public function testBasic(): void | ||
{ | ||
$rawDescription = | ||
"* WHAT...Snow expected. Total snow accumulations of 5 to 10\ninches.\n\n"; | ||
$rawDescription .= "* WHERE...Eastern San Juan Mountains Above 10000 Feet.\n\n"; | ||
$rawDescription .= "* WHEN...From 11 PM this evening to 11 PM MST Thursday.\n\n"; | ||
$rawDescription .= "* IMPACTS...Travel could be very difficult. The hazardous | ||
conditions may impact travel over Wolf Creek Pass."; | ||
$parsedDescription = WeatherAlertTrait::tryParsingDescriptionText( | ||
$rawDescription, | ||
); | ||
|
||
$expected = [ | ||
"what" => | ||
"Snow expected. Total snow accumulations of 5 to 10\ninches.", | ||
"where" => "Eastern San Juan Mountains Above 10000 Feet.", | ||
"when" => "From 11 PM this evening to 11 PM MST Thursday.", | ||
"impacts" => | ||
"Travel could be very difficult. The hazardous\nconditions may impact travel over Wolf Creek Pass.", | ||
]; | ||
$this->assertEquals($expected, $parsedDescription); | ||
} | ||
|
||
public function testNotMatching(): void | ||
{ | ||
$rawDescription = | ||
"* This is an alert with\n\nmultiple newlines, but it has nothing "; | ||
$rawDescription .= "to do with the what WHERE WHEN\n format we are concerned with."; | ||
$parsedDescription = WeatherAlertTrait::tryParsingDescriptionText( | ||
$rawDescription, | ||
); | ||
$expected = $rawDescription; | ||
|
||
$this->assertEquals($expected, $parsedDescription); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters