Skip to content

Commit

Permalink
Merge branch 'feature/form_decorator_refactor' into ucsf/develop
Browse files Browse the repository at this point in the history
Conflicts:
	root/assets/lib/decorator/html/tag.class.php
	root/assets/lib/decorator/site/footer.class.php
	root/assets/lib/decorator/site/menu.class.php
  • Loading branch information
Trott committed Mar 30, 2012
2 parents b34b695 + aac975b commit 2475133
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 25 deletions.
10 changes: 0 additions & 10 deletions root/assets/lib/decorator/html/tag.class.php
Expand Up @@ -82,16 +82,6 @@ public function flush_inner() {
} }




/**
* If you really must pass raw HTML to the decorator, well, don't. But if
* you have to, this is the method to use.
*
* @return string
*/
public function render_raw() {
return $this->render(true);
}

/** /**
* Render the tag for output. * Render the tag for output.
* *
Expand Down
3 changes: 2 additions & 1 deletion root/assets/lib/decorator/site/footer.class.php
Expand Up @@ -59,7 +59,8 @@ public function &show_powered_by($val = true) {
return $this; return $this;
} }


public function render($raw) {
public function render($raw = false) {
$this->set_param('id', 'footer'); $this->set_param('id', 'footer');


if ($this->_copyright || $this->_footer_link_urls) { if ($this->_copyright || $this->_footer_link_urls) {
Expand Down
5 changes: 2 additions & 3 deletions root/assets/lib/decorator/site/menu.class.php
Expand Up @@ -135,10 +135,9 @@ public function render($raw = false) {
if ($this->_homescreen && Classification::is_full() && Config::get('frontpage', 'configurable_homescreen')) { if ($this->_homescreen && Classification::is_full() && Config::get('frontpage', 'configurable_homescreen')) {
$js = 'mwf.full.configurableMenu("homescreen_layout").render("main_menu_list",' . $js = 'mwf.full.configurableMenu("homescreen_layout").render("main_menu_list",' .
json_encode( json_encode(
array_map(function($obj) { array_map(function($obj, $raw) {
return $obj->render($raw); return $obj->render($raw);
}, $this->_list)) . ');'; }, $this->_list, array_fill(0, count($this->_list), $raw))) . ');';

$this->add_inner(HTML_Decorator::tag('ol')->set_param('id', 'main_menu_list')); $this->add_inner(HTML_Decorator::tag('ol')->set_param('id', 'main_menu_list'));
$this->add_inner(HTML_Decorator::tag('script', $js)); $this->add_inner(HTML_Decorator::tag('script', $js));
} else { } else {
Expand Down
@@ -1,14 +1,15 @@
<?php <?php


require_once dirname(__FILE__) . '/../../../../../../../root/assets/lib/decorator/html/tag.class.php'; require_once dirname(dirname(dirname(dirname(dirname(dirname(dirname(__DIR__)))))))
. '/root/assets/lib/decorator/html/tag.class.php';


/** /**
* Test class for Tag_HTML_Decorator. * Test class for Tag_HTML_Decorator.
* *
* @author trott * @author trott
* @copyright Copyright (c) 2012 UC Regents * @copyright Copyright (c) 2012 UC Regents
* @license http://mwf.ucla.edu/license * @license http://mwf.ucla.edu/license
* @version 20120318 * @version 20120329
* *
* @uses PHPUnit_Framework_TestCase * @uses PHPUnit_Framework_TestCase
* @uses Tag_HTML_Decorator * @uses Tag_HTML_Decorator
Expand Down Expand Up @@ -47,11 +48,20 @@ public function render_rawHTML_convertedToEntities() {
/** /**
* @test * @test
*/ */
public function renderRaw_rawHTML_notConvertedToEntities() { public function render_rawFlagTruerawHTML_notConvertedToEntities() {
$this->object = HTML_Decorator::tag('p', '&<br>'); $this->object = HTML_Decorator::tag('p', '&<br>');
$this->assertEquals('<p>&<br></p>', $this->object->render_raw()); $this->assertEquals('<p>&<br></p>', $this->object->render(true));
} }


/**
* @test
*/
public function render_rawFlagTrueHTMLDecorator_notConvertedToEntities() {
$this->object = HTML_Decorator::tag('p')
->add_inner_tag('i', "& don't encode me either, Broseph!");
$this->assertEquals("<p><i>& don't encode me either, Broseph!</i></p>",
$this->object->render(true));
}
} }


?> ?>
@@ -0,0 +1,57 @@
<?php

require_once dirname(__FILE__) . '/../../../../../../../root/assets/lib/decorator/site/footer.class.php';

/**
* Test class for Footer_Site_Decorator.
* Generated by PHPUnit on 2012-03-29 at 23:26:46.
*/
class Footer_Site_DecoratorTest extends PHPUnit_Framework_TestCase {

/**
* @var Footer_Site_Decorator
*/
protected $object;

/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
protected function setUp() {
$this->object = new Footer_Site_Decorator;
}

/**
* Tears down the fixture, for example, closes a network connection.
* This method is called after a test is executed.
*/
protected function tearDown() {

}

/**
* @test
*/
public function render_noRawFlag_encodesResult() {
$this->object->add_inner('&');
$this->assertContains('&amp;', $this->object->render());
}

/**
* @test
*/
public function render_rawFlagTrue_doesNotEncodesResult() {
$this->object->add_inner('&');
$this->assertNotContains('&amp;', $this->object->render(true));
}

/**
* @test
*/
public function render_rawFlagFalse_doesNotEncodesResult() {
$this->object->add_inner('&');
$this->assertContains('&amp;', $this->object->render(false));
}

}

