* Copyright (c) 2006, Larry E. Masters Shorewood, IL. 60431 * Author(s): Larry E. Masters aka PhpNut * * Licensed under The Open Group Test Suite License * Redistributions of files must retain the above copyright notice. * * @filesource * @author Larry E. Masters aka PhpNut * @copyright Copyright (c) 2006, Larry E. Masters Shorewood, IL. 60431 * @link http://www.phpnut.com/projects/ * @package test_suite * @subpackage test_suite.cases.app * @since CakePHP Test Suite v 1.0.0.0 * @version $Revision$ * @modifiedby $LastChangedBy$ * @lastmodified $Date$ * @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License */ uses('view'.DS.'helpers'.DS.'app_helper', 'class_registry', 'controller'.DS.'controller', 'model'.DS.'model', 'view'.DS.'helper', 'view'.DS.'helpers'.DS.'html', 'view'.DS.'helpers'.DS.'form'); class TheHtmlTestController extends Controller { var $name = 'TheTest'; var $uses = null; } class HtmlHelperTest extends UnitTestCase { var $html = null; function setUp() { $this->Html =& new HtmlHelper(); $view =& new View(new TheHtmlTestController()); ClassRegistry::addObject('view', $view); } function testLinkEscape() { $result = $this->Html->link('Next >', '#'); $expected = '/^Next ><\/a>$/'; $this->assertPattern($expected, $result); $result = $this->Html->link('Next >', '#', array('escape' => false)); $this->assertPattern('/^Next ><\/a>$/', $result); } function testImageLink() { $result = $this->Html->link($this->Html->image('test.gif'), '#', array(), false, false, false); $this->assertPattern('/^<\/a>$/', $result); } function testStyle() { $result = $this->Html->style(array('display'=> 'none', 'margin'=>'10px')); $expected = 'display:none; margin:10px;'; $this->assertEqual($expected, $result); $result = $this->Html->style(array('display'=> 'none', 'margin'=>'10px'), false); $expected = "display:none;\nmargin:10px;"; $this->assertEqual($expected, $result); } function testCssLink() { $result = $this->Html->css('screen'); $this->assertPattern('/^]+\/>$/', $result); $this->assertPattern('/^]+rel="stylesheet"[^<>]+\/>$/', $result); $this->assertPattern('/^]+type="text\/css"[^<>]+\/>$/', $result); $this->assertPattern('/^]+href=".*css\/screen\.css"[^<>]+\/>$/', $result); $this->assertNoPattern('/^]+[^rel|type|href]=[^<>]*>/', $result); $result = $this->Html->css('screen.css'); $this->assertPattern('/^]+\/>$/', $result); $this->assertPattern('/^]+rel="stylesheet"[^<>]+\/>$/', $result); $this->assertPattern('/^]+type="text\/css"[^<>]+\/>$/', $result); $this->assertPattern('/^]+href=".*css\/screen\.css"[^<>]+\/>$/', $result); $this->assertNoPattern('/^]+[^rel|type|href]=[^<>]*>/', $result); $result = $this->Html->css('screen.css?1234'); $this->assertPattern('/^]+\/>$/', $result); $this->assertPattern('/^]+rel="stylesheet"[^<>]+\/>$/', $result); $this->assertPattern('/^]+type="text\/css"[^<>]+\/>$/', $result); $this->assertPattern('/^]+href=".*css\/screen\.css\?1234"[^<>]+\/>$/', $result); $this->assertNoPattern('/^]+[^rel|type|href]=[^<>]*>/', $result); } function testBreadcrumb() { $this->Html->addCrumb('First', '#first'); $this->Html->addCrumb('Second', '#second'); $this->Html->addCrumb('Third', '#third'); $result = $this->Html->getCrumbs(); $this->assertPattern('/^]+>First<\/a>»]+>Second<\/a>»]+>Third<\/a>$/', $result); $this->assertPattern('/]*>First<\/a>/', $result); $this->assertPattern('/]*>Second<\/a>/', $result); $this->assertPattern('/]*>Third<\/a>/', $result); $this->assertNoPattern('/]+[^href]=[^<>]*>/', $result); $result = $this->Html->getCrumbs(' > '); $this->assertPattern('/^]+>First<\/a> > ]+>Second<\/a> > ]+>Third<\/a>$/', $result); $this->assertPattern('/]*>First<\/a>/', $result); $this->assertPattern('/]*>Second<\/a>/', $result); $this->assertPattern('/]*>Third<\/a>/', $result); $this->assertNoPattern('/]+[^href]=[^<>]*>/', $result); $this->Html->addCrumb('Fourth', null); $result = $this->Html->getCrumbs(); $this->assertPattern('/^]+>First<\/a>»]+>Second<\/a>»]+>Third<\/a>»Fourth$/', $result); $this->assertPattern('/]*>First<\/a>/', $result); $this->assertPattern('/]*>Second<\/a>/', $result); $this->assertPattern('/]*>Third<\/a>/', $result); $this->assertNoPattern('/]+[^href]=[^<>]*>/', $result); } function testNestedList() { $list = array( 'Item 1', 'Item 2' => array( 'Item 2.1' ), 'Item 3', 'Item 4' => array( 'Item 4.1', 'Item 4.2', 'Item 4.3' => array( 'Item 4.3.1', 'Item 4.3.2' ) ), 'Item 5' => array( 'Item 5.1', 'Item 5.2' ) ); $result = $this->Html->nestedList($list); $this->assertPattern('/^
    \s*
  • Item 1<\/li>\s*
  • Item 2.+<\/li>
  • Item 3<\/li>\s*
  • Item 4.+<\/li>
  • Item 5.+<\/li><\/ul>$/', $result); $this->assertPattern('/
  • Item 2\s*
      \s*
    • Item 2.1<\/li>\s*<\/ul>\s*<\/li>/', $result); $this->assertPattern('/
    • Item 4\s*
        \s*
      • Item 4.1<\/li>\s*
      • Item 4.2<\/li>\s*
      • Item 4.3.+<\/li>\s*<\/ul>\s*<\/li>/', $result); $this->assertPattern('/
      • Item 4.3\s*
          \s*
        • Item 4.3.1<\/li>\s*
        • Item 4.3.2<\/li>\s*<\/ul>\s*<\/li>/', $result); $this->assertPattern('/
        • Item 5\s*
            \s*
          • Item 5.1<\/li>\s*
          • Item 5.2<\/li>\s*<\/ul>\s*<\/li>/', $result); $result = $this->Html->nestedList($list, null); $this->assertPattern('/^
              \s*
            • Item 1<\/li>\s*
            • Item 2.+<\/li>
            • Item 3<\/li>\s*
            • Item 4.+<\/li>
            • Item 5.+<\/li><\/ul>$/', $result); $this->assertPattern('/
            • Item 2\s*
                \s*
              • Item 2.1<\/li>\s*<\/ul>\s*<\/li>/', $result); $this->assertPattern('/
              • Item 4\s*
                  \s*
                • Item 4.1<\/li>\s*
                • Item 4.2<\/li>\s*
                • Item 4.3.+<\/li>\s*<\/ul>\s*<\/li>/', $result); $this->assertPattern('/
                • Item 4.3\s*
                    \s*
                  • Item 4.3.1<\/li>\s*
                  • Item 4.3.2<\/li>\s*<\/ul>\s*<\/li>/', $result); $this->assertPattern('/
                  • Item 5\s*
                      \s*
                    • Item 5.1<\/li>\s*
                    • Item 5.2<\/li>\s*<\/ul>\s*<\/li>/', $result); $result = $this->Html->nestedList($list, array(), array(), 'ol'); $this->assertPattern('/^
                        \s*
                      1. Item 1<\/li>\s*
                      2. Item 2.+<\/li>
                      3. Item 3<\/li>\s*
                      4. Item 4.+<\/li>
                      5. Item 5.+<\/li><\/ol>$/', $result); $this->assertPattern('/
                      6. Item 2\s*
                          \s*
                        1. Item 2.1<\/li>\s*<\/ol>\s*<\/li>/', $result); $this->assertPattern('/
                        2. Item 4\s*
                            \s*
                          1. Item 4.1<\/li>\s*
                          2. Item 4.2<\/li>\s*
                          3. Item 4.3.+<\/li>\s*<\/ol>\s*<\/li>/', $result); $this->assertPattern('/
                          4. Item 4.3\s*
                              \s*
                            1. Item 4.3.1<\/li>\s*
                            2. Item 4.3.2<\/li>\s*<\/ol>\s*<\/li>/', $result); $this->assertPattern('/
                            3. Item 5\s*
                                \s*
                              1. Item 5.1<\/li>\s*
                              2. Item 5.2<\/li>\s*<\/ol>\s*<\/li>/', $result); $result = $this->Html->nestedList($list, 'ol'); $this->assertPattern('/^
                                  \s*
                                1. Item 1<\/li>\s*
                                2. Item 2.+<\/li>
                                3. Item 3<\/li>\s*
                                4. Item 4.+<\/li>
                                5. Item 5.+<\/li><\/ol>$/', $result); $this->assertPattern('/
                                6. Item 2\s*
                                    \s*
                                  1. Item 2.1<\/li>\s*<\/ol>\s*<\/li>/', $result); $this->assertPattern('/
                                  2. Item 4\s*
                                      \s*
                                    1. Item 4.1<\/li>\s*
                                    2. Item 4.2<\/li>\s*
                                    3. Item 4.3.+<\/li>\s*<\/ol>\s*<\/li>/', $result); $this->assertPattern('/
                                    4. Item 4.3\s*
                                        \s*
                                      1. Item 4.3.1<\/li>\s*
                                      2. Item 4.3.2<\/li>\s*<\/ol>\s*<\/li>/', $result); $this->assertPattern('/
                                      3. Item 5\s*
                                          \s*
                                        1. Item 5.1<\/li>\s*
                                        2. Item 5.2<\/li>\s*<\/ol>\s*<\/li>/', $result); $result = $this->Html->nestedList($list, array('class'=>'list')); $this->assertPattern('/^]*class="list"[^<>]*>\s*
                                        3. Item 1<\/li>\s*
                                        4. Item 2.+<\/li>
                                        5. Item 3<\/li>\s*
                                        6. Item 4.+<\/li>
                                        7. Item 5.+<\/li><\/ul>$/', $result); $this->assertPattern('/
                                        8. Item 2\s*]*class="list"[^<>]*>\s*
                                        9. Item 2.1<\/li>\s*<\/ul>\s*<\/li>/', $result); $this->assertPattern('/
                                        10. Item 4\s*]*class="list"[^<>]*>\s*
                                        11. Item 4.1<\/li>\s*
                                        12. Item 4.2<\/li>\s*
                                        13. Item 4.3.+<\/li>\s*<\/ul>\s*<\/li>/', $result); $this->assertPattern('/
                                        14. Item 4.3\s*]*class="list"[^<>]*>\s*
                                        15. Item 4.3.1<\/li>\s*
                                        16. Item 4.3.2<\/li>\s*<\/ul>\s*<\/li>/', $result); $this->assertPattern('/
                                        17. Item 5\s*]*class="list"[^<>]*>\s*
                                        18. Item 5.1<\/li>\s*
                                        19. Item 5.2<\/li>\s*<\/ul>\s*<\/li>/', $result); $result = $this->Html->nestedList($list, array(), array('class' => 'item')); $this->assertPattern('/^
                                            \s*]*class="item"[^<>]*>Item 1<\/li>\s*]*class="item"[^<>]*>Item 2.+<\/li>]*class="item"[^<>]*>Item 3<\/li>\s*]*class="item"[^<>]*>Item 4.+<\/li>]*class="item"[^<>]*>Item 5.+<\/li><\/ul>$/', $result); $this->assertPattern('/]*class="item"[^<>]*>Item 2\s*
                                              \s*]*class="item"[^<>]*>Item 2.1<\/li>\s*<\/ul>\s*<\/li>/', $result); $this->assertPattern('/]*class="item"[^<>]*>Item 4\s*
                                                \s*]*class="item"[^<>]*>Item 4.1<\/li>\s*]*class="item"[^<>]*>Item 4.2<\/li>\s*]*class="item"[^<>]*>Item 4.3.+<\/li>\s*<\/ul>\s*<\/li>/', $result); $this->assertPattern('/]*class="item"[^<>]*>Item 4.3\s*
                                                  \s*]*class="item"[^<>]*>Item 4.3.1<\/li>\s*]*class="item"[^<>]*>Item 4.3.2<\/li>\s*<\/ul>\s*<\/li>/', $result); $this->assertPattern('/]*class="item"[^<>]*>Item 5\s*
                                                    \s*]*class="item"[^<>]*>Item 5.1<\/li>\s*]*class="item"[^<>]*>Item 5.2<\/li>\s*<\/ul>\s*<\/li>/', $result); $result = $this->Html->nestedList($list, array(), array('even' => 'even', 'odd' => 'odd')); $this->assertPattern('/^
                                                      \s*]*class="odd"[^<>]*>Item 1<\/li>\s*]*class="even"[^<>]*>Item 2.+<\/li>]*class="odd"[^<>]*>Item 3<\/li>\s*]*class="even"[^<>]*>Item 4.+<\/li>]*class="odd"[^<>]*>Item 5.+<\/li><\/ul>$/', $result); $this->assertPattern('/]*class="even"[^<>]*>Item 2\s*
                                                        \s*]*class="odd"[^<>]*>Item 2.1<\/li>\s*<\/ul>\s*<\/li>/', $result); $this->assertPattern('/]*class="even"[^<>]*>Item 4\s*
                                                          \s*]*class="odd"[^<>]*>Item 4.1<\/li>\s*]*class="even"[^<>]*>Item 4.2<\/li>\s*]*class="odd"[^<>]*>Item 4.3.+<\/li>\s*<\/ul>\s*<\/li>/', $result); $this->assertPattern('/]*class="odd"[^<>]*>Item 4.3\s*
                                                            \s*]*class="odd"[^<>]*>Item 4.3.1<\/li>\s*]*class="even"[^<>]*>Item 4.3.2<\/li>\s*<\/ul>\s*<\/li>/', $result); $this->assertPattern('/]*class="odd"[^<>]*>Item 5\s*
                                                              \s*]*class="odd"[^<>]*>Item 5.1<\/li>\s*]*class="even"[^<>]*>Item 5.2<\/li>\s*<\/ul>\s*<\/li>/', $result); $result = $this->Html->nestedList($list, array('class'=>'list'), array('class' => 'item')); $this->assertPattern('/^]*class="list"[^<>]*>\s*]*class="item"[^<>]*>Item 1<\/li>\s*]*class="item"[^<>]*>Item 2.+<\/li>]*class="item"[^<>]*>Item 3<\/li>\s*]*class="item"[^<>]*>Item 4.+<\/li>]*class="item"[^<>]*>Item 5.+<\/li><\/ul>$/', $result); $this->assertPattern('/]*class="item"[^<>]*>Item 2\s*]*class="list"[^<>]*>\s*]*class="item"[^<>]*>Item 2.1<\/li>\s*<\/ul>\s*<\/li>/', $result); $this->assertPattern('/]*class="item"[^<>]*>Item 4\s*]*class="list"[^<>]*>\s*]*class="item"[^<>]*>Item 4.1<\/li>\s*]*class="item"[^<>]*>Item 4.2<\/li>\s*]*class="item"[^<>]*>Item 4.3.+<\/li>\s*<\/ul>\s*<\/li>/', $result); $this->assertPattern('/]*class="item"[^<>]*>Item 4.3\s*]*class="list"[^<>]*>\s*]*class="item"[^<>]*>Item 4.3.1<\/li>\s*]*class="item"[^<>]*>Item 4.3.2<\/li>\s*<\/ul>\s*<\/li>/', $result); $this->assertPattern('/]*class="item"[^<>]*>Item 5\s*]*class="list"[^<>]*>\s*]*class="item"[^<>]*>Item 5.1<\/li>\s*]*class="item"[^<>]*>Item 5.2<\/li>\s*<\/ul>\s*<\/li>/', $result); } function tearDown() { unset($this->Html); } } ?>