Skip to content
This repository has been archived by the owner on Sep 13, 2023. It is now read-only.

Commit

Permalink
adding first tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mvhenten committed Mar 23, 2012
1 parent 272b43b commit 131764e
Show file tree
Hide file tree
Showing 6 changed files with 333 additions and 0 deletions.
21 changes: 21 additions & 0 deletions Application/plugin/Builder/hook.php
@@ -0,0 +1,21 @@
<?php
/**
* Application/plugin/ItemThumbnail/hook.php
*
* @author Matthijs van Henten <matthijs@ischen.nl>
* @package default
*/


@list( , $controller, $action, $item_id ) = $request->pathParts;
?>

<?php
if ( $start ) {
Nano_Autoloader::registerNamespace( 'Builder', dirname(__FILE__) );
$this->router->prepend( '/admin/plugin/thumb/\w+(/\d+)?', 'ItemThumb_Plugin' );
}
?>

<?php if ( $end ): ?>
<?php endif; ?>
85 changes: 85 additions & 0 deletions Application/plugin/Builder/lib/Abc.php
@@ -0,0 +1,85 @@
<?php
/**
* Application/plugin/Builder/lib/Abc.php
*
* @author Matthijs van Henten <matthijs@ischen.nl>
* @package Pico
*/


abstract class Builder_Abc {
private $_constructor_args;



/**
*
*
* @param unknown $args
*/
public function __construct( $args ) {
$this->_constructor_args = $args; //func_get_args();
}



/**
*
*
* @return unknown
*/
public function __toString() {
return $this->as_string();
}


/**
*
*
* @param unknown $name
* @return unknown
*/
public function __get( $name ) {
if ( ($property = "_$name")
&& (isset($this->$property) || property_exists( $this, $property ))) {
if ( ! isset( $this->$property )
&& method_exists( $this, "_build_$property" ) ) {
$method = "_build_$property";
$this->$property = $this->$method();
}
return $this->$property;
}
}



/**
*
*
* @param unknown $name
* @return unknown
*/
public function arg( $name ) {
if ( isset( $this->_constructor_args[$name] ) ) {
return $this->_constructor_args[$name];
}

return array();
}



/**
*
*
* @param unknown $args
* @return unknown
*/
public function element( $args ) {
$args = array_merge( array( 'type' => 'div', 'attributes' => array() ), $args );

return new Nano_Element( $args['type'], $args['attributes']);
}


}
40 changes: 40 additions & 0 deletions Application/plugin/Builder/lib/Block.php
@@ -0,0 +1,40 @@
<?php
/**
* Application/plugin/Builder/lib/Block.php
*
* @author Matthijs van Henten <matthijs@ischen.nl>
* @package Pico
*/


class Builder_Block extends Builder_Abc {

protected $_element;



/**
*
*
* @return unknown
*/
public function as_string() {
return (string) $this->element;
}



/**
*
*
* @return unknown
*/
protected function _build__element() {
$div = new Nano_Element( 'div' );
$div->setVertile();

return $div;
}


}
99 changes: 99 additions & 0 deletions Application/plugin/Builder/lib/Page.php
@@ -0,0 +1,99 @@
<?php
/**
* Application/plugin/Builder/lib/Page.php
*
* @author Matthijs van Henten <matthijs@ischen.nl>
* @package Pico
*/


class Builder_Page extends Builder_Abc {
protected $_doctype = 'html';

protected $_html;
protected $_body;
protected $_head;


//$builder = new Builder_Page(array(
// 'head' => array(
// 'children' => array(
// 'type' => 'link',
// 'attibutes' => array(
// 'href' => 'style.css',
// 'rel' => 'stylesheet',
// )
// )
// ),
// 'children' => array(
// array(
// 'type' => 'block',
// )
// )
//));


/**
*
*
* @return unknown
*/
public function as_string() {
$doctype = sprintf('<!DOCTYPE %s>', $this->doctype );

return join( "\n", array( $doctype, $this->html ) );
}



/**
*
*
* @return unknown
*/
protected function _build__html() {
$html = new Nano_Element( 'html' );
$html->addChild( $this->head );
$html->addChild( $this->body );

return $html;
}



/**
*
*
* @return unknown
*/
protected function _build__head() {
$head = new Nano_Element( 'head' );
$head->setVertile();

$args = $this->arg('head');

if ( isset( $args['children'] ) ) {
foreach ( $args['children'] as $child ) {
$head->addChild( $this->element( $child )) ;
}
}

return $head;
}



/**
*
*
* @return unknown
*/
protected function _build__body() {
$body = new Nano_Element( 'body' );
$body->setVertile();

return $body;
}


}
38 changes: 38 additions & 0 deletions Application/plugin/Builder/t/Block.php
@@ -0,0 +1,38 @@
<?php
/**
* Application/plugin/Builder/t/Block.php
*
* @author Matthijs van Henten <matthijs@ischen.nl>
* @package Pico
*/


class Builder_PageTest extends PHPUnit_Framework_TestCase{
private $config;

/**
*
*/
protected function setUp() {
require_once dirname(dirname(__FILE__)) . '/../Nano/library/Nano/Autoloader.php';
Nano_Autoloader::register();
Nano_Autoloader::registerNamespace( 'Builder', dirname(__FILE__) . '/../lib' );
}



/**
*
*/
public function testStringify() {
$builder = new Builder_Block();
$expect = ' <div>
</div>
';

$this->assertEquals($expect, (string) $builder );
}


}
50 changes: 50 additions & 0 deletions Application/plugin/Builder/t/Page.php
@@ -0,0 +1,50 @@
<?php
/**
* Application/plugin/Builder/t/Page.php
*
* @author Matthijs van Henten <matthijs@ischen.nl>
* @package Pico
*/


class Builder_PageTest extends PHPUnit_Framework_TestCase{
private $config;

/**
*
*/
protected function setUp() {
require_once dirname(dirname(__FILE__)) . '/../Nano/library/Nano/Autoloader.php';
Nano_Autoloader::register();
Nano_Autoloader::registerNamespace( 'Builder', dirname(__FILE__) . '/../lib' );
}



/**
*
*/
public function testSmoke() {
$builder = new Builder_Page(array(
'head' => array(
'children' => array(
array(
'type' => 'link',
'attributes' => array(
'href' => 'style.css',
'rel' => 'stylesheet',
))
)
),
'children' => array(
array(
'type' => 'block',
)
)
));

echo $builder;
}


}

0 comments on commit 131764e

Please sign in to comment.