2013-01-04 14:28:55 +00:00
|
|
|
# encoding: utf-8
|
|
|
|
require 'test_helper'
|
2014-05-27 13:22:21 +00:00
|
|
|
|
2013-01-04 14:28:55 +00:00
|
|
|
class NotificationFactoryTest < ActiveSupport::TestCase
|
2014-12-28 13:02:23 +00:00
|
|
|
test 'notifications base' do
|
2014-05-27 13:22:21 +00:00
|
|
|
ticket = Ticket.create(
|
2014-12-28 13:02:23 +00:00
|
|
|
:title => 'some title äöüß',
|
|
|
|
:group => Group.lookup( :name => 'Users'),
|
|
|
|
:customer_id => 2,
|
|
|
|
:state => Ticket::State.lookup( :name => 'new' ),
|
|
|
|
:priority => Ticket::Priority.lookup( :name => '2 normal' ),
|
2015-01-02 22:34:37 +00:00
|
|
|
:updated_by_id => 2,
|
|
|
|
:created_by_id => 2,
|
2014-12-28 13:02:23 +00:00
|
|
|
)
|
|
|
|
article_plain = Ticket::Article.create(
|
|
|
|
:ticket_id => ticket.id,
|
|
|
|
:type_id => Ticket::Article::Type.where(:name => 'phone' ).first.id,
|
|
|
|
:sender_id => Ticket::Article::Sender.where(:name => 'Customer' ).first.id,
|
|
|
|
:from => 'Zammad Feedback <feedback@example.org>',
|
|
|
|
:body => 'some text',
|
|
|
|
:internal => false,
|
|
|
|
:updated_by_id => 1,
|
|
|
|
:created_by_id => 1,
|
2014-05-27 13:22:21 +00:00
|
|
|
)
|
2013-01-04 14:28:55 +00:00
|
|
|
tests = [
|
|
|
|
{
|
|
|
|
:locale => 'en',
|
|
|
|
:string => 'Hi #{recipient.firstname},',
|
|
|
|
:result => 'Hi Nicole,',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
:locale => 'de',
|
|
|
|
:string => 'Hi #{recipient.firstname},',
|
|
|
|
:result => 'Hi Nicole,',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
:locale => 'de',
|
|
|
|
:string => 'Hi #{recipient.firstname}, Group: #{ticket.group.name}',
|
|
|
|
:result => 'Hi Nicole, Group: Users',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
:locale => 'de',
|
|
|
|
:string => '#{config.http_type} some text',
|
|
|
|
:result => 'http some text',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
:locale => 'de',
|
2014-10-19 18:26:01 +00:00
|
|
|
:string => 'i18n(New) some text',
|
2013-01-04 14:28:55 +00:00
|
|
|
:result => 'Neu some text',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
:locale => 'de',
|
2014-06-08 22:01:20 +00:00
|
|
|
:string => '\'i18n(#{ticket.state.name})\' ticket state',
|
2013-01-04 14:28:55 +00:00
|
|
|
:result => '\'neu\' ticket state',
|
|
|
|
},
|
2015-01-02 22:34:37 +00:00
|
|
|
{
|
|
|
|
:locale => 'de',
|
|
|
|
:string => 'a #{not_existing_object.test}',
|
|
|
|
:result => 'a #{not_existing_object / no such object}',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
:locale => 'de',
|
|
|
|
:string => 'a #{ticket.level1}',
|
|
|
|
:result => 'a #{ticket.level1 / no such method}',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
:locale => 'de',
|
|
|
|
:string => 'a #{ticket.level1.level2}',
|
|
|
|
:result => 'a #{ticket.level1 / no such method}',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
:locale => 'de',
|
|
|
|
:string => 'a #{ticket.title.level2}',
|
|
|
|
:result => 'a #{ticket.title.level2 / no such method}',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
:locale => 'de',
|
|
|
|
:string => 'by #{ticket.updated_by.fullname}',
|
|
|
|
:result => 'by Nicole Braun',
|
|
|
|
},
|
2014-12-28 13:02:23 +00:00
|
|
|
{
|
|
|
|
:locale => 'de',
|
|
|
|
:string => 'Subject #{article.from}, Group: #{ticket.group.name}',
|
|
|
|
:result => 'Subject Zammad Feedback <feedback@example.org>, Group: Users',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
:locale => 'de',
|
|
|
|
:string => 'Body #{article.body}, Group: #{ticket.group.name}',
|
2015-01-06 14:30:00 +00:00
|
|
|
:result => 'Body some text, Group: Users',
|
2014-12-28 13:02:23 +00:00
|
|
|
},
|
2014-10-19 18:26:01 +00:00
|
|
|
{
|
|
|
|
:locale => 'de',
|
|
|
|
:string => '\#{puts `ls`}',
|
2015-01-02 22:34:37 +00:00
|
|
|
:result => '\#{puts `ls`} (not allowed)',
|
2014-10-19 18:26:01 +00:00
|
|
|
},
|
2013-01-04 14:28:55 +00:00
|
|
|
]
|
|
|
|
tests.each { |test|
|
|
|
|
result = NotificationFactory.build(
|
|
|
|
:string => test[:string],
|
|
|
|
:objects => {
|
2014-05-27 13:22:21 +00:00
|
|
|
:ticket => ticket,
|
2014-12-28 13:02:23 +00:00
|
|
|
:article => article_plain,
|
|
|
|
:recipient => User.find(2),
|
|
|
|
},
|
|
|
|
:locale => test[:locale]
|
|
|
|
)
|
|
|
|
assert_equal( test[:result], result, "verify result" )
|
|
|
|
}
|
|
|
|
|
|
|
|
ticket.destroy
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'notifications html' do
|
|
|
|
ticket = Ticket.create(
|
|
|
|
:title => 'some title <b>äöüß</b> 2',
|
|
|
|
:group => Group.lookup( :name => 'Users'),
|
|
|
|
:customer_id => 2,
|
|
|
|
:state => Ticket::State.lookup( :name => 'new' ),
|
|
|
|
:priority => Ticket::Priority.lookup( :name => '2 normal' ),
|
|
|
|
:updated_by_id => 1,
|
|
|
|
:created_by_id => 1,
|
|
|
|
)
|
|
|
|
article_html = Ticket::Article.create(
|
|
|
|
:ticket_id => ticket.id,
|
|
|
|
:type_id => Ticket::Article::Type.where(:name => 'phone' ).first.id,
|
|
|
|
:sender_id => Ticket::Article::Sender.where(:name => 'Customer' ).first.id,
|
|
|
|
:from => 'Zammad Feedback <feedback@example.org>',
|
|
|
|
:body => 'some <b>text</b><br>next line',
|
|
|
|
:content_type => 'text/html',
|
|
|
|
:internal => false,
|
|
|
|
:updated_by_id => 1,
|
|
|
|
:created_by_id => 1,
|
|
|
|
)
|
|
|
|
tests = [
|
|
|
|
{
|
|
|
|
:locale => 'de',
|
|
|
|
:string => 'Subject #{ticket.title}',
|
|
|
|
:result => 'Subject some title <b>äöüß</b> 2',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
:locale => 'de',
|
|
|
|
:string => 'Subject #{article.from}, Group: #{ticket.group.name}',
|
|
|
|
:result => 'Subject Zammad Feedback <feedback@example.org>, Group: Users',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
:locale => 'de',
|
|
|
|
:string => 'Body #{article.body}, Group: #{ticket.group.name}',
|
2015-01-06 14:30:00 +00:00
|
|
|
:result => 'Body some text
|
|
|
|
next line, Group: Users',
|
2014-12-28 13:02:23 +00:00
|
|
|
},
|
|
|
|
]
|
|
|
|
tests.each { |test|
|
|
|
|
result = NotificationFactory.build(
|
|
|
|
:string => test[:string],
|
|
|
|
:objects => {
|
|
|
|
:ticket => ticket,
|
|
|
|
:article => article_html,
|
|
|
|
:recipient => User.find(2),
|
|
|
|
},
|
|
|
|
:locale => test[:locale]
|
|
|
|
)
|
|
|
|
assert_equal( test[:result], result, "verify result" )
|
|
|
|
}
|
|
|
|
|
|
|
|
ticket.destroy
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'notifications attack' do
|
|
|
|
ticket = Ticket.create(
|
|
|
|
:title => 'some title <b>äöüß</b> 3',
|
|
|
|
:group => Group.lookup( :name => 'Users'),
|
|
|
|
:customer_id => 2,
|
|
|
|
:state => Ticket::State.lookup( :name => 'new' ),
|
|
|
|
:priority => Ticket::Priority.lookup( :name => '2 normal' ),
|
|
|
|
:updated_by_id => 1,
|
|
|
|
:created_by_id => 1,
|
|
|
|
)
|
|
|
|
article_html = Ticket::Article.create(
|
|
|
|
:ticket_id => ticket.id,
|
|
|
|
:type_id => Ticket::Article::Type.where(:name => 'phone' ).first.id,
|
|
|
|
:sender_id => Ticket::Article::Sender.where(:name => 'Customer' ).first.id,
|
|
|
|
:from => 'Zammad Feedback <feedback@example.org>',
|
|
|
|
:body => 'some <b>text</b><br>next line',
|
|
|
|
:content_type => 'text/html',
|
|
|
|
:internal => false,
|
|
|
|
:updated_by_id => 1,
|
|
|
|
:created_by_id => 1,
|
|
|
|
)
|
|
|
|
tests = [
|
|
|
|
{
|
|
|
|
:locale => 'de',
|
|
|
|
:string => '\#{puts `ls`}',
|
2015-01-02 22:34:37 +00:00
|
|
|
:result => '\#{puts `ls`} (not allowed)',
|
2014-12-28 13:02:23 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
:locale => 'de',
|
|
|
|
:string => 'attack#1 #{article.destroy}',
|
2015-01-02 22:34:37 +00:00
|
|
|
:result => 'attack#1 #{article.destroy} (not allowed)',
|
2014-12-28 13:02:23 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
:locale => 'de',
|
|
|
|
:string => 'attack#2 #{Article.where}',
|
2015-01-02 22:34:37 +00:00
|
|
|
:result => 'attack#2 #{Article.where} (not allowed)',
|
2014-12-28 13:02:23 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
:locale => 'de',
|
|
|
|
:string => 'attack#1 #{article.
|
|
|
|
destroy}',
|
|
|
|
:result => 'attack#1 #{article.
|
2015-01-02 22:34:37 +00:00
|
|
|
destroy} (not allowed)',
|
2014-12-28 13:02:23 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
:locale => 'de',
|
|
|
|
:string => 'attack#1 #{article.find}',
|
2015-01-02 22:34:37 +00:00
|
|
|
:result => 'attack#1 #{article.find} (not allowed)',
|
2014-12-28 13:02:23 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
:locale => 'de',
|
2015-01-02 22:34:37 +00:00
|
|
|
:string => 'attack#1 #{article.update(:name => "test")}',
|
|
|
|
:result => 'attack#1 #{article.update(:name => "test")} (not allowed)',
|
2014-12-28 13:02:23 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
:locale => 'de',
|
|
|
|
:string => 'attack#1 #{article.all}',
|
2015-01-02 22:34:37 +00:00
|
|
|
:result => 'attack#1 #{article.all} (not allowed)',
|
2014-12-28 13:02:23 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
:locale => 'de',
|
|
|
|
:string => 'attack#1 #{article.delete}',
|
2015-01-02 22:34:37 +00:00
|
|
|
:result => 'attack#1 #{article.delete} (not allowed)',
|
2014-12-28 13:02:23 +00:00
|
|
|
},
|
|
|
|
]
|
|
|
|
tests.each { |test|
|
|
|
|
result = NotificationFactory.build(
|
|
|
|
:string => test[:string],
|
|
|
|
:objects => {
|
|
|
|
:ticket => ticket,
|
|
|
|
:article => article_html,
|
2013-01-04 14:28:55 +00:00
|
|
|
:recipient => User.find(2),
|
|
|
|
},
|
|
|
|
:locale => test[:locale]
|
|
|
|
)
|
2014-12-28 13:02:23 +00:00
|
|
|
assert_equal( test[:result], result, "verify result" )
|
2013-01-04 14:28:55 +00:00
|
|
|
}
|
2014-05-27 13:22:21 +00:00
|
|
|
|
|
|
|
ticket.destroy
|
2013-01-04 14:28:55 +00:00
|
|
|
end
|
|
|
|
end
|