Revisited the persistence layer.

Simplified schema to focus on user and node.
Now possible to have sqlite via ODBC and/or mysql support, and select using configuration file.
Updated demo example.
This commit is contained in:
2015-01-27 19:48:37 +01:00
parent db9e40cec4
commit 7d5869f3b9
71 changed files with 2665 additions and 3313 deletions

View File

@@ -1,7 +1,7 @@
note
description : "tests application root class"
date : "$Date: 2014-08-20 15:21:15 -0300 (mi., 20 ago. 2014) $"
revision : "$Revision: 95678 $"
date : "$Date: 2015-01-27 19:15:02 +0100 (mar., 27 janv. 2015) $"
revision : "$Revision: 96542 $"
class
APPLICATION
@@ -17,78 +17,25 @@ feature {NONE} -- Initialization
make
-- Run application.
local
user: USER_DATA_PROVIDER
node: NODE_DATA_PROVIDER
l_security: SECURITY_PROVIDER
l_profile, l_db_profile: CMS_USER_PROFILE
l_cursor: TABLE_ITERATION_CURSOR [READABLE_STRING_8, READABLE_STRING_8]
l_list: LIST[CMS_NODE]
storage: CMS_STORAGE
l_node: CMS_NODE
do
create connection.login_with_schema ("cms_dev", "root", "")
-- create user.make (connection)
-- create node.make (connection)
(create {CLEAN_DB}).clean_db(connection)
create {CMS_STORAGE_MYSQL} storage.make (connection)
l_node := custom_node ("Content", "Summary", "Title")
storage.save_user (default_user)
storage.save_user (custom_user ("u2", "p2", "e2"))
storage.new_user (default_user)
storage.new_user (custom_user ("u2", "p2", "e2"))
l_node.set_author (storage.user_by_email (default_user.email))
storage.save_node (l_node)
if attached {CMS_NODE} storage.node (1) as ll_node then
storage.new_node (l_node)
if attached {CMS_NODE} storage.node_by_id (1) as ll_node then
storage.update_node_title (2,ll_node.id, "New Title")
check
attached {CMS_NODE} storage.node (1) as u_node and then not (u_node.title ~ ll_node.title) and then u_node.content ~ ll_node.content and then u_node.summary ~ ll_node.summary
attached {CMS_NODE} storage.node_by_id (1) as u_node and then not (u_node.title ~ ll_node.title) and then u_node.content ~ ll_node.content and then u_node.summary ~ ll_node.summary
end
end
-- user.new_user ("test", "test","test@admin.com")
-- if attached {CMS_USER} user.user_by_name ("test") as l_user then
-- create l_profile.make
-- l_profile.force ("Eiffel", "language")
-- l_profile.force ("Argentina", "country")
-- l_profile.force ("GMT-3", "time zone")
-- user.save_profile (l_user.id, l_profile)
-- l_db_profile := user.user_profile (l_user.id)
-- from
-- l_cursor := l_db_profile.new_cursor
-- until
-- l_cursor.after
-- loop
-- print (l_cursor.item + " - " + l_cursor.key + "%N")
-- l_cursor.forth
-- end
-- create {ARRAYED_LIST[CMS_NODE]} l_list.make (0)
-- node.new_node (default_node)
-- node.new_node (custom_node ("content1", "summary1", "title1"))
-- node.new_node (custom_node ("content2", "summary2", "title2"))
-- node.new_node (custom_node ("content3", "summary3", "title3"))
-- user.new_user ("u1", "u1", "email")
-- if attached user.user_by_name ("u1") as ll_user then
-- node.add_collaborator (ll_user.id, 1)
-- node.add_collaborator (ll_user.id, 2)
-- node.add_collaborator (ll_user.id, 3)
-- node.add_collaborator (ll_user.id, 4)
-- across node.collaborator_nodes (l_user.id) as c loop
-- print (c.item.title)
-- end
-- end
-- if attached user.user_by_name ("u1") as ll_user then
-- node.add_author (ll_user.id, 1)
-- if attached node.node_author (1) as l_author then
-- print (l_author.name)
-- end
-- end
-- end
end

View File

