-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- checking html validity
- Loading branch information
Showing
6 changed files
with
151 additions
and
82 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
use PHPUnit\Framework\TestCase; | ||
|
||
class SocialGroupsTest extends TestCase { | ||
public function isValidHtmlContent($htmlExtract) { | ||
try { | ||
$doc = new DOMDocument(); | ||
|
||
return $doc->loadHTML('<html><body>'.$htmlExtract.'</body></html>'); | ||
} catch (Exception $e) { | ||
echo "\n\ninvalid HTML:\n",$e->getMessage(),"\n\n",$htmlExtract,"\n\n"; | ||
|
||
return false; | ||
} | ||
} | ||
|
||
public function test_generate_social_groups() { | ||
// GIVEN | ||
require_once 'website/templates/konfig-groups.php'; | ||
$socialGroupsConfig = $config['gk_social_groups']; | ||
$socialGroups = new \Geokrety\View\SocialGroups($socialGroupsConfig); | ||
|
||
// WHEN | ||
$groupsCount = $socialGroups->count(); | ||
$groupsTable = $socialGroups->toHtmlTable(); | ||
|
||
// THEN | ||
$this->assertGreaterThan(0, $groupsCount, 'please define one or more social groups into konfig-groups'); | ||
|
||
$this->assertNotNull($groupsTable); | ||
$this->assertTrue($this->isValidHtmlContent($groupsTable), 'social groups table: must be valid html content'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
namespace Geokrety\View; | ||
|
||
/** | ||
* HTML Helper, a way to generate GeoKrety Social Groups Html Table. | ||
**/ | ||
class SocialGroups { | ||
private $socialGroups; | ||
|
||
public function __construct($config) { | ||
$this->socialGroups = $config; | ||
} | ||
|
||
public function count() { | ||
if (!isset($this->socialGroups)) { | ||
return 0; | ||
} | ||
|
||
return count($this->socialGroups) - 1; | ||
} | ||
|
||
public function toHtmlTable() { | ||
$groupsTable = '<table style="padding:15px;" cellpadding="10">' | ||
.'<thead><tr>' | ||
.'<th>'.$this->socialGroups[0]['lang'].'</th>' | ||
.'<th>'.$this->socialGroups[0]['service'].'</th>' | ||
.'<th>'.$this->socialGroups[0]['title'].'</th>' | ||
.'</tr></thead>' | ||
.'<tbody>'; | ||
for ($i = 1; $i < count($this->socialGroups); ++$i) { | ||
$groupsTable .= '<tr>' | ||
.'<td style="padding:4px;"><img src="https://cdn.geokrety.org/images/country-codes/' | ||
.$this->socialGroups[$i]['flag'] | ||
.'.png"/>' | ||
.' '.$this->socialGroups[$i]['lang'].'</td>' | ||
.'<td>'.$this->socialGroups[$i]['service'].'</td>' | ||
.'<td><a href="'.$this->socialGroups[$i]['link'].'">'.$this->socialGroups[$i]['title'].'</td>' | ||
.'</tr>'; | ||
} | ||
$groupsTable .= '</tbody></table>'; | ||
|
||
return $groupsTable; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
if (!isset($config)) { | ||
$config = array(); | ||
} | ||
|
||
$config['gk_social_groups'] = array(); | ||
$config['gk_social_groups'][0] = [ | ||
'link' => _('group link'), | ||
'service' => _('group service'), | ||
'title' => _('group name'), | ||
'lang' => _('languages'), | ||
'flag' => _('flag'), | ||
]; | ||
$config['gk_social_groups'][1] = [ | ||
'link' => 'https://www.facebook.com/groups/1624761011150615/about/', | ||
'service' => 'Facebook', | ||
'title' => 'GeoKret en France', | ||
'lang' => 'french', | ||
'flag' => 'fr', | ||
]; | ||
$config['gk_social_groups'][2] = [ | ||
'link' => 'https://www.facebook.com/groups/317897208552636/about/', | ||
'service' => 'Facebook', | ||
'title' => 'GeoCaching met GeoKrety.Org', | ||
'lang' => 'dutch', | ||
'flag' => 'de', | ||
]; | ||
$config['gk_social_groups'][3] = [ | ||
'link' => 'https://plus.google.com/communities/100975961916549394786', | ||
'service' => 'Google+', | ||
'title' => 'GeoKrety Discussion', | ||
'lang' => 'dutch, english', | ||
'flag' => 'de', | ||
]; | ||
$config['gk_social_groups'][4] = [ | ||
'link' => 'https://forum.opencaching.pl/viewforum.php?f=11', | ||
'service' => 'Opencaching Poland', | ||
'title' => 'geokrety', | ||
'lang' => 'polska', | ||
'flag' => 'pl', | ||
]; | ||
$config['gk_social_groups'][5] = [ | ||
'link' => 'https://geoclub.de/forum/viewforum.php?f=102', | ||
'service' => 'geoclub.de forum', | ||
'title' => 'Geokrety', | ||
'lang' => 'dutch', | ||
'flag' => 'de', | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters