예제 #1
0
<?php

require_once dirname(__FILE__) . '/helper/dmUnitTestHelper.php';
$helper = new dmUnitTestHelper();
$helper->boot('front');
$t = new lime_test(47);
dm::loadHelpers(array('Dm'));
sfConfig::set('sf_no_script_name', false);
dmDb::table('DmPage')->checkBasicPages();
$sc = $helper->get('service_container');
$sc->mergeParameter('link_tag_record.options', array('current_span' => false))->mergeParameter('link_tag_page.options', array('current_span' => false));
$t->diag('link current_span is false');
$home = dmDb::table('DmPage')->getTree()->fetchRoot();
$helper->get('context')->setPage($home);
$t->diag($home->name . ' is the current page');
$testPage = dmDb::create('DmPage', array('module' => 'main', 'action' => 'test' . dmString::random(12), 'name' => 'I am a root child', 'slug' => dmString::random()));
$testPage->Node->insertAsLastChildOf($home);
$scriptName = $helper->get('request')->getScriptName();
$t->diag('Current cli script name = ' . $scriptName);
$t->is((string) _link('http://c2.com/cgi/wiki?DontRepeatYourself')->text('DRY'), $expected = '<a class="link" href="http://c2.com/cgi/wiki?DontRepeatYourself">DRY</a>', $expected);
$t->like(£link()->render(), '|<a class="link dm_current|', '£link() has class dm_current');
$t->like(£link()->set('current_class', 'my_current')->render(), '|<a class="link my_current|', '£link() has class my_current');
$t->is((string) £link($home), (string) £link(), '£link($home) is £link()');
$t->is((string) £link('@homepage'), (string) £link($home), '£link("@homepage") is £link()');
$t->is((string) £link('main/root'), (string) £link($home), '£link("main/root") is £link()');
$t->is(£link()->getHref(), $scriptName, 'root href is ' . $scriptName);
$t->is(£link()->getText(), $home->name, 'root link text is ' . $home->name);
$expected = $helper->get('controller')->genUrl('dmAuth/signin');
$t->is(£link('+/dmAuth/signin')->getHref(), $expected, '+/dmAuth/signin href is ' . $expected);
$rootLink = sprintf('<a class="%s" href="%s">%s</a>', 'link dm_current', $scriptName, $home->name);
$t->is((string) £link(), $rootLink, 'root link is ' . $rootLink);
예제 #2
0
파일: dmMenuTest.php 프로젝트: jdart/diem
<?php

