Skip tests that require internet if offline

Change-Id: I679362d9d3595c8212c20d2086d92afcbd58d13f
diff --git a/man/corpusStats-KorAPConnection-method.Rd b/man/corpusStats-KorAPConnection-method.Rd
index 24f6fa0..417c377 100644
--- a/man/corpusStats-KorAPConnection-method.Rd
+++ b/man/corpusStats-KorAPConnection-method.Rd
@@ -23,9 +23,11 @@
 Fetch information about a (virtual) corpus
 }
 \examples{
-\donttest{corpusStats(new("KorAPConnection"))}
+\dontrun{
+corpusStats(new("KorAPConnection"))
 
-kco <- new("KorAPConnection")
-corpusStats(kco, "pubDate in 2017 & articleType=/Zeitung.*/")
+new("KorAPConnection") \%>\%
+  corpusStats("pubDate in 2017 & textType=/Zeit.*/")
+}
 
 }
diff --git a/tests/testthat/test-collocations.R b/tests/testthat/test-collocations.R
index e2d1755..7c05658 100644
--- a/tests/testthat/test-collocations.R
+++ b/tests/testthat/test-collocations.R
@@ -1,4 +1,5 @@
 test_that("collocationScoreQuery works", {
+  skip_if_offline()
   kco <- new("KorAPConnection", cache = TRUE, verbose = TRUE)
   df <- collocationScoreQuery(kco, "Ameisenplage", "heimgesucht", leftContextSize=0, rightContextSize=1)
   expect_gt(df$logDice, 1)
@@ -11,7 +12,8 @@
 
 
 test_that("collocationAnalysis works and warns about missing token", {
-    kco <- new("KorAPConnection",
+  skip_if_offline()
+  kco <- new("KorAPConnection",
                accessToken = NULL,
                verbose = TRUE)
     expect_warning(
@@ -34,6 +36,7 @@
 })
 
 test_that("collocationAnalysis on unaccounted strings does not error out", {
+  skip_if_offline()
   kco <- new("KorAPConnection", accessToken = NULL, verbose = TRUE)
   expect_warning(
     df <- collocationAnalysis(kco, "XXXXXXXXAmeisenplage", vc=c("corpusSigle=/WDD17/", "corpusSigle=/WUD17/"), maxRecurse = 2),
diff --git a/tests/testthat/test-corpusQuery.R b/tests/testthat/test-corpusQuery.R
index df512cd..0483745 100644
--- a/tests/testthat/test-corpusQuery.R
+++ b/tests/testthat/test-corpusQuery.R
@@ -1,10 +1,12 @@
 test_that("frequencyQuery can be cached", {
+  skip_if_offline()
   kco <- new("KorAPConnection", cache = TRUE, verbose = TRUE)
   frequencyQuery(kco, "Ameisenplage", "pubDate since 2014")
   expect_output(frequencyQuery(kco, "Ameisenplage", "pubDate since 2014"), "cached")
 })
 
 test_that("collocationScoreQuery works", {
+  skip_if_offline()
   kco <- new("KorAPConnection", cache = TRUE, verbose = TRUE)
   df <- collocationScoreQuery(kco,"Ameisenplage", "heimgesucht", leftContextSize=0, rightContextSize=1)
   expect_gt(df$logDice, 1)
@@ -16,6 +18,7 @@
 })
 
 test_that("Cache depends on indexRevision (handling also NULL values)", {
+  skip_if_offline()
   kco <- new("KorAPConnection", cache = TRUE, verbose = TRUE)
   kco@indexRevision <- NULL
   frequencyQuery(kco, "Ameisenplage", "pubDate since 2014")
@@ -25,6 +28,7 @@
 })
 
 test_that("corpusQuery returns results", {
+  skip_if_offline()
   q <- new("KorAPConnection") %>%
     corpusQuery("Ameisenplage")
   expect_gt(q@totalResults, 0)
@@ -36,6 +40,7 @@
   vc <- "pubPlace=N\xfcrnberg"
   Encoding(vc)="latin1"
 
+  skip_if_offline()
   q <- new("KorAPConnection") %>%
     corpusQuery(query, vc=vc)
   expect_gt(q@totalResults, 0)
@@ -47,12 +52,14 @@
   vc <- "pubPlace=N\xc3\xbcrnberg"
   Encoding(vc)="UTF-8"
 
+  skip_if_offline()
   q <- new("KorAPConnection") %>%
     corpusQuery(query, vc=vc)
   expect_gt(q@totalResults, 0)
 })
 
 test_that("fetchAll fetches all results", {
+  skip_if_offline()
   q <- new("KorAPConnection", verbose = TRUE) %>%
     corpusQuery("Ameisenplage", vc = "pubDate since 2014")
   expectedResults <- q@totalResults
@@ -61,11 +68,13 @@
 })
 
 test_that("Uncached query for non-matching search string return 0 results", {
+  skip_if_offline()
   q <- new("KorAPConnection", cache = FALSE) %>% corpusQuery("Xmeisenplagx")
   expect_equal( q@totalResults, 0)
 })
 
 test_that("Empty query result is printable", {
+  skip_if_offline()
   q <- new("KorAPConnection", cache = TRUE, verbose = TRUE) %>%
     corpusQuery("Xmeisenplagx", vc = "pubDate in 2012") %>%
     fetchNext()
@@ -73,6 +82,7 @@
 })
 
 test_that("Non-empty query result is printable", {
+  skip_if_offline()
   q <- new("KorAPConnection", cache = TRUE, verbose = TRUE) %>%
     corpusQuery("Ameisenplage", "pubDate since 2014", fields=c("sigle")) %>%
     fetchRest()
@@ -80,6 +90,7 @@
 })
 
 test_that("Query from KorAP URL returns as many results as corresponding direct query", {
+  skip_if_offline()
   kco <- new("KorAPConnection")
   r1 <- corpusQuery(kco, KorAPUrl = "https://korap.ids-mannheim.de/?q=Ameisenplage&cq=pubDate+since+2014&ql=poliqarp")@totalResults
   r2 <- corpusQuery(kco, "Ameisenplage", "pubDate since 2014")@totalResults
@@ -87,6 +98,7 @@
 })
 
 test_that("Typo in query causes error", {
+  skip_if_offline()
   kco <- new("KorAPConnection", verbose = TRUE)
-  expect_error(kco %>% corpusQuery("[[xx"), "unbalanced")
+  expect_message(kco %>% corpusQuery("[[xx"), "unbalanced")
 })
diff --git a/tests/testthat/test-corpusStats.R b/tests/testthat/test-corpusStats.R
index 8143886..b06a54f 100644
--- a/tests/testthat/test-corpusStats.R
+++ b/tests/testthat/test-corpusStats.R
@@ -1,4 +1,5 @@
 test_that("corpusStats works", {
+  skip_if_offline()
   stats <- new("KorAPConnection") %>% corpusStats()
   expect_gt(stats@tokens, 0)
   expect_gt(stats@paragraphs, 0)
@@ -7,11 +8,13 @@
 
 
 test_that("Printing corpusStats for the whole corpus works", {
+  skip_if_offline()
   stats <- new("KorAPConnection") %>% corpusStats()
   expect_error(print(stats), NA)
 })
 
 test_that("Printing corpusStats for a sub-corpus works", {
+  skip_if_offline()
   stats <- new("KorAPConnection") %>% corpusStats("pubDate in 2018")
   expect_error(print(stats), NA)
 })
diff --git a/tests/testthat/test-demos.R b/tests/testthat/test-demos.R
index c0412ba..b51a4cd 100644
--- a/tests/testthat/test-demos.R
+++ b/tests/testthat/test-demos.R
@@ -1,4 +1,5 @@
 test_that("Alternatives over time highcharter example works", {
+  skip_if_offline()
   year <- c(2013:2018)
   alternatives <- c("macht []{0,3} Sinn", "ergibt []{0,3} Sinn")
   hc <- new("KorAPConnection", verbose = TRUE) %>%
@@ -12,6 +13,7 @@
 })
 
 test_that("Multiple queries over time highcharter example works", {
+  skip_if_offline()
   year <- c(2013:2018)
   alternatives <- c("macht []{0,3} Sinn", "ergibt []{0,3} Sinn")
 
@@ -26,6 +28,7 @@
 })
 
 test_that("Single query in multiple over time highcharter example works", {
+  skip_if_offline()
   year <- c(2013:2018)
   alternatives <- c("macht []{0,3} Sinn", "ergibt []{0,3} Sinn")
 
@@ -40,6 +43,7 @@
 })
 
 test_that("Single query over time highcharter example works", {
+  skip_if_offline()
   year <- c(2013:2018)
   q <- c("macht []{0,3} Sinn")
 
@@ -54,6 +58,7 @@
 })
 
 test_that("Auto conditions over time highcharter example works", {
+  skip_if_offline()
   kco <- new("KorAPConnection", verbose=TRUE)
   hc <- expand_grid(
     myconditions = c("textDomain = /Wirtschaft.*/",
@@ -70,6 +75,7 @@
 })
 
 test_that("Single condition over time highcharter example works", {
+  skip_if_offline()
   kco <- new("KorAPConnection", verbose=TRUE)
   hc <- expand_grid(
     condition = c("textDomain = /Wirtschaft.*/"),
@@ -85,6 +91,7 @@
 })
 
 test_that("Multiple conditions over time highcharter example works", {
+  skip_if_offline()
   kco <- new("KorAPConnection", verbose=TRUE)
   hc <- expand_grid(
     condition = c("textDomain = /Wirtschaft.*/",
@@ -101,6 +108,7 @@
 })
 
 test_that("Multiple conditions and queries over time highcharter example works", {
+  skip_if_offline()
   kco <- new("KorAPConnection", verbose=TRUE)
   hc <- expand_grid(
     qx = c("[tt/l=Heuschrecke]", "Ameise"),
@@ -117,7 +125,8 @@
   expect_true(all(class(hc) %in% c("highchart", "htmlwidget")))
 })
 
-test_that("collocationScoreQuery works iwth hchart and hc_add_onclick_korap_search", {
+test_that("collocationScoreQuery works with hchart and hc_add_onclick_korap_search", {
+  skip_if_offline()
   kco <- new("KorAPConnection", cache = TRUE, verbose = TRUE)
   df <- collocationScoreQuery(kco,"Ameisenplage", "heimgesucht", leftContextSize=0, rightContextSize=1)
   hc <- hchart(df, type="spline", hcaes(label, logDice))