Skip to content

Commit

Permalink
fix the testsuite
Browse files Browse the repository at this point in the history
  • Loading branch information
FinalAngel committed Sep 9, 2016
1 parent 8e2cd53 commit ac1fb28
Show file tree
Hide file tree
Showing 5 changed files with 125 additions and 50 deletions.
4 changes: 2 additions & 2 deletions djangocms_link/migrations/0010_adapted_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class Migration(migrations.Migration):
migrations.AlterField(
model_name='link',
name='external_link',
field=models.URLField(blank=True, max_length=2040, null=True, verbose_name='External link', validators=[djangocms_link.validators.IntranetURLValidator(intranet_host_re=None)]),
field=models.URLField(blank=True, max_length=2040, null=True, verbose_name='External link', help_text='Provide a valid url to an external website.', validators=[djangocms_link.validators.IntranetURLValidator(intranet_host_re=None)]),
),
migrations.AlterField(
model_name='link',
Expand All @@ -67,6 +67,6 @@ class Migration(migrations.Migration):
migrations.AlterField(
model_name='link',
name='target',
field=models.CharField(blank=True, max_length=255, verbose_name='Target', choices=[('_blank', 'Open in new window.'), ('_self', 'Open in same window.'), ('_parent', 'Delegate to parent.'), ('_top', 'Delegate to top.')]),
field=models.CharField(blank=True, max_length=255, verbose_name='Target', choices=[('_blank', 'Open in new window'), ('_self', 'Open in same window'), ('_parent', 'Delegate to parent'), ('_top', 'Delegate to top')]),
),
]
18 changes: 5 additions & 13 deletions djangocms_link/templates/djangocms_link/default/link.html
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
{% load cms_tags %}
{% load cms_tags %}{% spaceless %}

<a href="{{ link }}"
{% if target %} target="{{ instance.target }}"{% endif %}
{{ instance.attributes_str }}
>
{% for plugin in instance.child_plugin_instances %}
{% render_plugin plugin %}
{% empty %}
{{ instance.name }}
{% endfor %}
</a>
{# this needs to be in one line for rendering purpose #}
{% endspaceless %}<a href="{{ link }}"{% if target %} target="{{ instance.target }}"{% endif %}{% if instance.attributes %} {{ instance.attributes_str }}{% endif %}>{% for plugin in instance.child_plugin_instances %}{% render_plugin plugin %}{% empty %}{{ instance.name }}{% endfor %}</a>{% spaceless %}

{% comment %}
{% endspaceless %}{% comment %}
# https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a
{{ instance.name }}
{{ link }} or {{ instance.get_link }} summarizes:
Expand All @@ -22,4 +14,4 @@
{{ instance.phone }}
{{ instance.target }}
{{ instance.attributes_str }}
{% endcomment %}
{% endcomment %}
1 change: 1 addition & 0 deletions tests/requirements.txt
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
1 change: 1 addition & 0 deletions tests/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
HELPER_SETTINGS = {
'INSTALLED_APPS': [
'django_select2',
'djangocms_text_ckeditor',
],
'ALLOWED_HOSTS': ['localhost'],
'CMS_LANGUAGES': {
Expand Down
151 changes: 116 additions & 35 deletions tests/tests_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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):
"""
Expand Down

0 comments on commit ac1fb28

Please sign in to comment.