$config = getcwd() . '/config/ProjectConfiguration.class.php';
require_once $config;
require_once dm::getDir() . '/dmCorePlugin/test/unit/helper/dmUnitTestHelper.php';
$helper = new dmUnitTestHelper();
$helper->boot('front');
$t = new lime_test(50);
dm::loadHelpers(array('Dm', 'I18N'));
$menu = $helper->get('menu')->name('Test Menu');
$root1 = $menu->getChild('Root 1');
$root1->addChild('Child 1');
$last = $root1->addChild('Child 2');
$root2 = $menu->getChild('Root 2');
$child1 = $root2->addChild('Child 1');
$child2 = $child1->addChild('Child 2');
$t->is($root1->getLevel(), 0, 'Test root level is 0');
$t->is($root2->getLevel(), 0, 'Test root level is 0');
$t->is($child1->getLevel(), 1, 'Test level is 1');
$t->is($child2->getLevel(), 2, 'Test level is 2');
$t->is($child2->getPathAsString(), 'Test Menu > Root 2 > Child 1 > Child 2', 'Test getPathAsString()');
$t->is(get_class($root1), get_class($menu), 'Test children are created as same class as parent');
// array access
$t->is($menu['Root 1']['Child 1']->getName(), 'Child 1', 'Test name()');
// countable
$t->is(count($menu), $menu->count(), 'Test sfSympalMenu Countable interface');
$t->is(count($root1), 2, 'Test sfSympalMenu Countable interface');
$count = 0;
foreach ($root1 as $key => $value) {
    $count++;
    $t->is($key, 'Child ' . $count, 'Test iteratable');
예제 #3
0
<?php

$config = getcwd() . '/config/ProjectConfiguration.class.php';
require_once $config;
require_once dm::getDir() . '/dmCorePlugin/test/unit/helper/dmUnitTestHelper.php';
$helper = new dmUnitTestHelper();
$helper->boot('front');
// load both standard and alternative helpers
dm::loadHelpers(array('Dm', 'DmAlternative', 'I18N'));
$t = new lime_test(30);
/*
* $helper is the test helper. It acts as a service container
* and can provide you all services with its get() method.
* so here we get the 'helper' service which is the template helper instance
*/
$templateHelper = $helper->get('helper');
// £ function
$t->is(£('div', 'content'), _tag('div', 'content'), '£ == _tag');
// £ method
$t->is($templateHelper->£('div', 'content'), $templateHelper->tag('div', 'content'), '£ == _tag');
$t->is(£('div', 'content'), _tag('div', 'content'), '£ == _tag');
// £link method
$t->is((string) $templateHelper->£link()->text('home'), (string) $templateHelper->link()->text('home'), '£link == _link');
$t->is((string) £link()->text('home'), (string) _link()->text('home'), '£link == _link');
$openDiv = '<div>';
$t->is(£o('div'), _tagO('div'), $openDiv);
$openDiv = '<div class="test_class">';
$t->is(£o('div.test_class'), _tagO('div.test_class'), $openDiv);
$openDiv = '<div id="test_id" class="test_class other_class">';
$t->is(£o('div#test_id.test_class.other_class'), _tagO('div#test_id.test_class.other_class'), $openDiv);
$openDiv = '<div class="test_class other_class" id="test_id">';
예제 #4
0
$helper = new dmUnitTestHelper();
$helper->boot('front');
$t = new lime_test(76);
$pageTable = dmDb::table('DmPage');
$root = $pageTable->getTree()->fetchRoot();
$testModule = dmString::random();
$pages = array($root);
for ($it = 1; $it <= 2; $it++) {
    $pages[] = $p = dmDb::table('DmPage')->create(array('module' => $testModule, 'action' => 'test' . $it, 'name' => dmString::random(), 'slug' => dmString::random()));
    $p->Node->insertAsLastChildOf($pages[$it - 1]);
    $pages[$it - 1]->refresh();
    $p->refresh();
    $t->ok($p->exists(), $p . ' exists');
    $t->is($p->nodeParentId, (string) $pages[$it - 1]->id, $p . ' is child of ' . $pages[$it - 1]);
}
dm::loadHelpers(array('DmFront'));
foreach ($pages as $index => $page) {
    $helper->get('context')->setPage($page);
    $t->comment('Testing ->isSource for ' . $page);
    foreach ($pages as $_page) {
        $ok = $page === $_page;
        $t->is($page->isSource($_page), $ok, '$page->isSource($page) ' . ($ok ? 'TRUE' : 'FALSE'));
        $t->is($page->isSource("page:" . $_page->id), $ok, '$page->isSource("page:".$page->id) ' . ($ok ? 'TRUE' : 'FALSE'));
        $t->is($page->isSource($_page->module . "/" . $_page->action), $ok, '$page->isSource($page->module."/".$page->action) ' . ($ok ? 'TRUE' : 'FALSE'));
        $t->is(dm_current($_page), $ok, 'dm_current($page) ' . ($ok ? 'TRUE' : 'FALSE'));
    }
    if ($index) {
        $t->comment('Testing ->isDescendantOfSource for ' . $page);
        for ($i = 0; $i < $index; $i++) {
            $t->ok($page->isDescendantOfSource($pages[$i]), '$page->isDescendantOfSource($pages[$i])');
            $t->ok($page->isDescendantOfSource("page:" . $pages[$i]->id), '$page->isDescendantOfSource("page:".$pages[$i]->id)');
예제 #5
0
<?php

require_once dirname(__FILE__) . '/helper/dmUnitTestHelper.php';
$helper = new dmUnitTestHelper();
$helper->boot('front');
$t = new lime_test();
dm::loadHelpers('DmFront');
$title = dm_get_widget('dmWidgetContent', 'title', array('tag' => 'h1', 'text' => 'The title text'));
$expected = '<div class="dm_widget content_title"><div class="dm_widget_inner"><h1>The title text</h1></div></div>';
$t->is($title, $expected, 'rendered title H1');
$title = dm_get_widget('dmWidgetContent', 'title', array('tag' => 'h2', 'text' => 'The title text', 'css_class' => 'custom_class'));
$expected = '<div class="dm_widget content_title custom_class"><div class="dm_widget_inner"><h2>The title text</h2></div></div>';
$t->is($title, $expected, 'rendered title H2 with CSS class');
$title = dm_get_widget('main', 'header', array('name' => 'Thibault', 'css_class' => 'custom_class'));
$expected = '<div class="dm_widget main_header custom_class"><div class="dm_widget_inner">name: Thibault</div></div>';
$t->is($title, $expected, 'rendered main header with component param and CSS class');
예제 #6
0
<?php

require_once dirname(__FILE__) . '/helper/dmUnitTestHelper.php';
$helper = new dmUnitTestHelper();
$helper->boot('front');
class DummyTestForm extends dmForm
{
    public function getStylesheets()
    {
        return array('lib.ui-tabs', 'lib.ui-core' => 'all');
    }
    public function getJavascripts()
    {
        return array('core.tabForm');
    }
}
$t = new lime_test();
$form = new DummyTestForm();
dm::loadHelpers(array('Asset', 'Tag', 'Dm'));
$stylesheets = dm_get_stylesheets_for_form($form);
$t->like($stylesheets, '#' . preg_quote('/dmCorePlugin/lib/jquery-ui/css/jquery-ui-tabs.css', '#') . '#');
$t->like($stylesheets, '#' . preg_quote('/fancyTheme/css/lib.ui-core.css', '#') . '#');
$javascripts = dm_get_javascripts_for_form($form);
$t->like($javascripts, '#' . preg_quote('/dmCorePlugin/js/dmCoreTabForm.js', '#') . '#');