Skip to content

Commit

Permalink
Second commit
Browse files Browse the repository at this point in the history
  • Loading branch information
silbinarywolf committed Mar 25, 2018
1 parent 3559e50 commit baa8514
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 16 deletions.
10 changes: 3 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@

language: php

dist: trusty

php:
# Silverstripe 3.x
# NOTE: Travis-CI is only supporting PHP 5.4+ from late 2017.
- 5.4

env:
Expand All @@ -17,12 +13,12 @@ matrix:
include:
- php: 5.4
env:
- DB=PGSQL
- CORE_RELEASE=3.2
- DB=MYSQL
- CORE_RELEASE=3.6
- php: 5.5
env:
- DB=MYSQL
- CORE_RELEASE=3.3
- CORE_RELEASE=3.6
- php: 5.6
env:
- DB=MYSQL
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "Create components using SilverStripe.",
"type": "silverstripe-module",
"keywords": [
"silverstripe",
"silverstripe"
],
"license": "BSD-3-Clause",
"authors": [
Expand All @@ -13,7 +13,7 @@
}
],
"require": {
"silverstripe/framework": "~3.6",
"silverstripe/framework": "~3.6"
},
"require-dev": {
"squizlabs/php_codesniffer": "^3.0"
Expand Down
10 changes: 8 additions & 2 deletions src/SilbinaryWolf/Components/TemplateParserComponentProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,14 @@ public static function componentTemplate($res)
$properties[$varName] = $value;
}

$componentClass = Component::class;
$htmlTextClass = HTMLText::class;
// HTMLText::class / Component::class won't work in PHP versions below 5.5
// we just utilize the string values directly here.
//
// When this module stops supporting lower PHP versions, we will replace these
// values.
//
$componentClass = 'SilbinaryWolf\Components\Component';
$htmlTextClass = 'HTMLText';

// Add HTML within the block as $Children variable
$childrenText = $res['Template']['text'];
Expand Down
33 changes: 28 additions & 5 deletions tests/ComponentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@

class ComponentTest extends SapphireTest
{
public function setUp()
public function setUp()
{
parent::setUp();
Config::inst()->update(SSViewer::class, 'source_file_comments', false);
Config::inst()->update(SSViewer_FromString::class, 'cache_template', false);
Config::inst()->update('SSViewer', 'source_file_comments', false);
Config::inst()->update('SSViewer_FromString', 'cache_template', false);
}

public function tearDown()
public function tearDown()
{
parent::tearDown();
}
Expand All @@ -40,14 +40,37 @@ public function testSimpleCase()
No submission
</span>
</button>
HTML;
$this->assertEqualIgnoringWhitespace($expectedHTML, $resultHTML, 'Unexpected output');
}

/**
*
*/
public function testPassingOptionalTypeProperty()
{
$template = <<<SSTemplate
<% component MyComponentButton, "Class=btn btn-primary", "Type=submit" %>
<span class="text">
Submit me!
</span>
<% end_component %>
SSTemplate;
$resultHTML = SSViewer::fromString($template)->process(null);
$expectedHTML = <<<HTML
<button class="btn btn-primary" type="submit">
<span class="text">
Submit me!
</span>
</button>
HTML;
$this->assertEqualIgnoringWhitespace($expectedHTML, $resultHTML, 'Unexpected output');
}

/**
* Taken from "framework\tests\view\SSViewerTest.php"
*/
protected function assertEqualIgnoringWhitespace($a, $b)
protected function assertEqualIgnoringWhitespace($a, $b)
{
$this->assertEquals(preg_replace('/\s+/', '', $a), preg_replace('/\s+/', '', $b));
}
Expand Down

0 comments on commit baa8514

Please sign in to comment.