@@ -3,8 +3,8 @@ note
Eiffel tests that can be executed by testing tool.
]"
author: "EiffelStudio test wizard"
date: "$Date$"
revision: "$Revision$"
date: "$Date: 2015-01-27 19:15:02 +0100 (mar., 27 janv. 2015) $"
revision: "$Revision: 96542 $"
testing:"execution/isolated"
class
@@ -29,8 +29,8 @@ feature {NONE} -- Events
on_prepare
-- <Precursor>
do
(create {CLEAN_DB}).clean_db(connection)
assert ("Empty Nodes", node_provider.nodes.after)
(create {CLEAN_DB}).clean_db (connection)
assert ("Empty Nodes", storage.nodes_count = 0)
end
on_clean
@@ -43,14 +43,14 @@ feature -- Test routines
test_new_node
note
testing: "execution/isolated"
do
assert ("Empty Nodes", node_provider.nodes.after)
node_provider.new_node (default_node)
assert ("Not empty Nodes after new_node", not node_provider.nodes.after)
do
assert ("Empty Nodes", storage.nodes_count = 0)
storage.new_node (default_node)
assert ("Not empty Nodes after new_node", not storage.nodes.after)
-- Exist node with id 1
assert ("Exist node with id 1", attached node_provider.node (1))
assert ("Exist node with id 1", attached storage.node_by_id (1))
-- Not exist node with id 2
assert ("Not exist node with id 2", node_provider.node (2) = Void)
assert ("Not exist node with id 2", storage.node_by_id (2) = Void)
end
@@ -60,31 +60,31 @@ feature -- Test routines
local
l_node: CMS_NODE
do
assert ("Empty Nodes", node_provider.nodes.after)
assert ("Empty Nodes", storage.nodes.after)
l_node := custom_node ("<h1> test node udpate </h1>", "Update node", "Test case update")
node_provider.new_node (l_node)
assert ("Not empty Nodes after new_node", not node_provider.nodes.after)
storage.new_node (l_node)
assert ("Not empty Nodes after new_node", not storage.nodes.after)
-- Exist node with id 1
assert ("Exist node with id 1", attached {CMS_NODE} node_provider.node (1) as ll_node and then ll_node.content ~ l_node.content and then ll_node.summary ~ l_node.summary and then ll_node.title ~ l_node.title )
assert ("Exist node with id 1", attached {CMS_NODE} storage.node_by_id (1) as ll_node and then ll_node.content ~ l_node.content and then ll_node.summary ~ l_node.summary and then ll_node.title ~ l_node.title )
-- Update node (content and summary)
if attached {CMS_NODE} node_provider.node (1) as l_un then
if attached {CMS_NODE} storage.node_by_id (1) as l_un then
l_un.set_content ("<h1>Updating test node udpate </h1>")
l_un.set_summary ("updating summary")
node_provider.update_node (0,l_un)
assert ("Exist node with id 1", attached {CMS_NODE} node_provider.node (1) as ll_node and then not (ll_node.content ~ l_node.content) and then not (ll_node.summary ~ l_node.summary) and then ll_node.title ~ l_node.title )
assert ("Exist node with id 1", attached {CMS_NODE} node_provider.node (1) as ll_node and then ll_node.content ~ l_un.content and then ll_node.summary ~ l_un.summary and then ll_node.title ~ l_un.title )
storage.update_node (l_un)
assert ("Exist node with id 1", attached {CMS_NODE} storage.node_by_id (1) as ll_node and then not (ll_node.content ~ l_node.content) and then not (ll_node.summary ~ l_node.summary) and then ll_node.title ~ l_node.title )
assert ("Exist node with id 1", attached {CMS_NODE} storage.node_by_id (1) as ll_node and then ll_node.content ~ l_un.content and then ll_node.summary ~ l_un.summary and then ll_node.title ~ l_un.title )
end
-- Update node (content and summary and title)
if attached {CMS_NODE} node_provider.node (1) as l_un then
if attached {CMS_NODE} storage.node_by_id (1) as l_un then
l_un.set_content ("<h1>Updating test node udpate </h1>")
l_un.set_summary ("updating summary")
l_un.set_title ("Updating Test case")
node_provider.update_node (0,l_un)
assert ("Exist node with id 1", attached {CMS_NODE} node_provider.node (1) as ll_node and then not (ll_node.content ~ l_node.content) and then not (ll_node.summary ~ l_node.summary) and then not (ll_node.title ~ l_node.title) )
assert ("Exist node with id 1", attached {CMS_NODE} node_provider.node (1) as ll_node and then ll_node.content ~ l_un.content and then ll_node.summary ~ l_un.summary and then ll_node.title ~ l_un.title )
storage.update_node (l_un)
assert ("Exist node with id 1", attached {CMS_NODE} storage.node_by_id (1) as ll_node and then not (ll_node.content ~ l_node.content) and then not (ll_node.summary ~ l_node.summary) and then not (ll_node.title ~ l_node.title) )
assert ("Exist node with id 1", attached {CMS_NODE} storage.node_by_id (1) as ll_node and then ll_node.content ~ l_un.content and then ll_node.summary ~ l_un.summary and then ll_node.title ~ l_un.title )
end
end
@@ -93,19 +93,23 @@ feature -- Test routines
testing: "execution/isolated"
local
l_node: CMS_NODE
u: CMS_USER
do
assert ("Empty Nodes", node_provider.nodes.after)
u := default_user
storage.new_user (u)
assert ("Empty Nodes", storage.nodes.after)
l_node := custom_node ("<h1> test node udpate </h1>", "Update node", "Test case update")
node_provider.new_node (l_node)
assert ("Not empty Nodes after new_node", not node_provider.nodes.after)
storage.new_node (l_node)
assert ("Not empty Nodes after new_node", not storage.nodes.after)
-- Exist node with id 1
assert ("Exist node with id 1", attached {CMS_NODE} node_provider.node (1) as ll_node and then ll_node.content ~ l_node.content and then ll_node.summary ~ l_node.summary and then ll_node.title ~ l_node.title )
assert ("Exist node with id 1", attached {CMS_NODE} storage.node_by_id (1) as ll_node and then ll_node.content ~ l_node.content and then ll_node.summary ~ l_node.summary and then ll_node.title ~ l_node.title )
-- Update node title
if attached {CMS_NODE} node_provider.node (1) as l_un then
node_provider.update_node_title (l_un.id, "New Title")
assert ("Exist node with id 1", attached {CMS_NODE} node_provider.node (1) as ll_node and then ll_node.content ~ l_un.content and then ll_node.summary ~ l_un.summary and then not ( ll_node.title ~ l_un.title) and then ll_node.title ~ "New Title" )
if attached {CMS_NODE} storage.node_by_id (1) as l_un then
storage.update_node_title (u.id, l_un.id, "New Title")
assert ("Exist node with id 1", attached {CMS_NODE} storage.node_by_id (1) as ll_node and then ll_node.content ~ l_un.content and then ll_node.summary ~ l_un.summary and then not ( ll_node.title ~ l_un.title) and then ll_node.title ~ "New Title" )
end
end
@@ -114,19 +118,23 @@ feature -- Test routines
testing: "execution/isolated"
local
l_node: CMS_NODE
u: CMS_USER
do
assert ("Empty Nodes", node_provider.nodes.after)
u := default_user
storage.new_user (u)
assert ("Empty Nodes", storage.nodes.after)
l_node := custom_node ("<h1> test node udpate </h1>", "Update node", "Test case update")
node_provider.new_node (l_node)
assert ("Not empty Nodes after new_node", not node_provider.nodes.after)
storage.new_node (l_node)
assert ("Not empty Nodes after new_node", not storage.nodes.after)
-- Exist node with id 1
assert ("Exist node with id 1", attached {CMS_NODE} node_provider.node (1) as ll_node and then ll_node.content ~ l_node.content and then ll_node.summary ~ l_node.summary and then ll_node.title ~ l_node.title )
assert ("Exist node with id 1", attached {CMS_NODE} storage.node_by_id (1) as ll_node and then ll_node.content ~ l_node.content and then ll_node.summary ~ l_node.summary and then ll_node.title ~ l_node.title )
-- Update node summary
if attached {CMS_NODE} node_provider.node (1) as l_un then
node_provider.update_node_summary (l_un.id,"New Summary")
assert ("Exist node with id 1", attached {CMS_NODE} node_provider.node (1) as ll_node and then ll_node.content ~ l_un.content and then not (ll_node.summary ~ l_un.summary) and then ll_node.summary ~ "New Summary" and then ll_node.title ~ l_un.title)
if attached {CMS_NODE} storage.node_by_id (1) as l_un then
storage.update_node_summary (u.id, l_un.id, "New Summary")
assert ("Exist node with id 1", attached {CMS_NODE} storage.node_by_id (1) as ll_node and then ll_node.content ~ l_un.content and then not (ll_node.summary ~ l_un.summary) and then ll_node.summary ~ "New Summary" and then ll_node.title ~ l_un.title)
end
end
@@ -135,22 +143,26 @@ feature -- Test routines
testing: "execution/isolated"
local
l_node: CMS_NODE
u: CMS_USER
do
assert ("Empty Nodes", node_provider.nodes.after)
u := default_user
storage.new_user (u)
assert ("Empty Nodes", storage.nodes.after)
l_node := custom_node ("<h1> test node udpate </h1>", "Update node", "Test case update")
connection.begin_transaction
node_provider.new_node (l_node)
assert ("Not empty Nodes after new_node", not node_provider.nodes.after)
storage.sql_begin_transaction
storage.new_node (l_node)
assert ("Not empty Nodes after new_node", not storage.nodes.after)
-- Exist node with id 1
assert ("Exist node with id 1", attached {CMS_NODE} node_provider.node (1) as ll_node and then ll_node.content ~ l_node.content and then ll_node.summary ~ l_node.summary and then ll_node.title ~ l_node.title )
assert ("Exist node with id 1", attached {CMS_NODE} storage.node_by_id (1) as ll_node and then ll_node.content ~ l_node.content and then ll_node.summary ~ l_node.summary and then ll_node.title ~ l_node.title )
-- Update node content
if attached {CMS_NODE} node_provider.node (1) as l_un then
node_provider.update_node_content (l_un.id,"New Content")
assert ("Exist node with id 1", attached {CMS_NODE} node_provider.node (1) as ll_node and then not (ll_node.content ~ l_un.content) and then ll_node.content ~ "New Content" and then ll_node.summary ~ l_un.summary and then ll_node.title ~ l_un.title)
if attached {CMS_NODE} storage.node_by_id (1) as l_un then
storage.update_node_content (u.id, l_un.id, "New Content")
assert ("Exist node with id 1", attached {CMS_NODE} storage.node_by_id (1) as ll_node and then not (ll_node.content ~ l_un.content) and then ll_node.content ~ "New Content" and then ll_node.summary ~ l_un.summary and then ll_node.title ~ l_un.title)
end
connection.commit
storage.sql_commit_transaction
end
@@ -158,17 +170,17 @@ feature -- Test routines
local
l_node: CMS_NODE
do
assert ("Empty Nodes", node_provider.nodes.after)
assert ("Empty Nodes", storage.nodes.after)
l_node := custom_node ("<h1> test node udpate </h1>", "Update node", "Test case update")
node_provider.new_node (l_node)
assert ("Not empty Nodes after new_node", not node_provider.nodes.after)
storage.new_node (l_node)
assert ("Not empty Nodes after new_node", not storage.nodes.after)
-- Exist node with id 1
assert ("Exist node with id 1", attached {CMS_NODE} node_provider.node (1) as ll_node and then ll_node.content ~ l_node.content and then ll_node.summary ~ l_node.summary and then ll_node.title ~ l_node.title )
assert ("Exist node with id 1", attached {CMS_NODE} storage.node_by_id (1) as ll_node and then ll_node.content ~ l_node.content and then ll_node.summary ~ l_node.summary and then ll_node.title ~ l_node.title )
-- Delte node 1
node_provider.delete_node (1)
assert ("Node does not exist", node_provider.node (1) = Void)
storage.delete_node_by_id (1)
assert ("Node does not exist", storage.node_by_id (1) = Void)
end
test_recent_nodes
@@ -179,142 +191,51 @@ feature -- Test routines
local
i : INTEGER
do
assert ("Empty Nodes", node_provider.nodes.after)
assert ("Empty Nodes", storage.nodes.after)
across 1 |..| 10 as c loop
node_provider.new_node (custom_node ("Content_" + c.item.out, "Summary_" + c.item.out, "Title_" + c.item.out))
storage.new_node (custom_node ("Content_" + c.item.out, "Summary_" + c.item.out, "Title_" + c.item.out))
end
-- Scenario (0,10) rows, recents (10 down to 1)
i := 10
across node_provider.recent_nodes (0, 10) as c loop
across storage.recent_nodes (0, 10) as c loop
assert ("Same id:" + i.out, c.item.id = i)
i := i - 1
end
-- Scenario (5, 10) rows, recent nodes (5 down to 1)
i := 5
across node_provider.recent_nodes (5, 10) as c loop
across storage.recent_nodes (5, 10) as c loop
assert ("Same id:" + i.out, c.item.id = i)
i := i - 1
end
-- Scenario (9,10) rows, recent node 1
i := 1
across node_provider.recent_nodes (9, 10) as c loop
across storage.recent_nodes (9, 10) as c loop
assert ("Same id:" + i.out, c.item.id = i)
i := i - 1
end
-- Scenrario 10..10 empty
assert ("Empty", node_provider.recent_nodes (10, 10).after)
end
test_new_node_without_user
do
node_provider.new_node (default_node)
user_provider.new_user ("u1", "u1", "email")
if attached user_provider.user_by_name ("u1") as l_user then
assert ("Empty nodes", node_provider.author_nodes (l_user.id).after)
end
assert ("Empty", storage.recent_nodes (10, 10).after)
end
test_new_node_add_author
do
node_provider.new_node (default_node)
assert ("Exist node with id 1", attached {CMS_NODE} node_provider.node (1))
user_provider.new_user ("u1", "u1", "email")
if attached user_provider.user_by_name ("u1") as l_user then
node_provider.add_author (l_user.id, 1)
assert ("Author not void for node 1", attached node_provider.node_author (1))
end
end
test_new_node_add_collaborator
do
node_provider.new_node (default_node)
assert ("Exist node with id 1", attached {CMS_NODE} node_provider.node (1))
user_provider.new_user ("u1", "u1", "email")
if attached user_provider.user_by_name ("u1") as l_user then
node_provider.add_collaborator (l_user.id, 1)
assert ("Not Empty Collaborator for node 1", not node_provider.node_collaborators (1).after)
end
end
test_multiple_nodes_add_collaborator
local
l_list: LIST[CMS_NODE]
do
create {ARRAYED_LIST[CMS_NODE]} l_list.make (0)
node_provider.new_node (default_node)
node_provider.new_node (custom_node ("content1", "summary1", "title1"))
node_provider.new_node (custom_node ("content2", "summary2", "title2"))
node_provider.new_node (custom_node ("content3", "summary3", "title3"))
user_provider.new_user ("u1", "u1", "email")
if attached user_provider.user_by_name ("u1") as l_user then
node_provider.add_collaborator (l_user.id, 1)
node_provider.add_collaborator (l_user.id, 2)
node_provider.add_collaborator (l_user.id, 3)
node_provider.add_collaborator (l_user.id, 4)
assert ("Not Empty Collaborator for node 1", not node_provider.node_collaborators (1).after)
assert ("Not Empty Collaborator for node 2", not node_provider.node_collaborators (2).after)
assert ("Not Empty Collaborator for node 3", not node_provider.node_collaborators (3).after)
assert ("Not Empty Collaborator for node 4", not node_provider.node_collaborators (4).after)
end
end
test_nodes_collaborator
local
l_list: LIST[CMS_NODE]
do
create {ARRAYED_LIST[CMS_NODE]} l_list.make (0)
node_provider.new_node (default_node)
node_provider.new_node (custom_node ("content1", "summary1", "title1"))
node_provider.new_node (custom_node ("content2", "summary2", "title2"))
node_provider.new_node (custom_node ("content3", "summary3", "title3"))
user_provider.new_user ("u1", "u1", "email")
if attached user_provider.user_by_name ("u1") as l_user then
node_provider.add_collaborator (l_user.id, 1)
node_provider.add_collaborator (l_user.id, 2)
node_provider.add_collaborator (l_user.id, 3)
node_provider.add_collaborator (l_user.id, 4)
across node_provider.collaborator_nodes (l_user.id) as c loop
l_list.force (c.item)
storage.new_node (default_node)
assert ("Exist node with id 1", attached {CMS_NODE} storage.node_by_id (1))
storage.new_user (custom_user ("u1", "u1", "email"))
if attached storage.user_by_name ("u1") as l_user then
if attached storage.node_by_id (1) as l_node then
l_node.set_author (l_user)
storage.update_node (l_node)
assert ("Author not void for node 1", attached storage.node_author (1))
end
assert ("User is collaborating in 4 nodes", l_list.count = 4)
end
end
feature {NONE} -- Implementation
node_provider: NODE_DATA_PROVIDER
-- node provider.
once
create Result.make (connection)
end
user_provider: USER_DATA_PROVIDER
-- user provider.
once
create Result.make (connection)
end
feature {NONE} -- Implementation Fixture Factories
default_node: CMS_NODE
do
Result := custom_node ("Default content", "default summary", "Default")
end
custom_node (a_content, a_summary, a_title: READABLE_STRING_32): CMS_NODE
do
create Result.make (a_content, a_summary, a_title)
end
end

