Skip to content
Snippets Groups Projects
Commit b41137a7 authored by Kristiaan Van den Eynde's avatar Kristiaan Van den Eynde
Browse files

Issue #3447592: Add GitLab CI

parent 9c69529c
No related branches found
No related tags found
1 merge request!2Initial stab at this
Pipeline #174318 passed
# Not copying all comments from template, original found here:
# https://git.drupalcode.org/project/gitlab_templates/-/blob/1.0.x/gitlab-ci/template.gitlab-ci.yml
include:
- project: $_GITLAB_TEMPLATES_REPO
ref: 'main'
file:
- '/includes/include.drupalci.main.yml'
- '/includes/include.drupalci.variables.yml'
- '/includes/include.drupalci.workflows.yml'
variables:
SKIP_ESLINT: '1'
OPT_IN_TEST_MAX_PHP: '1'
OPT_IN_TEST_NEXT_MINOR: '1'
_CURL_TEMPLATES_REF: 'main'
......@@ -20,5 +20,8 @@
"drupal/group": "^2 || ^3",
"drupal/domain": "^2",
"drupal/core": "^9.5 || ^10 || ^11"
},
"require-dev": {
"jangregor/phpstan-prophecy": "^1.0"
}
}
......@@ -6,6 +6,7 @@
*/
use Drupal\Core\Cache\CacheableMetadata;
use Drupal\Core\Entity\EntityForm;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\domain\DomainInterface;
......@@ -42,7 +43,10 @@ function group_context_domain_form_domain_form_alter(&$form, FormStateInterface
$options[$group->uuid()] = $group->label();
}
$domain = $form_state->getFormObject()->getEntity();
$form_object = $form_state->getFormObject();
assert($form_object instanceof EntityForm);
$domain = $form_object->getEntity();
assert($domain instanceof DomainInterface);
$form['group_uuid'] = [
......@@ -74,7 +78,13 @@ function _group_context_domain_save_group_uuid($entity_type, $entity, &$form, Fo
* Form validate handler.
*/
function _group_context_domain_validate_group_uuid(&$form, FormStateInterface $form_state) {
$violations = $form_state->getFormObject()->getEntity()->getTypedData()->validate();
$form_object = $form_state->getFormObject();
assert($form_object instanceof EntityForm);
$domain = $form_object->getEntity();
assert($domain instanceof DomainInterface);
$violations = $domain->getTypedData()->validate();
foreach ($violations as $violation) {
assert($violation instanceof ConstraintViolation);
if ($violation->getConstraint() instanceof DomainGroupUnique) {
......
parameters:
level: 2
ignoreErrors:
# new static() is a best practice in Drupal, so we cannot fix that.
- "#^Unsafe usage of new static#"
......@@ -25,7 +25,7 @@ class DomainGroupUniqueValidator extends ConstraintValidator implements Containe
*/
public function __construct(
protected EntityTypeManagerInterface $entityTypeManager,
protected EntityRepositoryInterface $entityRepository
protected EntityRepositoryInterface $entityRepository,
) {
}
......
......@@ -18,7 +18,7 @@ class DomainGroupUniqueValidatorTest extends GroupContextDomainKernelTestBase {
public function testConstraint(): void {
// Save a domain without a group assigned.
$control = $this->createDomain();
$this->assertSame(0, $control->getTypedData()->validate()->count());
$this->assertCount(0, $control->getTypedData()->validate());
// Create two groups and assign them to two different domains.
$group_type = $this->createGroupType();
......@@ -26,13 +26,13 @@ class DomainGroupUniqueValidatorTest extends GroupContextDomainKernelTestBase {
$group_b = $this->createGroup(['type' => $group_type->id()]);
$domain_a = $this->createDomain(['third_party_settings' => ['group_context_domain' => ['group_uuid' => $group_a->uuid()]]]);
$domain_b = $this->createDomain(['third_party_settings' => ['group_context_domain' => ['group_uuid' => $group_b->uuid()]]]);
$this->assertSame(0, $domain_a->getTypedData()->validate()->count());
$this->assertSame(0, $domain_b->getTypedData()->validate()->count());
$this->assertCount(0, $domain_a->getTypedData()->validate());
$this->assertCount(0, $domain_b->getTypedData()->validate());
// Now try to assign one of these groups to another domain.
$domain_c = $this->createDomain(['third_party_settings' => ['group_context_domain' => ['group_uuid' => $group_a->uuid()]]]);
$violations = $domain_c->getTypedData()->validate();
$this->assertSame(1, $violations->count());
$this->assertCount(1, $violations);
$this->assertEquals(
new TranslatableMarkup(
'The %group_label group is already tied to another domain.',
......
......@@ -99,7 +99,7 @@ class GroupFromDomainContextTest extends GroupContextDomainKernelTestBase {
}
/**
* Tests getting the available conexts.
* Tests getting the available contexts.
*
* @covers ::getAvailableContexts
*/
......
......@@ -24,14 +24,14 @@ class DomainGroupCacheContextTest extends UnitTestCase {
/**
* The mocked domain negotiator service.
*
* @var \Drupal\domain\DomainNegotiatorInterface|\Prophecy\Prophecy\ObjectProphecy
* @var \Prophecy\Prophecy\ObjectProphecy<\Drupal\domain\DomainNegotiatorInterface>
*/
protected $domainNegotiator;
/**
* The mocked entity repository service.
*
* @var \Drupal\Core\Entity\EntityRepositoryInterface|\Prophecy\Prophecy\ObjectProphecy
* @var \Prophecy\Prophecy\ObjectProphecy<\Drupal\Core\Entity\EntityRepositoryInterface>
*/
protected $entityRepository;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment