Skip to content

Commit

Permalink
#277 - added the HighlightProviderTest unit test case, and added the …
Browse files Browse the repository at this point in the history
…new Validator::isHTML() method
  • Loading branch information
alphadevx committed Apr 10, 2016
1 parent 4d0ff2c commit e53e590
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 1 deletion.
17 changes: 16 additions & 1 deletion Alpha/Util/Helper/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*
* @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).
* @copyright Copyright (c) 2016, John Collins (founder of Alpha Framework).
* All rights reserved.
*
* <pre>
Expand Down Expand Up @@ -381,4 +381,19 @@ public static function isBase64($value)
{
return (bool) preg_match('/^(?:[A-Za-z0-9+\/]{4})*(?:[A-Za-z0-9+\/]{2}==|[A-Za-z0-9+\/]{3}=)?$/', $value);
}

/**
* Will return true if the value provided contains any HTML code that is stripable by
* the native strip_tags() function.
*
* @param $value
*
* @return bool
*
* @since 2.0.1
*/
public static function isHTML($value)
{
return $value != strip_tags($value) ? true : false;
}
}
84 changes: 84 additions & 0 deletions test/Alpha/Test/Util/Code/Highlight/HighlightProviderTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?php

namespace Alpha\Test\Util\Code\Highlight;

use Alpha\Util\Code\Highlight\HighlightProviderFactory;
use Alpha\Util\Helper\Validator;

/**
* Test cases for the HighlightProviderInterface implementations.
*
* @since 2.0.1
*
* @author John Collins <dev@alphaframework.org>
* @license http://www.opensource.org/licenses/bsd-license.php The BSD License
* @copyright Copyright (c) 2016, 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 HighlightProviderTest extends \PHPUnit_Framework_TestCase
{
/**
* Returns an array of highlight providers.
*
* @return array
*
* @since 2.0.1
*/
public function getHighlightProviders()
{
return array(
array('Alpha\Util\Code\Highlight\HighlightProviderGeshi'),
array('Alpha\Util\Code\Highlight\HighlightProviderLuminous')
);
}

/**
* Testing the highlight() method.
*
* @since 2.0.1
* @dataProvider getHighlightProviders
*/
public function testHighlight($provider)
{
$highlighter = HighlightProviderFactory::getInstance($provider);

$code = '<?= $value ?>';

$highlighted = $highlighter->highlight($code, 'php');

$this->assertNotEmpty($highlighted, 'Testing the highlight() method');
$this->assertTrue(Validator::isHTML($highlighted), 'Testing the highlight() method');
}
}

0 comments on commit e53e590

Please sign in to comment.