View File

@@ -1,100 +0,0 @@
note
description: "Summary description for {ROLE_TEST_SET}."
author: ""
date: "$Date$"
revision: "$Revision$"
class
ROLE_TEST_SET
inherit
EQA_TEST_SET
redefine
on_prepare,
on_clean
select
default_create
end
ABSTRACT_DB_TEST
rename
default_create as default_db_test
end
feature {NONE} -- Events
on_prepare
-- <Precursor>
do
(create {CLEAN_DB}).clean_db(connection)
end
on_clean
-- <Precursor>
do
end
feature -- Test routines
test_roles_empty
do
assert ("Not elements",role_provider.roles.after)
assert ("Count = 0", role_provider.count = 0)
end
test_roles_by_id_not_exist
do
assert ("Void", role_provider.role (1) = Void)
end
test_roles_by_name_not_exist
do
assert ("Void", role_provider.role_by_name ("admin") = Void)
end
test_new_role
do
assert ("Count = 0", role_provider.count = 0)
role_provider.new_role ("admin")
assert ("Count = 1", role_provider.count = 1)
assert ("Expected role", attached role_provider.role (1) as l_role and then l_role.name ~ "admin")
assert ("Expected role", attached role_provider.role_by_name ("admin") as l_role and then l_role.id = 1)
end
test_permissions_empty_not_exist_role
do
assert ("Not elements",role_provider.permission_by_role (1).after)
end
test_permissions_empty_exist_role
do
assert ("Count = 0", role_provider.count = 0)
role_provider.new_role ("admin")
assert ("Count = 1", role_provider.count = 1)
assert ("Exist role",not role_provider.roles.after)
assert ("Not permission by role 1 elements",role_provider.permission_by_role (1).after)
end
test_new_role_with_permissions
do
assert ("Count = 0", role_provider.count = 0)
role_provider.new_role ("admin")
role_provider.save_role_permission (1, "Create Page")
role_provider.save_role_permission (1, "Edit Page")
role_provider.save_role_permission (1, "Delete Page")
assert ("Count = 1", role_provider.count = 1)
assert ("Exist role",not role_provider.roles.after)
assert ("Exist role permissions",not role_provider.permission_by_role (1).after)
assert ("Not Exist role permissions, for id 2",role_provider.permission_by_role (2).after)
end
feature {NONE} -- Implementation
role_provider: ROLE_DATA_PROVIDER
-- role provider.
once
create Result.make (connection)
end
end

