Add test to catch faulty behaviour in favicon URLs
This commit is contained in:
parent
3f1f500aa7
commit
8e5d6e3c1c
7 changed files with 68 additions and 3 deletions
|
@ -94,11 +94,13 @@ test-suite tests
|
||||||
, Mock.Blog.Wording
|
, Mock.Blog.Wording
|
||||||
, Mock.Collection
|
, Mock.Collection
|
||||||
, Mock.Markdown
|
, Mock.Markdown
|
||||||
|
, Mock.URL
|
||||||
, Structure
|
, Structure
|
||||||
, Utils
|
, Utils
|
||||||
, XML.Card
|
, XML.Card
|
||||||
, XML.Card.Component
|
, XML.Card.Component
|
||||||
, XML.Card.Output
|
, XML.Card.Output
|
||||||
|
, XML.Favicon
|
||||||
build-depends: base
|
build-depends: base
|
||||||
, Cabal
|
, Cabal
|
||||||
, containers
|
, containers
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
module Blog.Skin (
|
module Blog.Skin (
|
||||||
Skin(..)
|
Skin(..)
|
||||||
, build
|
, build
|
||||||
|
, findImage
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import Arguments (Arguments)
|
import Arguments (Arguments)
|
||||||
|
|
|
@ -5,12 +5,12 @@ module Mock.Blog.URL (
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import Blog.URL (AbsoluteURL(..), URLs(..))
|
import Blog.URL (AbsoluteURL(..), URLs(..))
|
||||||
import Network.URL (Host(..), Protocol(..))
|
import Mock.URL (testHost)
|
||||||
|
|
||||||
simple :: URLs
|
simple :: URLs
|
||||||
simple = URLs {
|
simple = URLs {
|
||||||
cards = Just (AbsoluteURL {
|
cards = Just (AbsoluteURL {
|
||||||
Blog.URL.host = Host (HTTP True) "test.net" Nothing
|
Blog.URL.host = testHost
|
||||||
, urlPath = ""
|
, urlPath = ""
|
||||||
, urlParams = []
|
, urlParams = []
|
||||||
})
|
})
|
||||||
|
@ -21,7 +21,7 @@ simple = URLs {
|
||||||
subPath :: URLs
|
subPath :: URLs
|
||||||
subPath = URLs {
|
subPath = URLs {
|
||||||
cards = Just (AbsoluteURL {
|
cards = Just (AbsoluteURL {
|
||||||
Blog.URL.host = Host (HTTP True) "test.net" Nothing
|
Blog.URL.host = testHost
|
||||||
, urlPath = "subPath"
|
, urlPath = "subPath"
|
||||||
, urlParams = []
|
, urlParams = []
|
||||||
})
|
})
|
||||||
|
|
35
test/Mock/URL.hs
Normal file
35
test/Mock/URL.hs
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
module Mock.URL (
|
||||||
|
cdnFavicon
|
||||||
|
, localDiscovered
|
||||||
|
, localFavicon
|
||||||
|
, testHost
|
||||||
|
) where
|
||||||
|
|
||||||
|
import Network.URL (Host(..), Protocol(..), URL(..), URLType(..))
|
||||||
|
|
||||||
|
testHost :: Host
|
||||||
|
testHost = Host (HTTP True) "test.net" Nothing
|
||||||
|
|
||||||
|
cdn :: Host
|
||||||
|
cdn = Host (HTTP True) "cdn.net" Nothing
|
||||||
|
|
||||||
|
cdnFavicon :: URL
|
||||||
|
cdnFavicon = URL {
|
||||||
|
url_type = Absolute cdn
|
||||||
|
, url_path = "favicon.png"
|
||||||
|
, url_params = []
|
||||||
|
}
|
||||||
|
|
||||||
|
localFavicon :: URL
|
||||||
|
localFavicon = URL {
|
||||||
|
url_type = HostRelative
|
||||||
|
, url_path = "favicon.png"
|
||||||
|
, url_params = []
|
||||||
|
}
|
||||||
|
|
||||||
|
localDiscovered :: URL
|
||||||
|
localDiscovered = URL {
|
||||||
|
url_type = HostRelative
|
||||||
|
, url_path = "skin/favicon.png"
|
||||||
|
, url_params = []
|
||||||
|
}
|
|
@ -6,9 +6,11 @@ import Distribution.TestSuite
|
||||||
import qualified Structure (test)
|
import qualified Structure (test)
|
||||||
import Utils (tag)
|
import Utils (tag)
|
||||||
import qualified XML.Card (test)
|
import qualified XML.Card (test)
|
||||||
|
import qualified XML.Favicon (test)
|
||||||
|
|
||||||
tests :: IO [Test]
|
tests :: IO [Test]
|
||||||
tests = return $ tag "xml" <$> [
|
tests = return $ tag "xml" <$> [
|
||||||
XML.Card.test
|
XML.Card.test
|
||||||
|
, XML.Favicon.test
|
||||||
, Structure.test
|
, Structure.test
|
||||||
]
|
]
|
||||||
|
|
25
test/XML/Favicon.hs
Normal file
25
test/XML/Favicon.hs
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
module XML.Favicon (
|
||||||
|
test
|
||||||
|
) where
|
||||||
|
|
||||||
|
import Blog.Skin (findImage)
|
||||||
|
import Distribution.TestSuite
|
||||||
|
import Mock.URL (cdnFavicon, localDiscovered, localFavicon)
|
||||||
|
import Network.URL (URL)
|
||||||
|
import Utils (assertAll, assertEqual, simpleTest, tag)
|
||||||
|
|
||||||
|
check :: IO (Maybe URL) -> Maybe URL -> IO Progress
|
||||||
|
check getter expected = do
|
||||||
|
actual <- getter
|
||||||
|
assertAll $ [
|
||||||
|
assertEqual "URLs" actual expected
|
||||||
|
]
|
||||||
|
|
||||||
|
test :: Test
|
||||||
|
test = tag "favicon" . testGroup "Favicons" $ simpleTest <$> [
|
||||||
|
("auto-discover", check (findImage "favicon" Nothing) (Just localDiscovered))
|
||||||
|
, ("none", check (findImage "blerp" Nothing) Nothing)
|
||||||
|
, ("manual absolute", check (findImage "" (Just "https://cdn.net/favicon.png")) (Just cdnFavicon))
|
||||||
|
, ("manual relative", check (findImage "" (Just "favicon.ico")) (Just localFavicon))
|
||||||
|
, ("manual host-relative", check (findImage "" (Just "/favicon.ico")) (Just localFavicon))
|
||||||
|
]
|
0
test/XML/Favicon/Input/skin/favicon.png
Normal file
0
test/XML/Favicon/Input/skin/favicon.png
Normal file
Loading…
Reference in a new issue