Expand Up @@ -6,7 +6,7 @@
* @author trott * @author trott
* @copyright Copyright (c) 2010-12 UC Regents * @copyright Copyright (c) 2010-12 UC Regents
* @license http://mwf.ucla.edu/license * @license http://mwf.ucla.edu/license
* @version 20120218 * @version 20120229
* *
* @uses PHPUnit_Framework_TestCase * @uses PHPUnit_Framework_TestCase
* @uses Menu_Site_Decorator * @uses Menu_Site_Decorator
Expand All @@ -25,7 +25,7 @@ public function setUp() {
* @runInSeparateProcess * @runInSeparateProcess
*/ */
public function render_ampersandInUrlParam_ampersandEntityUsed() { public function render_ampersandInUrlParam_ampersandEntityUsed() {
require dirname(dirname(dirname(dirname(dirname(dirname(dirname(dirname(__FILE__)))))))) . '/root/assets/lib/decorator/site/menu.class.php'; require dirname(dirname(dirname(dirname(dirname(dirname(dirname(__DIR__))))))) . '/root/assets/lib/decorator/site/menu.class.php';


$this->object = new Menu_Site_Decorator; $this->object = new Menu_Site_Decorator;


Expand All @@ -38,7 +38,7 @@ public function render_ampersandInUrlParam_ampersandEntityUsed() {
* @runInSeparateProcess * @runInSeparateProcess
*/ */
public function render_quotesInUrlParam_quotesReplacedWithEntities() { public function render_quotesInUrlParam_quotesReplacedWithEntities() {
require dirname(dirname(dirname(dirname(dirname(dirname(dirname(dirname(__FILE__)))))))) . '/root/assets/lib/decorator/site/menu.class.php'; require dirname(dirname(dirname(dirname(dirname(dirname(dirname(__DIR__))))))) . '/root/assets/lib/decorator/site/menu.class.php';


$this->object = new Menu_Site_Decorator; $this->object = new Menu_Site_Decorator;


Expand All @@ -51,7 +51,7 @@ public function render_quotesInUrlParam_quotesReplacedWithEntities() {
* @runInSeparateProcess * @runInSeparateProcess
*/ */
public function setHomescreen_noParam_isHomescreen() { public function setHomescreen_noParam_isHomescreen() {
require dirname(dirname(dirname(dirname(dirname(dirname(dirname(dirname(__FILE__)))))))) . '/root/assets/lib/decorator/site/menu.class.php'; require dirname(dirname(dirname(dirname(dirname(dirname(dirname(__DIR__))))))) . '/root/assets/lib/decorator/site/menu.class.php';


$this->object = new Menu_Site_Decorator; $this->object = new Menu_Site_Decorator;


Expand All @@ -66,12 +66,12 @@ public function setHomescreen_noParam_isHomescreen() {
* @runInSeparateProcess * @runInSeparateProcess
*/ */
public function render_homescreenAndFull_jsObject() { public function render_homescreenAndFull_jsObject() {
require_once dirname(dirname(dirname(dirname(dirname(dirname(dirname(dirname(__FILE__)))))))) . '/root/assets/lib/config.class.php'; require_once dirname(dirname(dirname(dirname(dirname(dirname(dirname(__DIR__))))))) . '/root/assets/lib/config.class.php';
Config::set('frontpage', 'configurable_homescreen', true); Config::set('frontpage', 'configurable_homescreen', true);
Config::set('global', 'cookie_prefix', 'mwftest_'); Config::set('global', 'cookie_prefix', 'mwftest_');
$_COOKIE['mwftest_classification'] = '{"mobile":false,"basic":true,"standard":true,"full":true,"native":false}'; $_COOKIE['mwftest_classification'] = '{"mobile":false,"basic":true,"standard":true,"full":true,"native":false}';
require_once dirname(dirname(dirname(dirname(dirname(dirname(dirname(dirname(__FILE__)))))))) . '/root/assets/lib/classification.class.php'; require_once dirname(dirname(dirname(dirname(dirname(dirname(dirname(__DIR__))))))) . '/root/assets/lib/classification.class.php';
require_once dirname(dirname(dirname(dirname(dirname(dirname(dirname(dirname(__FILE__)))))))) . '/root/assets/lib/decorator/site/menu.class.php'; require_once dirname(dirname(dirname(dirname(dirname(dirname(dirname(__DIR__))))))) . '/root/assets/lib/decorator/site/menu.class.php';


$this->object = new Menu_Site_Decorator; $this->object = new Menu_Site_Decorator;
$this->object->set_homescreen(); $this->object->set_homescreen();
Expand Down

0 comments on commit 2475133

Please sign in to comment.