View File

@@ -1,8 +1,8 @@
note
description: "Summary description for {STORAGE_TEST_SET}."
author: ""
date: "$Date$"
revision: "$Revision$"
date: "$Date: 2015-01-27 19:15:02 +0100 (mar., 27 janv. 2015) $"
revision: "$Revision: 96542 $"
class
STORAGE_TEST_SET
@@ -109,15 +109,15 @@ feature -- Test routines
retry
end
test_save_user
test_new_user
do
storage.save_user (default_user)
storage.new_user (default_user)
assert ("Has user", storage.has_user)
end
test_user_by_id
do
storage.save_user (default_user)
storage.new_user (default_user)
assert ("Has user", storage.has_user)
if attached {CMS_USER} storage.user_by_id (1) as l_user then
assert ("Exist", True)
@@ -130,7 +130,7 @@ feature -- Test routines
test_user_by_name
do
storage.save_user (default_user)
storage.new_user (default_user)
assert ("Has user", storage.has_user)
if attached {CMS_USER} storage.user_by_name ("test") as l_user then
assert ("Exist", True)
@@ -142,7 +142,7 @@ feature -- Test routines
test_user_by_email
do
storage.save_user (default_user)
storage.new_user (default_user)
assert ("Has user", storage.has_user)
if attached {CMS_USER} storage.user_by_email ("test@test.com") as l_user then
assert ("Exist", True)
@@ -154,7 +154,7 @@ feature -- Test routines
test_invalid_credential
do
storage.save_user (default_user)
storage.new_user (default_user)
assert ("Has user test", attached storage.user_by_name ("test"))
assert ("Wrong password", not storage.is_valid_credential ("test", "test"))
assert ("Wrong user", not storage.is_valid_credential ("test1", "test"))
@@ -162,7 +162,7 @@ feature -- Test routines
test_valid_credential
do
storage.save_user (default_user)
storage.new_user (default_user)
assert ("Has user test", attached storage.user_by_name ("test"))
assert ("Valid password", storage.is_valid_credential ("test", "password"))
end
@@ -177,11 +177,11 @@ feature -- Test routines
l_nodes: LIST[CMS_NODE]
l_node: CMS_NODE
do
storage.save_user (default_user)
storage.new_user (default_user)
across 1 |..| 10 as c loop
l_node := custom_node ("Content_" + c.item.out, "Summary_" + c.item.out, "Title_" + c.item.out)
l_node.set_author (storage.user_by_email (default_user.email))
storage.save_node (l_node)
storage.new_node (l_node)
end
l_nodes := storage.recent_nodes (0, 10)
assert ("10 recent nodes", l_nodes.count = 10)
@@ -207,26 +207,26 @@ feature -- Test routines
local
l_node: CMS_NODE
do
storage.save_user (default_user)
storage.new_user (default_user)
across 1 |..| 10 as c loop
l_node := custom_node ("Content_" + c.item.out, "Summary_" + c.item.out, "Title_" + c.item.out)
l_node.set_author (storage.user_by_email (default_user.email))
storage.save_node (l_node)
storage.new_node (l_node)
end
assert ("Not exist node id: 12", storage.node (12) = Void)
assert ("Not exist node id: 12", storage.node_by_id (12) = Void)
end
test_node
local
l_node: CMS_NODE
do
storage.save_user (default_user)
storage.new_user (default_user)
across 1 |..| 10 as c loop
l_node := custom_node ("Content_" + c.item.out, "Summary_" + c.item.out, "Title_" + c.item.out)
l_node.set_author (storage.user_by_email (default_user.email))
storage.save_node (l_node)
storage.new_node (l_node)
end
assert ("Node id: 10", attached storage.node (10) as ll_node and then ll_node.title ~ "Title_10" )
assert ("Node id: 10", attached storage.node_by_id (10) as ll_node and then ll_node.title ~ "Title_10" )
end
test_update_node
@@ -234,17 +234,18 @@ feature -- Test routines
l_node: CMS_NODE
do
l_node := custom_node ("Content", "Summary", "Title")
storage.save_user (default_user)
storage.new_user (default_user)
l_node.set_author (storage.user_by_email (default_user.email))
storage.save_node (l_node)
if attached {CMS_NODE} storage.node (1) as ll_node then
storage.new_node (l_node)
if attached {CMS_NODE} storage.node_by_id (1) as ll_node then
l_node := ll_node.twin
l_node.set_content ("New Content")
l_node.set_summary ("New Summary")
l_node.set_title("New Title")
if attached storage.user_by_email (default_user.email) as l_user then
storage.update_node (l_user.id,l_node)
assert ("Updated", attached {CMS_NODE} storage.node (1) as u_node and then not (u_node.title ~ ll_node.title) and then not (u_node.content ~ ll_node.content) and then not (u_node.summary ~ ll_node.summary))
l_node.set_author (l_user)
storage.update_node (l_node)
assert ("Updated", attached {CMS_NODE} storage.node_by_id (1) as u_node and then not (u_node.title ~ ll_node.title) and then not (u_node.content ~ ll_node.content) and then not (u_node.summary ~ ll_node.summary))
end
end
end
@@ -254,13 +255,13 @@ feature -- Test routines
l_node: CMS_NODE
do
l_node := custom_node ("Content", "Summary", "Title")
storage.save_user (default_user)
storage.save_user (custom_user ("u2", "p2", "e2"))
storage.new_user (default_user)
storage.new_user (custom_user ("u2", "p2", "e2"))
l_node.set_author (storage.user_by_email (default_user.email))
storage.save_node (l_node)
if attached {CMS_NODE} storage.node (1) as ll_node then
storage.new_node (l_node)
if attached {CMS_NODE} storage.node_by_id (1) as ll_node then
storage.update_node_title (2,ll_node.id, "New Title")
assert ("Updated", attached {CMS_NODE} storage.node (1) as u_node and then not (u_node.title ~ ll_node.title) and then u_node.content ~ ll_node.content and then u_node.summary ~ ll_node.summary)
assert ("Updated", attached {CMS_NODE} storage.node_by_id (1) as u_node and then not (u_node.title ~ ll_node.title) and then u_node.content ~ ll_node.content and then u_node.summary ~ ll_node.summary)
end
end
@@ -269,13 +270,13 @@ feature -- Test routines
l_node: CMS_NODE
do
l_node := custom_node ("Content", "Summary", "Title")
storage.save_user (default_user)
storage.save_user (custom_user ("u2", "p2", "e2"))
storage.new_user (default_user)
storage.new_user (custom_user ("u2", "p2", "e2"))
l_node.set_author (storage.user_by_email (default_user.email))
storage.save_node (l_node)
if attached {CMS_NODE} storage.node (1) as ll_node then
storage.new_node (l_node)
if attached {CMS_NODE} storage.node_by_id (1) as ll_node then
storage.update_node_summary (2,ll_node.id, "New Summary")
assert ("Updated", attached {CMS_NODE} storage.node (1) as u_node and then u_node.title ~ ll_node.title and then u_node.content ~ ll_node.content and then not (u_node.summary ~ ll_node.summary))
assert ("Updated", attached {CMS_NODE} storage.node_by_id (1) as u_node and then u_node.title ~ ll_node.title and then u_node.content ~ ll_node.content and then not (u_node.summary ~ ll_node.summary))
end
end
@@ -284,13 +285,13 @@ feature -- Test routines
l_node: CMS_NODE
do
l_node := custom_node ("Content", "Summary", "Title")
storage.save_user (default_user)
storage.save_user (custom_user ("u2", "p2", "e2"))
storage.new_user (default_user)
storage.new_user (custom_user ("u2", "p2", "e2"))
l_node.set_author (storage.user_by_email (default_user.email))
storage.save_node (l_node)
if attached {CMS_NODE} storage.node (1) as ll_node then
storage.new_node (l_node)
if attached {CMS_NODE} storage.node_by_id (1) as ll_node then
storage.update_node_content (2,ll_node.id, "New Content")
assert ("Updated", attached {CMS_NODE} storage.node (1) as u_node and then u_node.title ~ ll_node.title and then not (u_node.content ~ ll_node.content) and then u_node.summary ~ ll_node.summary)
assert ("Updated", attached {CMS_NODE} storage.node_by_id (1) as u_node and then u_node.title ~ ll_node.title and then not (u_node.content ~ ll_node.content) and then u_node.summary ~ ll_node.summary)
end
end
@@ -300,12 +301,12 @@ feature -- Test routines
l_node: CMS_NODE
do
l_node := custom_node ("Content", "Summary", "Title")
storage.save_user (default_user)
storage.new_user (default_user)
l_node.set_author (storage.user_by_email (default_user.email))
storage.save_node (l_node)
if attached {CMS_NODE} storage.node (1) as ll_node then
storage.new_node (l_node)
if attached {CMS_NODE} storage.node_by_id (1) as ll_node then
storage.update_node_title (1,ll_node.id, "New Title")
assert ("Updated", attached {CMS_NODE} storage.node (1) as u_node and then not (u_node.title ~ ll_node.title) and then u_node.content ~ ll_node.content and then u_node.summary ~ ll_node.summary)
assert ("Updated", attached {CMS_NODE} storage.node_by_id (1) as u_node and then not (u_node.title ~ ll_node.title) and then u_node.content ~ ll_node.content and then u_node.summary ~ ll_node.summary)
end
end
@@ -314,12 +315,12 @@ feature -- Test routines
l_node: CMS_NODE
do
l_node := custom_node ("Content", "Summary", "Title")
storage.save_user (default_user)
storage.new_user (default_user)
l_node.set_author (storage.user_by_email (default_user.email))
storage.save_node (l_node)
if attached {CMS_NODE} storage.node (1) as ll_node then
storage.new_node (l_node)
if attached {CMS_NODE} storage.node_by_id (1) as ll_node then
storage.update_node_summary (1,ll_node.id, "New Summary")
assert ("Updated", attached {CMS_NODE} storage.node (1) as u_node and then u_node.title ~ ll_node.title and then u_node.content ~ ll_node.content and then not (u_node.summary ~ ll_node.summary))
assert ("Updated", attached {CMS_NODE} storage.node_by_id (1) as u_node and then u_node.title ~ ll_node.title and then u_node.content ~ ll_node.content and then not (u_node.summary ~ ll_node.summary))
end
end
@@ -328,12 +329,12 @@ feature -- Test routines
l_node: CMS_NODE
do
l_node := custom_node ("Content", "Summary", "Title")
storage.save_user (default_user)
storage.new_user (default_user)
l_node.set_author (storage.user_by_email (default_user.email))
storage.save_node (l_node)
if attached {CMS_NODE} storage.node (1) as ll_node then
storage.new_node (l_node)
if attached {CMS_NODE} storage.node_by_id (1) as ll_node then
storage.update_node_content (1,ll_node.id, "New Content")
assert ("Updated", attached {CMS_NODE} storage.node (1) as u_node and then u_node.title ~ ll_node.title and then not (u_node.content ~ ll_node.content) and then u_node.summary ~ ll_node.summary)
assert ("Updated", attached {CMS_NODE} storage.node_by_id (1) as u_node and then u_node.title ~ ll_node.title and then not (u_node.content ~ ll_node.content) and then u_node.summary ~ ll_node.summary)
end
end
@@ -342,52 +343,16 @@ feature -- Test routines
l_node: CMS_NODE
l_user: like {CMS_NODE}.author
do
storage.save_user (custom_user ("test_delete", "testu", "email"))
storage.new_user (custom_user ("test_delete", "testu", "email"))
l_user := storage.user_by_name ("test_delete")
across 1 |..| 10 as c loop
l_node := custom_node ("Content_" + c.item.out, "Summary_" + c.item.out, "Title_" + c.item.out)
l_node.set_author (l_user)
storage.save_node (l_node)
storage.new_node (l_node)
end
assert ("Exist node id: 10", attached storage.node (10) as ll_node and then ll_node.title ~ "Title_10" )
storage.delete_node (10)
assert ("Not exist node id: 10", storage.node (10) = Void)
end
feature {NONE} -- Implementation
storage: CMS_STORAGE
-- Storage
once
create {CMS_STORAGE_MYSQL}Result.make (connection)
end
feature {NONE} -- Fixture Factory: Users
default_user: CMS_USER
do
Result := custom_user ("test", "password", "test@test.com")
end
custom_user (a_name, a_password, a_email: READABLE_STRING_32): CMS_USER
do
create Result.make (a_name)
Result.set_password (a_password)
Result.set_email (a_email)
end
feature {NONE} -- Fixture Factories: Nodes
default_node: CMS_NODE
do
Result := custom_node ("Default content", "default summary", "Default")
end
custom_node (a_content, a_summary, a_title: READABLE_STRING_32): CMS_NODE
do
create Result.make (a_content, a_summary, a_title)
assert ("Exist node id: 10", attached storage.node_by_id (10) as ll_node and then ll_node.title ~ "Title_10" )
storage.delete_node_by_id (10)
assert ("Not exist node id: 10", storage.node_by_id (10) = Void)
end
end

