Added isTest property.

This commit is contained in:
Erik C. Thauvin 2019-09-20 00:44:01 -07:00
parent a7f6b6a6c4
commit 1a2fa5273f
2 changed files with 16 additions and 11 deletions

View file

@ -89,6 +89,11 @@ open class Akismet(apiKey: String) {
field = value field = value
} }
/**
* Set the test parameter globally. Can be overwritten in [checkComment], [submitHam] and [submitSpam].
*/
var isTest: Boolean = false
/** /**
* Check if the API Key has been verified. * Check if the API Key has been verified.
*/ */
@ -183,7 +188,7 @@ open class Akismet(apiKey: String) {
blogLang: String = "", blogLang: String = "",
blogCharset: String = "", blogCharset: String = "",
userRole: String = "", userRole: String = "",
isTest: Boolean = false, isTest: Boolean = this.isTest,
recheckReason: String = "", recheckReason: String = "",
other: Map<String, String> = emptyMap() other: Map<String, String> = emptyMap()
): Boolean { ): Boolean {
@ -226,7 +231,7 @@ open class Akismet(apiKey: String) {
blogLang: String = "", blogLang: String = "",
blogCharset: String = "", blogCharset: String = "",
userRole: String = "", userRole: String = "",
isTest: Boolean = false, isTest: Boolean = this.isTest,
recheckReason: String = "", recheckReason: String = "",
other: Map<String, String> = emptyMap() other: Map<String, String> = emptyMap()
): Boolean { ): Boolean {
@ -274,7 +279,7 @@ open class Akismet(apiKey: String) {
blogLang: String = "", blogLang: String = "",
blogCharset: String = "", blogCharset: String = "",
userRole: String = "", userRole: String = "",
isTest: Boolean = false, isTest: Boolean = this.isTest,
recheckReason: String = "", recheckReason: String = "",
other: Map<String, String> = emptyMap() other: Map<String, String> = emptyMap()
): Boolean { ): Boolean {
@ -318,7 +323,7 @@ open class Akismet(apiKey: String) {
blogLang: String = "", blogLang: String = "",
blogCharset: String = "", blogCharset: String = "",
userRole: String = "", userRole: String = "",
isTest: Boolean = false, isTest: Boolean = this.isTest,
recheckReason: String = "", recheckReason: String = "",
other: Map<String, String> = emptyMap() other: Map<String, String> = emptyMap()
): Boolean { ): Boolean {
@ -363,7 +368,7 @@ open class Akismet(apiKey: String) {
blogLang: String = "", blogLang: String = "",
blogCharset: String = "", blogCharset: String = "",
userRole: String = "", userRole: String = "",
isTest: Boolean = false, isTest: Boolean = this.isTest,
recheckReason: String = "", recheckReason: String = "",
other: Map<String, String> = emptyMap() other: Map<String, String> = emptyMap()
): Boolean { ): Boolean {
@ -407,7 +412,7 @@ open class Akismet(apiKey: String) {
blogLang: String = "", blogLang: String = "",
blogCharset: String = "", blogCharset: String = "",
userRole: String = "", userRole: String = "",
isTest: Boolean = false, isTest: Boolean = this.isTest,
recheckReason: String = "", recheckReason: String = "",
other: Map<String, String> = emptyMap() other: Map<String, String> = emptyMap()
): Boolean { ): Boolean {

View file

@ -79,7 +79,7 @@ class AkismetTest {
private val userAgent = "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2) Gecko/20100115 Firefox/3.6" private val userAgent = "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2) Gecko/20100115 Firefox/3.6"
private val referrer = "http://www.google.com" private val referrer = "http://www.google.com"
private val permalink = "http://yourblogdomainname.com/blog/post=1" private val permalink = "http://yourblogdomainname.com/blog/post=1"
private val type = "comment" private val type = Akismet.COMMENT_TYPE_COMMENT
private val author = "admin" private val author = "admin"
private val authorEmail = "test@test.com" private val authorEmail = "test@test.com"
private val authorUrl = "http://www.CheckOutMyCoolSite.com" private val authorUrl = "http://www.CheckOutMyCoolSite.com"
@ -146,6 +146,8 @@ class AkismetTest {
userRole = Akismet.ADMIN_ROLE, userRole = Akismet.ADMIN_ROLE,
isTest = true), "check_comment(admin) -> false") isTest = true), "check_comment(admin) -> false")
akismet.isTest = true
assertTrue( assertTrue(
akismet.checkComment( akismet.checkComment(
userIp = userIp, userIp = userIp,
@ -156,8 +158,7 @@ class AkismetTest {
author = spamAuthor, author = spamAuthor,
authorEmail = spamEmail, authorEmail = spamEmail,
authorUrl = authorUrl, authorUrl = authorUrl,
content = content, content = content), "check_comment -> true")
isTest = true), "check_comment -> true")
assertTrue( assertTrue(
akismet.checkComment( akismet.checkComment(
@ -167,8 +168,7 @@ class AkismetTest {
author = spamAuthor, author = spamAuthor,
authorEmail = spamEmail, authorEmail = spamEmail,
authorUrl = authorUrl, authorUrl = authorUrl,
content = content, content = content), "check_comment(request) -> true")
isTest = true), "check_comment(request) -> true")
} }
@Test @Test