tests: Fix tests
[nit.git] / src / doc / commands / tests / test_commands_http.nit
index 7cdd240..1f51238 100644 (file)
@@ -38,15 +38,15 @@ class TestCommandsHttp
 
        fun test_cmd_http_entity is test do
                var req = new_request("/test_prog::Character")
-               var cmd = new CmdEntity(test_view)
+               var cmd = new CmdEntity(test_model)
                var res = cmd.http_init(req)
                assert res isa CmdSuccess
                assert cmd.mentity.as(not null).full_name == "test_prog::Character"
        end
 
        fun test_cmd_http_entity_not_found is test do
-               var req = new_request("/Characterzzz")
-               var cmd = new CmdEntity(test_view)
+               var req = new_request("/Characterz")
+               var cmd = new CmdEntity(test_model)
                var res = cmd.http_init(req)
                assert res isa ErrorMEntityNotFound
                assert res.suggestions.first.full_name == "test_prog::Character"
@@ -54,7 +54,7 @@ class TestCommandsHttp
 
        fun test_cmd_http_entity_conflict is test do
                var req = new_request("/+")
-               var cmd = new CmdEntity(test_view)
+               var cmd = new CmdEntity(test_model)
                var res = cmd.http_init(req)
                assert res isa ErrorMEntityConflict
                assert res.conflicts.length == 2
@@ -64,7 +64,7 @@ class TestCommandsHttp
 
        fun test_cmd_http_comment is test do
                var req = new_request("/test_prog::Character")
-               var cmd = new CmdComment(test_view)
+               var cmd = new CmdComment(test_model)
                var res = cmd.http_init(req)
                assert res isa CmdSuccess
                assert cmd.mdoc != null
@@ -72,16 +72,54 @@ class TestCommandsHttp
 
        fun test_cmd_http_comment_no_mdoc is test do
                var req = new_request("/test_prog::Character?fallback=false")
-               var cmd = new CmdComment(test_view)
+               var cmd = new CmdComment(test_model)
                var res = cmd.http_init(req)
                assert res isa WarningNoMDoc
        end
 
+       # CmdEntityLink
+
+       fun test_cmd_http_link is test do
+               var req = new_request("/test_prog::Character")
+               var cmd = new CmdEntityLink(test_model)
+               var res = cmd.http_init(req)
+               assert res isa CmdSuccess
+               assert cmd.text == "Character"
+               assert cmd.title == "Characters can be played by both the human or the machine."
+       end
+
+       fun test_cmd_http_link_with_text is test do
+               var req = new_request("/test_prog::Character?text=foo")
+               var cmd = new CmdEntityLink(test_model)
+               var res = cmd.http_init(req)
+               assert res isa CmdSuccess
+               assert cmd.text == "foo"
+               assert cmd.title == "Characters can be played by both the human or the machine."
+       end
+
+       fun test_cmd_http_link_with_title is test do
+               var req = new_request("/test_prog::Character?title=bar")
+               var cmd = new CmdEntityLink(test_model)
+               var res = cmd.http_init(req)
+               assert res isa CmdSuccess
+               assert cmd.text == "Character"
+               assert cmd.title == "bar"
+       end
+
+       fun test_cmd_http_link_with_text_and_title is test do
+               var req = new_request("/test_prog::Character?text=foo&title=bar")
+               var cmd = new CmdEntityLink(test_model)
+               var res = cmd.http_init(req)
+               assert res isa CmdSuccess
+               assert cmd.text == "foo"
+               assert cmd.title == "bar"
+       end
+
        # CmdInheritance
 
        fun test_cmd_http_parents is test do
                var req = new_request("/test_prog::Warrior")
-               var cmd = new CmdParents(test_view)
+               var cmd = new CmdParents(test_model, test_main)
                var res = cmd.http_init(req)
                assert res isa CmdSuccess
                assert cmd.results.as(not null).length == 1
@@ -89,7 +127,7 @@ class TestCommandsHttp
 
        fun test_cmd_http_ancestors is test do
                var req = new_request("/test_prog::Warrior")
-               var cmd = new CmdAncestors(test_view)
+               var cmd = new CmdAncestors(test_model, test_main)
                var res = cmd.http_init(req)
                assert res isa CmdSuccess
                assert cmd.results.as(not null).length == 2
@@ -97,7 +135,7 @@ class TestCommandsHttp
 
        fun test_cmd_http_ancestorsi_without_parents is test do
                var req = new_request("/test_prog::Warrior?parents=false")