View File

@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<system xmlns="http://www.eiffel.com/developers/xml/configuration-1-13-0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.eiffel.com/developers/xml/configuration-1-13-0 http://www.eiffel.com/developers/xml/configuration-1-13-0.xsd" name="tests">
<system xmlns="http://www.eiffel.com/developers/xml/configuration-1-13-0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.eiffel.com/developers/xml/configuration-1-13-0 http://www.eiffel.com/developers/xml/configuration-1-13-0.xsd" name="tests" uuid="FCC2264E-784F-4ACF-9262-E348904FDBA5">
<target name="tests">
<root class="APPLICATION" feature="make"/>
<option warning="true" void_safety="conformance">
@@ -7,11 +7,12 @@
</option>
<setting name="concurrency" value="thread"/>
<library name="base" location="$ISE_LIBRARY\library\base\base-safe.ecf"/>
<library name="model" location="..\..\..\..\model\cms_model-safe.ecf"/>
<library name="cms" location="..\..\..\..\..\cms-safe.ecf" readonly="false"/>
<library name="crypto" location="$ISE_LIBRARY\unstable\library\text\encryption\crypto\crypto-safe.ecf"/>
<library name="model" location="..\..\..\..\model\cms_model-safe.ecf"/>
<library name="persitence_mysql" location="..\persistence_mysql-safe.ecf" readonly="false"/>
<library name="testing" location="$ISE_LIBRARY\library\testing\testing-safe.ecf"/>
<library name="process" location="$ISE_LIBRARY\library\process\process-safe.ecf"/>
<library name="testing" location="$ISE_LIBRARY\library\testing\testing-safe.ecf"/>
<cluster name="tests" location=".\" recursive="true">
<file_rule>
<exclude>/EIFGENs$</exclude>

