1
# Copyright (c) 2009 Twisted Matrix Laboratories.
2
# See LICENSE for details.
5
Tests for L{twisted.lore.slides}.
8
from xml.dom.minidom import Element, Text
10
from twisted.trial.unittest import TestCase
11
from twisted.lore.slides import HTMLSlide, splitIntoSlides, insertPrevNextLinks
14
class SlidesTests(TestCase):
16
Tests for functions in L{twisted.lore.slides}.
18
def test_splitIntoSlides(self):
20
L{splitIntoSlides} accepts a document and returns a list of two-tuples,
21
each element of which contains the title of a slide taken from an I{h2}
22
element and the body of that slide.
24
parent = Element('html')
25
body = Element('body')
26
parent.appendChild(body)
30
text.data = 'first slide'
31
first.appendChild(text)
32
body.appendChild(first)
33
body.appendChild(Element('div'))
34
body.appendChild(Element('span'))
36
second = Element('h2')
38
text.data = 'second slide'
39
second.appendChild(text)
40
body.appendChild(second)
41
body.appendChild(Element('p'))
42
body.appendChild(Element('br'))
44
slides = splitIntoSlides(parent)
46
self.assertEqual(slides[0][0], 'first slide')
47
firstContent = slides[0][1]
48
self.assertEqual(firstContent[0].tagName, 'div')
49
self.assertEqual(firstContent[1].tagName, 'span')
50
self.assertEqual(len(firstContent), 2)
52
self.assertEqual(slides[1][0], 'second slide')
53
secondContent = slides[1][1]
54
self.assertEqual(secondContent[0].tagName, 'p')
55
self.assertEqual(secondContent[1].tagName, 'br')
56
self.assertEqual(len(secondContent), 2)
58
self.assertEqual(len(slides), 2)
61
def test_insertPrevNextText(self):
63
L{insertPrevNextLinks} appends a text node with the title of the
64
previous slide to each node with a I{previous} class and the title of
65
the next slide to each node with a I{next} class.
67
next = Element('span')
68
next.setAttribute('class', 'next')
69
container = Element('div')
70
container.appendChild(next)
71
slideWithNext = HTMLSlide(container, 'first', 0)
73
previous = Element('span')
74
previous.setAttribute('class', 'previous')
75
container = Element('div')
76
container.appendChild(previous)
77
slideWithPrevious = HTMLSlide(container, 'second', 1)
80
[slideWithNext, slideWithPrevious], None, None)
83
next.toxml(), '<span class="next">second</span>')
85
previous.toxml(), '<span class="previous">first</span>')