-               var cmd = new CmdAncestors(test_view)
+               var cmd = new CmdAncestors(test_model, test_main)
                var res = cmd.http_init(req)
                assert res isa CmdSuccess
                assert cmd.results.as(not null).length == 1
@@ -105,7 +143,7 @@ class TestCommandsHttp
 
        fun test_cmd_http_children is test do
                var req = new_request("/test_prog::Career")
-               var cmd = new CmdChildren(test_view)
+               var cmd = new CmdChildren(test_model, test_main)
                var res = cmd.http_init(req)
                assert res isa CmdSuccess
                assert cmd.results.as(not null).length == 3
@@ -113,17 +151,25 @@ class TestCommandsHttp
 
        fun test_cmd_http_descendants is test do
                var req = new_request("/test_prog::Career?children=false")
-               var cmd = new CmdDescendants(test_view)
+               var cmd = new CmdDescendants(test_model, test_main)
                var res = cmd.http_init(req)
                assert res isa CmdSuccess
                assert cmd.results.as(not null).length == 0
        end
 
+       fun test_cmd_http_ancestors_with_filter_match is test do
+               var req = new_request("/test_prog::Warrior?match=Object")
+               var cmd = new CmdAncestors(test_model, test_main)
+               var res = cmd.http_init(req)
+               assert res isa CmdSuccess
+               assert cmd.results.as(not null).length == 1
+       end
+
        # CmdSearch
 
        fun test_cmd_http_search is test do
                var req = new_request("/?q=Carer&l=1")
-               var cmd = new CmdSearch(test_view)
+               var cmd = new CmdSearch(test_model)
                var res = cmd.http_init(req)
                assert res isa CmdSuccess
                assert cmd.results.as(not null).first.full_name == "test_prog::Career"
@@ -132,7 +178,7 @@ class TestCommandsHttp
 
        fun test_cmd_http_search_no_query is test do
                var req = new_request("/")
-               var cmd = new CmdSearch(test_view)
+               var cmd = new CmdSearch(test_model)
                var res = cmd.http_init(req)
                assert res isa ErrorNoQuery
        end
@@ -141,7 +187,7 @@ class TestCommandsHttp
 
        fun test_cmd_http_features is test do
                var req = new_request("/test_prog::Character?l=10")
-               var cmd = new CmdFeatures(test_view)
+               var cmd = new CmdFeatures(test_model)
                var res = cmd.http_init(req)
                assert res isa CmdSuccess
                assert cmd.results.as(not null).length == 10
@@ -149,24 +195,32 @@ class TestCommandsHttp
 
        fun test_cmd_http_features_no_features is test do
                var req = new_request("/test_prog$Career$strength_bonus?l=10")
-               var cmd = new CmdFeatures(test_view)
+               var cmd = new CmdFeatures(test_model)
                var res = cmd.http_init(req)
                assert res isa WarningNoFeatures
        end
 
+       fun test_cmd_http_features_with_filter_inherited is test do
+               var req = new_request("/test_prog::TestGame?inherited=TestGame")
+               var cmd = new CmdFeatures(test_model)
+               var res = cmd.http_init(req)
+               assert res isa CmdSuccess
+               assert cmd.results.as(not null).length == 4
+       end
+
        # CmdLinearization
 
        fun test_cmd_http_lin is test do
                var req = new_request("/init?l=10")
-               var cmd = new CmdLinearization(test_view)
+               var cmd = new CmdLinearization(test_model, test_main)
                var res = cmd.http_init(req)
                assert res isa CmdSuccess
-               assert cmd.results.as(not null).length == 10
+               assert cmd.results.as(not null).length == 9
        end
 
        fun test_cmd_http_lin_no_lin is test do
                var req = new_request("/test_prog?l=10")
-               var cmd = new CmdLinearization(test_view)
+               var cmd = new CmdLinearization(test_model, test_main)
                var res = cmd.http_init(req)
                assert res isa WarningNoLinearization
        end
@@ -175,7 +229,7 @@ class TestCommandsHttp
 
        fun test_cmd_http_code is test do
                var req = new_request("/test_prog::Career")
-               var cmd = new CmdEntityCode(test_view, test_builder)
+               var cmd = new CmdEntityCode(test_model, test_builder)
                var res = cmd.http_init(req)
                assert res isa CmdSuccess
                assert cmd.node isa AStdClassdef
