Skip to content

Commit

Permalink
#165 - added a unit test for SequenceView::listView()
Browse files Browse the repository at this point in the history
  • Loading branch information
alphadevx committed Aug 13, 2015
1 parent d1af59a commit 64fda37
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 9 deletions.
14 changes: 5 additions & 9 deletions Alpha/View/SequenceView.php
Expand Up @@ -4,6 +4,7 @@

use Alpha\Controller\Front\FrontController;
use Alpha\Util\Logging\Logger;
use Alpha\Util\Config\ConfigProvider;
use Alpha\Exception\IllegalArguementException;
use Alpha\Model\Type\String;
use Alpha\View\Widget\Button;
Expand Down Expand Up @@ -157,27 +158,22 @@ public function listView($fields=array())

$fields['formFields'] = $html;

// View button
if (strpos($fields['URI'], '/tk/') !== false) {
$button = new Button("document.location = '".FrontController::generateSecureURL('act=Detail&bo='.get_class($this->BO).'&oid='.$this->BO->getOID())."';", 'View', 'viewBut');
$fields['viewButton'] = $button->render();
} else {
$button = new Button("document.location = '".$this->BO->get('URL')."';", 'View', 'viewBut');
$fields['viewButton'] = $button->render();
}
$button = new Button("document.location = '".FrontController::generateSecureURL('act=Detail&bo='.get_class($this->BO).'&oid='.$this->BO->getOID())."';", 'View', 'viewBut');
$fields['viewButton'] = $button->render();

// supressing the edit/delete buttons for Sequences
$fields['adminButtons'] = '';

// buffer security fields to $formSecurityFields variable
$fields['formSecurityFields'] = $this->renderSecurityFields();

$this->loadTemplate($this->BO, 'list', $fields);
$html = $this->loadTemplate($this->BO, 'list', $fields);

if (method_exists($this, 'after_listView_callback'))
$this->after_listView_callback();

self::$logger->debug('<<listView');
return $html;
}

/**
Expand Down
100 changes: 100 additions & 0 deletions test/Alpha/Test/View/SequenceViewTest.php
@@ -0,0 +1,100 @@
<?php

namespace Alpha\Test\View;

use Alpha\View\SequenceView;
use Alpha\View\View;
use Alpha\Model\Type\Sequence;
use Alpha\Util\Config\ConfigProvider;
use Alpha\Util\Http\Session\SessionProviderFactory;

/**
*
* Test cases for the SequenceView class.
*
* @since 2.0
* @author John Collins <dev@alphaframework.org>
* @license http://www.opensource.org/licenses/bsd-license.php The BSD License
* @copyright Copyright (c) 2015, John Collins (founder of Alpha Framework).
* All rights reserved.
*
* <pre>
* Redistribution and use in source and binary forms, with or
* without modification, are permitted provided that the
* following conditions are met:
*
* * Redistributions of source code must retain the above
* copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the
* following disclaimer in the documentation and/or other
* materials provided with the distribution.
* * Neither the name of the Alpha Framework nor the names
* of its contributors may be used to endorse or promote
* products derived from this software without specific
* prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* </pre>
*
*/
class SequenceViewTest extends \PHPUnit_Framework_TestCase
{
/**
* {@inheritDoc}
*
* @since 2.0
*/
protected function setUp()
{
$config = ConfigProvider::getInstance();
$config->set('session.provider.name', 'Alpha\Util\Http\Session\SessionProviderArray');

$sequence = new Sequence();
$sequence->rebuildTable();
$sequence->set('prefix', 'TEST');
$sequence->set('sequence', 1);
$sequence->save();
}

/**
* {@inheritDoc}
*
* @since 2.0
*/
protected function tearDown()
{
$sequence = new Sequence();
$sequence->dropTable();
}

/**
* Testing the listView() method
*
* @since 2.0
*/
public function testListView()
{
$sequence = new Sequence();
$sequence->load(1);
$view = View::getInstance($sequence);

$this->assertNotEmpty($view->listView(array('URI' => '/')), 'Testing the listView() method');
$this->assertTrue(strpos($view->listView(array('URI' => '/')),'TEST') !== false, 'Testing the listView() method');
}
}

?>

0 comments on commit 64fda37

Please sign in to comment.