Skip to content

Commit

Permalink
test: add mock for language API in acceptance tests
Browse files Browse the repository at this point in the history
  • Loading branch information
stklcode committed May 13, 2024
1 parent 899df20 commit b4ed229
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
7 changes: 4 additions & 3 deletions bin/behat.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,11 @@ sleep 5

php -S "$WORDPRESS_URL" -t "$WORDPRESS_PATH" >/dev/null 2>&1 &

ln -s $PLUGIN_PATH $WORDPRESS_PATH/wp-content/plugins/antispam-bee
ln -s $PLUGIN_PATH/tests/Acceptance/Behat/env/mu-plugins/ $WORDPRESS_PATH/wp-content/mu-plugins
ln -s "$PLUGIN_PATH" "$WORDPRESS_PATH/wp-content/plugins/antispam-bee"
ln -s "$PLUGIN_PATH/tests/Acceptance/Behat/env/mu-plugins/" "$WORDPRESS_PATH/wp-content/mu-plugins"

ls $WORDPRESS_PATH/wp-content/plugins
ls "$WORDPRESS_PATH/wp-content/mu-plugins"
ls "$WORDPRESS_PATH/wp-content/plugins/"

vendor/bin/wp --path=$WORDPRESS_PATH plugin activate antispam-bee
vendor/bin/wp --path=$WORDPRESS_PATH theme activate twentynineteen
Expand Down
24 changes: 24 additions & 0 deletions tests/Acceptance/Behat/env/mu-plugins/mock-language-api.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php
/**
* Plugin Name: Mock Language API
*/

add_filter(
'antispam_bee_detected_lang',
function( $detected_lang, $comment_text ) {
if ( ! empty( $comment_text ) && strlen( $comment_text ) >= 50 ) {
// Only operate on strings above 50 characters.
if (strpos($comment_text, 'English') !== false) {
// We can only detect English.
return 'en';
} else {
// Not "null", so we don't continue querying the real API.
return 'xx';
}
} else {
return null;
}
},
10,
2
);

0 comments on commit b4ed229

Please sign in to comment.