View File

@@ -3,8 +3,8 @@ note
Eiffel tests that can be executed by testing tool.
]"
author: "EiffelStudio test wizard"
date: "$Date$"
revision: "$Revision$"
date: "$Date: 2015-01-27 19:15:02 +0100 (mar., 27 janv. 2015) $"
revision: "$Revision: 96542 $"
testing: "type/manual"
class
@@ -30,7 +30,7 @@ feature {NONE} -- Events
on_prepare
-- <Precursor>
do
(create {CLEAN_DB}).clean_db(connection)
(create {CLEAN_DB}).clean_db (connection)
end
on_clean
@@ -43,55 +43,45 @@ feature -- Test routines
test_user_rollback
note
testing: "execution/isolated"
local
u: detachable CMS_USER
do
connection.begin_transaction
user_provider.new_user ("test", "test","test@admin.com")
assert ("Has user:", user_provider.has_user)
connection.rollback
assert ("Not has user:", not user_provider.has_user)
u := storage.user_by_name ("test")
if u = Void then
u := custom_user ("test", "test","test@admin.com")
storage.new_user (u)
end
assert ("Has user:", storage.has_user)
u.set_email ("test@example.com")
storage.sql_begin_transaction
storage.update_user (u)
assert ("Has user:", storage.user_by_email ("test@example.com") /= Void)
storage.sql_rollback_transaction
assert ("Not has user:", storage.user_by_email ("test@example.com") = Void)
end
test_user_node_rollback
note
testing: "execution/isolated"
local
u: detachable CMS_USER
do
u := storage.user_by_name ("test")
if u = Void then
u := custom_user ("test", "test","test@admin.com")
storage.new_user (u)
end
connection.begin_transaction
user_provider.new_user ("test", "test","test@admin.com")
assert ("Has user:", user_provider.has_user)
node_provider.new_node (default_node)
node_provider.add_author (1, 1)
assert ("Has one node:", node_provider.count = 1)
u.set_email ("test@example.com")
assert ("Has user:", storage.user_by_email ("test@example.com") /= Void)
storage.new_node (default_node)
assert ("Has one node:", storage.nodes_count = 1)
connection.rollback
assert ("Not has user:", not user_provider.has_user)
assert ("Not has nodes:", node_provider.count = 0)
assert ("Not has user:", storage.user_by_email ("test@example.com") = Void)
assert ("Has no node:", storage.nodes_count = 0)
end
feature {NONE} -- Implementation
node_provider: NODE_DATA_PROVIDER
-- node provider.
once
create Result.make (connection)
end
user_provider: USER_DATA_PROVIDER
-- user provider.
once
create Result.make (connection)
end
feature {NONE} -- Implementation Fixture Factories
default_node: CMS_NODE
do
Result := custom_node ("Default content", "default summary", "Default")
end
custom_node (a_content, a_summary, a_title: READABLE_STRING_32): CMS_NODE
do
create Result.make (a_content, a_summary, a_title)
end
end