@@ -184,7 +238,7 @@ class TestCommandsHttp
 
        fun test_cmd_http_code_format is test do
                var req = new_request("/test_prog::Career?format=html")
-               var cmd = new CmdEntityCode(test_view, test_builder)
+               var cmd = new CmdEntityCode(test_model, test_builder)
                var res = cmd.http_init(req)
                assert res isa CmdSuccess
                assert cmd.node isa AStdClassdef
@@ -193,7 +247,7 @@ class TestCommandsHttp
 
        fun test_cmd_http_code_no_code is test do
                var req = new_request("/test_prog")
-               var cmd = new CmdEntityCode(test_view, test_builder)
+               var cmd = new CmdEntityCode(test_model, test_builder)
                var res = cmd.http_init(req)
                assert res isa WarningNoCode
        end
@@ -202,7 +256,7 @@ class TestCommandsHttp
 
        fun test_cmd_http_results is test do
                var req = new_request("/?kind=modules&l=2")
-               var cmd = new CmdModelEntities(test_view, kind = "modules")
+               var cmd = new CmdModelEntities(test_model, kind = "modules")
                var res = cmd.http_init(req)
                assert res isa CmdSuccess
                assert cmd.results.as(not null).length == 2
@@ -210,7 +264,7 @@ class TestCommandsHttp
 
        fun test_cmd_http_results_random is test do
                var req = new_request("/?kind=packages&l=1")
-               var cmd = new CmdRandomEntities(test_view, kind = "packages")
+               var cmd = new CmdRandomEntities(test_model, kind = "packages")
                var res = cmd.http_init(req)
                assert res isa CmdSuccess
                assert cmd.results.as(not null).length == 1
@@ -220,7 +274,7 @@ class TestCommandsHttp
 
        fun test_cmd_http_uml is test do
                var req = new_request("/test_prog::Character?format=svg")
-               var cmd = new CmdUML(test_view)
+               var cmd = new CmdUML(test_model, test_main)
                var res = cmd.http_init(req)
                assert res isa CmdSuccess
                assert cmd.uml != null
@@ -229,7 +283,7 @@ class TestCommandsHttp
 
        fun test_cmd_http_uml_not_found is test do
                var req = new_request("/strength_bonus")
-               var cmd = new CmdUML(test_view)
+               var cmd = new CmdUML(test_model, test_main)
                var res = cmd.http_init(req)
                assert res isa WarningNoUML
                assert cmd.format == "dot"
@@ -238,7 +292,7 @@ class TestCommandsHttp
 
        fun test_cmd_http_inh_graph is test do
                var req = new_request("/test_prog::Character?pdepth=1&cdepth=1")
-               var cmd = new CmdInheritanceGraph(test_view)
+               var cmd = new CmdInheritanceGraph(test_model, test_main)
                var res = cmd.http_init(req)
                assert res isa CmdSuccess
                assert cmd.graph != null
@@ -249,8 +303,8 @@ class TestCommandsHttp
        # CmdCatalog
 
        fun test_cmd_http_catalog_search is test do
-               var req = new_request("/?q=test&l=1")
-               var cmd = new CmdCatalogSearch(test_view, test_catalog)
+               var req = new_request("/?q=testprog&l=1")
+               var cmd = new CmdCatalogSearch(test_model, test_catalog)
                var res = cmd.http_init(req)
                assert res isa CmdSuccess
                assert cmd.results.as(not null).first.full_name == "test_prog"
@@ -260,7 +314,7 @@ class TestCommandsHttp
 
        fun test_cmd_http_catalog_tag is test do
                var req = new_request("/test", "/:tid")
-               var cmd = new CmdCatalogTag(test_view, test_catalog)
+               var cmd = new CmdCatalogTag(test_model, test_catalog)
                var res = cmd.http_init(req)
                assert res isa CmdSuccess
                assert cmd.tag == "test"
@@ -269,7 +323,7 @@ class TestCommandsHttp
 
        fun test_cmd_http_catalog_person is test do
                var req = new_request("/Alexandre%20Terrasa", "/:pid")
-               var cmd = new CmdCatalogPerson(test_view, test_catalog)
+               var cmd = new CmdCatalogPerson(test_model, test_catalog)
                var res = cmd.http_init(req)
                assert res isa CmdSuccess
                assert cmd.person.as(not null).name == "Alexandre Terrasa"