forked from django-cms/djangocms-link
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8e2cd53
commit ac1fb28
Showing
5 changed files
with
125 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
# requirements from setup.py | ||
django-select2>=4.3,<5.0 | ||
# other requirements | ||
djangocms-text-ckeditor | ||
djangocms-helper>=0.9.2,<0.10 | ||
tox | ||
coverage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,6 @@ | |
import django | ||
|
||
from django.core.management import call_command | ||
from django.utils import unittest | ||
from django.utils.encoding import force_text | ||
from django.utils.six import StringIO | ||
|
||
|
@@ -16,54 +15,136 @@ class LinkTestCase(BaseTestCase): | |
|
||
def test_link(self): | ||
|
||
page = create_page(title='hellp', template='page.html', language='en') | ||
|
||
plugin = add_plugin(page.placeholders.get(slot='content'), 'LinkPlugin', 'en', url='http://example.com') | ||
self.assertEqual(plugin.link(), 'http://example.com') | ||
|
||
plugin = add_plugin(page.placeholders.get(slot='content'), 'LinkPlugin', 'en', url='http://example.com', anchor='some-h1') | ||
self.assertEqual(plugin.link(), 'http://example.com#some-h1') | ||
|
||
plugin = add_plugin(page.placeholders.get(slot='content'), 'LinkPlugin', 'en', url='http://example.com', phone='555-123-555') | ||
self.assertEqual(plugin.link(), 'tel:555-123-555') | ||
|
||
plugin = add_plugin(page.placeholders.get(slot='content'), 'LinkPlugin', 'en', url='http://example.com', mailto='[email protected]') | ||
self.assertEqual(plugin.link(), 'mailto:[email protected]') | ||
|
||
plugin = add_plugin(page.placeholders.get(slot='content'), 'LinkPlugin', 'en', url='http://example.com', internal_link=page) | ||
self.assertEqual(plugin.link(), 'http://example.com') | ||
|
||
plugin = add_plugin(page.placeholders.get(slot='content'), 'LinkPlugin', 'en', internal_link=page) | ||
self.assertEqual(plugin.link(), '/en/') | ||
|
||
plugin = add_plugin(page.placeholders.get(slot='content'), 'LinkPlugin', 'en', internal_link=page, anchor='some-h1') | ||
self.assertEqual(plugin.link(), '/en/#some-h1') | ||
|
||
plugin = add_plugin(page.placeholders.get(slot='content'), 'LinkPlugin', 'en', name='some text') | ||
self.assertEqual(plugin.link(), '') | ||
page = create_page( | ||
title='help', | ||
template='page.html', | ||
language='en', | ||
) | ||
|
||
plugin = add_plugin( | ||
page.placeholders.get(slot='content'), | ||
'LinkPlugin', | ||
'en', | ||
external_link='http://example.com' | ||
) | ||
self.assertEqual(plugin.get_link(), 'http://example.com') | ||
|
||
plugin = add_plugin( | ||
page.placeholders.get(slot='content'), | ||
'LinkPlugin', | ||
'en', | ||
external_link='http://example.com', | ||
anchor='some-h1', | ||
) | ||
self.assertEqual(plugin.get_link(), 'http://example.com#some-h1') | ||
|
||
plugin = add_plugin( | ||
page.placeholders.get(slot='content'), | ||
'LinkPlugin', | ||
'en', | ||
external_link='http://example.com', | ||
phone='555-123-555', | ||
) | ||
self.assertEqual(plugin.get_link(), 'tel:555-123-555') | ||
|
||
plugin = add_plugin( | ||
page.placeholders.get(slot='content'), | ||
'LinkPlugin', | ||
'en', | ||
external_link='http://example.com', | ||
mailto='[email protected]', | ||
) | ||
self.assertEqual(plugin.get_link(), 'mailto:[email protected]') | ||
|
||
plugin = add_plugin( | ||
page.placeholders.get(slot='content'), | ||
'LinkPlugin', | ||
'en', | ||
internal_link=page, | ||
external_link='http://example.com', | ||
) | ||
self.assertEqual(plugin.get_link(), 'http://example.com') | ||
|
||
plugin = add_plugin( | ||
page.placeholders.get(slot='content'), | ||
'LinkPlugin', | ||
'en', | ||
internal_link=page, | ||
) | ||
self.assertEqual(plugin.get_link(), '/en/') | ||
|
||
plugin = add_plugin( | ||
page.placeholders.get(slot='content'), | ||
'LinkPlugin', | ||
'en', | ||
internal_link=page, | ||
anchor='some-h1', | ||
) | ||
self.assertEqual(plugin.get_link(), '/en/#some-h1') | ||
|
||
plugin = add_plugin( | ||
page.placeholders.get(slot='content'), | ||
'LinkPlugin', | ||
'en', | ||
name='some text', | ||
) | ||
self.assertEqual(plugin.get_link(), '') | ||
self.assertEqual(force_text(plugin), 'some text') | ||
|
||
def test_render(self): | ||
|
||
page = create_page(title='hellp', template='page.html', language='en') | ||
page = create_page( | ||
title='help', | ||
template='page.html', | ||
language='en', | ||
) | ||
request = self.get_request(page, 'en') | ||
|
||
plugin = add_plugin(page.placeholders.get(slot='content'), 'LinkPlugin', 'en', url='http://example.com', name='some text') | ||
context = PluginContext({'request': request}, plugin, page.placeholders.get(slot='content')) | ||
output = render_placeholder(page.placeholders.get(slot='content'), context, editable=False) | ||
plugin = add_plugin( | ||
page.placeholders.get(slot='content'), | ||
'LinkPlugin', | ||
'en', | ||
external_link='http://example.com', | ||
name='some text', | ||
) | ||
context = PluginContext( | ||
{'request': request}, | ||
plugin, | ||
page.placeholders.get(slot='content'), | ||
) | ||
output = render_placeholder( | ||
page.placeholders.get(slot='content'), | ||
context, | ||
editable=False, | ||
) | ||
|
||
# there should never be trailing or leading whitespace from the link. | ||
# when rendered, it counts as a space in html, which leads to incorrect rendering | ||
self.assertEqual(output, '<a href="http://example.com" >some text</a>') | ||
self.assertEqual(output, '<a href="http://example.com">some text</a>') | ||
plugin.delete() | ||
|
||
plugin = add_plugin(page.placeholders.get(slot='content'), 'LinkPlugin', 'en', url='http://example.com') | ||
add_plugin(page.placeholders.get(slot='content'), 'TextPlugin', 'en', body='text body', target=plugin) | ||
output = render_placeholder(page.placeholders.get(slot='content'), context, editable=False) | ||
plugin = add_plugin( | ||
page.placeholders.get(slot='content'), | ||
'LinkPlugin', | ||
'en', | ||
external_link='http://example.com', | ||
) | ||
add_plugin( | ||
page.placeholders.get(slot='content'), | ||
'TextPlugin', | ||
'en', | ||
body='text body', | ||
target=plugin, | ||
) | ||
output = render_placeholder( | ||
page.placeholders.get(slot='content'), | ||
context, | ||
editable=False, | ||
) | ||
|
||
# there should never be trailing or leading whitespace from the link. | ||
# when rendered, it counts as a space in html, which leads to incorrect rendering | ||
self.assertEqual(output, '<span class="plugin_link"><a href="http://example.com" >text body</a></span>') | ||
self.assertEqual(output, '<a href="http://example.com">text body</a>') | ||
|
||
def test_makemigrations(self): | ||
""" | ||
|