-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #161 from City-of-Helsinki/UHF-9159_subgroup
UHF-9159 subgroup
- Loading branch information
Showing
11 changed files
with
184 additions
and
0 deletions.
There are no files selected for viewing
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
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
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,79 @@ | ||
<?php | ||
|
||
declare(strict_types = 1); | ||
|
||
namespace Drupal\helfi_tpr\Field\Connection; | ||
|
||
use Drupal\Component\Render\FormattableMarkup; | ||
use Drupal\Component\Utility\Html; | ||
use Drupal\Core\Url; | ||
|
||
/** | ||
* Provides a domain object for TPR connection type of Subgroup. | ||
*/ | ||
final class Subgroup extends Connection { | ||
|
||
/** | ||
* The type name. | ||
* | ||
* @var string | ||
*/ | ||
public const TYPE_NAME = 'SUBGROUP'; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getFields(): array { | ||
return [ | ||
'name', | ||
'contact_person', | ||
'phone', | ||
'email', | ||
]; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function build(): array { | ||
$fields = $this->getFields(); | ||
$fields_data = []; | ||
|
||
foreach ($fields as $field) { | ||
if (!$this->get($field)) { | ||
continue; | ||
} | ||
|
||
$data = Html::escape($this->get($field)); | ||
|
||
$fields_data[] = match ($field) { | ||
'name' => [ | ||
'#markup' => '<strong>' . $data . '</strong>', | ||
], | ||
'contact_person' => [ | ||
'#markup' => '<span>' . $data . '</span>', | ||
'#prefix' => '<br />', | ||
], | ||
'email' => [ | ||
'#url' => Url::fromUri('mailto:' . $data), | ||
'#title' => new FormattableMarkup($data, []), | ||
'#type' => 'link', | ||
'#prefix' => '<br />', | ||
], | ||
'phone' => [ | ||
'#url' => Url::fromUri('tel:' . $data), | ||
'#title' => new FormattableMarkup($data, []), | ||
'#type' => 'link', | ||
'#prefix' => '<br />', | ||
], | ||
}; | ||
} | ||
|
||
$build = [ | ||
'subgroup' => $fields_data, | ||
]; | ||
|
||
return $build; | ||
} | ||
|
||
} |
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 |
---|---|---|
|
@@ -690,6 +690,26 @@ public function getMockData() : array { | |
'www_en' => 'https://localhost/en', | ||
'www_sv' => 'https://localhost/sv', | ||
], | ||
[ | ||
'unit_id' => 1, | ||
'section_type' => 'SUBGROUP', | ||
'name_fi' => 'subgroup fi 1', | ||
'name_en' => 'subgroup en 1', | ||
'name_sv' => 'subgroup sv 1', | ||
'contact_person' => 'subgroup contact person name', | ||
'phone' => '0406543210', | ||
'email' => '[email protected]', | ||
], | ||
[ | ||
'unit_id' => 1, | ||
'section_type' => 'SUBGROUP', | ||
'name_fi' => 'subgroup fi 2', | ||
'name_en' => 'subgroup en 2', | ||
'name_sv' => 'subgroup sv 2', | ||
'contact_person' => 'subgroup contact person name 2', | ||
'phone' => '0506543210', | ||
'email' => '[email protected]', | ||
], | ||
], | ||
'provided_languages' => [ | ||
'fi', | ||
|
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 |
---|---|---|
|
@@ -12,6 +12,7 @@ | |
use Drupal\helfi_tpr\Field\Connection\OtherInfo; | ||
use Drupal\helfi_tpr\Field\Connection\PhoneOrEmail; | ||
use Drupal\helfi_tpr\Field\Connection\Price; | ||
use Drupal\helfi_tpr\Field\Connection\Subgroup; | ||
use Drupal\helfi_tpr\Field\Connection\Topical; | ||
|
||
/** | ||
|
@@ -72,6 +73,7 @@ public function testUnitMigration() : void { | |
$this->assertEquals("price $langcode $delta", $translation->get('price_info')->get($i)->value); | ||
$this->assertEquals("other info $langcode $delta", $translation->get('other_info')->get($i)->value); | ||
$this->assertEquals("topical $langcode $delta", $translation->get('topical')->get($i)->value); | ||
$this->assertEquals("subgroup $langcode $delta", $translation->get('subgroup')->get($i)->value); | ||
} | ||
|
||
$opening_hour = $translation->get('opening_hours')->get(1)->data; | ||
|
@@ -102,6 +104,12 @@ public function testUnitMigration() : void { | |
$topical = $translation->get('topical')->get(0)->data; | ||
$this->assertInstanceOf(Topical::class, $topical); | ||
$this->assertEquals("https://localhost/$langcode", $links->get('www')); | ||
|
||
$subgroup = $translation->get('subgroup')->get(0)->data; | ||
$this->assertInstanceOf(Subgroup::class, $subgroup); | ||
$this->assertEquals("subgroup contact person name", $subgroup->get('contact_person')); | ||
$this->assertEquals("0406543210", $subgroup->get('phone')); | ||
$this->assertEquals("[email protected]", $subgroup->get('email')); | ||
} | ||
|
||
// Re-run migrate and make sure migrate map hash doesn't change. | ||
|
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 |
---|---|---|
|
@@ -11,6 +11,7 @@ | |
use Drupal\helfi_tpr\Field\Connection\OtherInfo; | ||
use Drupal\helfi_tpr\Field\Connection\PhoneOrEmail; | ||
use Drupal\helfi_tpr\Field\Connection\Price; | ||
use Drupal\helfi_tpr\Field\Connection\Subgroup; | ||
use Drupal\helfi_tpr\Field\Connection\TextWithLink; | ||
use Drupal\helfi_tpr\Field\Connection\Topical; | ||
|
||
|
@@ -198,6 +199,36 @@ public function testTopical() : void { | |
$this->assertNotEmpty($object->build()); | ||
} | ||
|
||
/** | ||
* Tests subgroups. | ||
* | ||
* @covers \Drupal\helfi_tpr\Field\Connection\Subgroup::build | ||
* @covers \Drupal\helfi_tpr\Field\Connection\Subgroup::getFields | ||
* @covers ::set | ||
* @covers ::get | ||
* @covers ::isValidField | ||
*/ | ||
public function testSubgroup() : void { | ||
$object = new Subgroup(); | ||
$object->set('name', 'Some information.'); | ||
$this->assertNotEmpty($object->build()); | ||
|
||
// Make sure we can override data. | ||
$object->set('name', 'override'); | ||
$this->assertNotEmpty($object->build()); | ||
|
||
$this->assertEquals(['name', 'contact_person', 'phone', 'email'], $object->getFields()); | ||
|
||
$this->assertNull($object->get('www')); | ||
|
||
$object->set('contact_person', 'John Doe'); | ||
$this->assertNotEmpty($object->build()); | ||
$object->set('phone', '040123456'); | ||
$this->assertNotEmpty($object->build()); | ||
$object->set('email', '[email protected]'); | ||
$this->assertNotEmpty($object->build()); | ||
} | ||
|
||
/** | ||
* Tests invalid field name. | ||
* | ||
|
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