View File

@@ -3,8 +3,8 @@ note
Eiffel tests that can be executed by testing tool.
]"
author: "EiffelStudio test wizard"
date: "$Date$"
revision: "$Revision$"
date: "$Date: 2015-01-27 19:15:02 +0100 (mar., 27 janv. 2015) $"
revision: "$Revision: 96542 $"
testing:"execution/isolated"
class
@@ -30,7 +30,7 @@ feature {NONE} -- Events
-- <Precursor>
do
(create {CLEAN_DB}).clean_db(connection)
user_provider.new_user ("admin", "admin","admin@admin.com")
storage.new_user (custom_user ("admin", "admin","admin@admin.com"))
end
on_clean
@@ -44,78 +44,67 @@ feature -- Test routines
test_user_exist
-- User admin exist
do
assert ("Not void", attached user_provider.user_by_email ("admin@admin.com"))
assert ("Not void", attached user_provider.user (1))
assert ("Not void", attached user_provider.user_by_name ("admin"))
assert ("Not void", attached storage.user_by_email ("admin@admin.com"))
assert ("Not void", attached storage.user_by_id (1))
assert ("Not void", attached storage.user_by_name ("admin"))
end
test_user_not_exist
-- Uset test does not exist.
do
assert ("User by email: Void", user_provider.user_by_email ("test1@test.com") = Void)
assert ("User by id: Void", user_provider.user(5) = Void )
assert ("User by name: Void", user_provider.user_by_name ("test1") = Void)
assert ("User by email: Void", storage.user_by_email ("test1@test.com") = Void)
assert ("User by id: Void", storage.user_by_id (5) = Void )
assert ("User by name: Void", storage.user_by_name ("test1") = Void)
end
test_new_user
do
user_provider.new_user ("test", "test","test@admin.com")
assert ("Not void", attached user_provider.user_by_email ("test@admin.com"))
assert ("Not void", attached user_provider.user (2))
assert ("Not void", attached user_provider.user (2) as l_user and then l_user.id = 2 and then l_user.name ~ "test")
assert ("Not void", attached user_provider.user_by_name ("test"))
end
test_new_user_with_roles
do
user_provider.new_user ("test", "test","test@admin.com")
role_provider.new_role ("Admin")
assert ("Empty roles for given user", user_provider.user_roles (1).after)
user_provider.add_role (1, 1)
assert ("Not empty roles for given user", not user_provider.user_roles (1).after)
end
test_new_user_without_profile
do
user_provider.new_user ("test", "test","test@admin.com")
assert ("Empty", user_provider.user_profile (1).new_cursor.after)
end
test_new_user_with_profile
local
l_profile: CMS_USER_PROFILE
l_db_profile: CMS_USER_PROFILE
u: CMS_USER
do
user_provider.new_user ("test", "test","test@admin.com")
if attached {CMS_USER} user_provider.user_by_name ("test") as l_user then
assert ("Empty", user_provider.user_profile (l_user.id).new_cursor.after)
create l_profile.make
l_profile.force ("Eiffel", "language")
l_profile.force ("Argentina", "country")
l_profile.force ("GMT-3", "time zone")
user_provider.save_profile (l_user.id, l_profile)
l_db_profile := user_provider.user_profile (l_user.id)
assert ("Not Empty", not l_db_profile.new_cursor.after)
assert ("Expected language Eiffel", attached l_db_profile.item ("language") as l_language and then l_language ~ "Eiffel")
assert ("Expected time zone GMT-3", attached l_db_profile.item ("time zone") as l_language and then l_language ~ "GMT-3")
end
u := default_user
storage.new_user (u)
assert ("Not void", attached storage.user_by_email (u.email))
assert ("Not void", attached storage.user_by_id (2))
assert ("Not void", attached storage.user_by_id (2) as l_user and then l_user.id = 2 and then l_user.name ~ u.name)
assert ("Not void", attached storage.user_by_name (u.name))
end
-- test_new_user_with_roles
-- do
-- storage.new_user (default_user)
-- storage.new_role ("Admin")
-- assert ("Empty roles for given user", storage.user_roles (1).after)
-- storage.add_role (1, 1)
-- assert ("Not empty roles for given user", not storage.user_roles (1).after)
-- end
feature {NONE} -- Implementation
-- test_new_user_without_profile
-- do
-- storage.new_user ("test", "test","test@admin.com")
-- assert ("Empty", storage.user_profile (1).new_cursor.after)
-- end
user_provider: USER_DATA_PROVIDER
-- user provider.
once
create Result.make (connection)
end
-- test_new_user_with_profile
-- local
-- l_profile: CMS_USER_PROFILE
-- l_db_profile: CMS_USER_PROFILE
-- do
-- storage.new_user (default_user)
-- if attached {CMS_USER} storage.user_by_name ("test") as l_user then
-- assert ("Empty", storage.user_profile (l_user.id).new_cursor.after)
-- create l_profile.make
-- l_profile.force ("Eiffel", "language")
-- l_profile.force ("Argentina", "country")
-- l_profile.force ("GMT-3", "time zone")
-- storage.save_profile (l_user.id, l_profile)
-- l_db_profile := storage.user_profile (l_user.id)
-- assert ("Not Empty", not l_db_profile.new_cursor.after)
-- assert ("Expected language Eiffel", attached l_db_profile.item ("language") as l_language and then l_language ~ "Eiffel")
-- assert ("Expected time zone GMT-3", attached l_db_profile.item ("time zone") as l_language and then l_language ~ "GMT-3")
-- end
-- end
role_provider: ROLE_DATA_PROVIDER
-- user provider.
once
create Result.make (connection)
end
end

View File

@@ -1,7 +1,7 @@
note
description: "Summary description for {ABSTRACT_DB_TEST}."
date: "$Date$"
revision: "$Revision$"
date: "$Date: 2015-01-27 19:15:02 +0100 (mar., 27 janv. 2015) $"
revision: "$Revision: 96542 $"
class
ABSTRACT_DB_TEST
@@ -14,4 +14,35 @@ feature -- Database connection
once
create Result.login_with_schema ("cms_dev", "root", "")
end
storage: CMS_STORAGE_MYSQL
once
create Result.make (connection)
end
feature {NONE} -- Fixture Factory: Users
default_user: CMS_USER
do
Result := custom_user ("test", "password", "test@test.com")
end
custom_user (a_name, a_password: READABLE_STRING_32; a_email: READABLE_STRING_8): CMS_USER
do
create Result.make (a_name)
Result.set_password (a_password)
Result.set_email (a_email)
end
feature {NONE} -- Fixture Factories: Nodes
default_node: CMS_NODE
do
Result := custom_node ("Default content", "default summary", "Default")
end
custom_node (a_content, a_summary, a_title: READABLE_STRING_32): CMS_NODE
do
create Result.make (a_content, a_summary, a_title)
end
end