Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
110 commits
Select commit Hold shift + click to select a range
9695863
Adding gitignore
simon-peacock Nov 6, 2018
000b61c
Updating travis file
simon-peacock Nov 6, 2018
bba365b
Updating travis file
simon-peacock Nov 6, 2018
363d28c
Updating travis file
simon-peacock Nov 6, 2018
c91d435
Ading composer file
simon-peacock Nov 6, 2018
87d0e5e
Updating travis
simon-peacock Nov 6, 2018
b9b97ea
Updating travis
simon-peacock Nov 6, 2018
53506b8
Updating travis
simon-peacock Nov 6, 2018
1d5f3bd
Updating travis
simon-peacock Nov 6, 2018
136ebb1
Updating travis
simon-peacock Nov 6, 2018
87daccf
Updating travis file
simon-peacock Nov 6, 2018
4ee5bba
Updating travis file
simon-peacock Nov 6, 2018
0102f21
Updating travis file
simon-peacock Nov 6, 2018
06e5df3
Updating travis file
simon-peacock Nov 6, 2018
eb7e05c
Updating travis file
simon-peacock Nov 6, 2018
2fd10ae
Adding sonar project
simon-peacock Nov 6, 2018
70323a6
Adding sonar project
simon-peacock Nov 6, 2018
877688d
Adding sonar project
simon-peacock Nov 6, 2018
c0b1737
Adding sonar project
simon-peacock Nov 6, 2018
bc65d0c
Updating README
simon-peacock Nov 6, 2018
a31f685
Making test fail
simon-peacock Nov 6, 2018
064a519
Adding circleci config
simon-peacock Nov 7, 2018
222dd6b
Updating circleci config
simon-peacock Nov 7, 2018
849fb34
Adding Jenkinsfile
simon-peacock Nov 8, 2018
435a27a
Adding Jenkinsfile
simon-peacock Nov 8, 2018
1bf243e
Updaing Jenkinsfile
simon-peacock Nov 8, 2018
3427004
Updaing Jenkinsfile
simon-peacock Nov 8, 2018
e62a25b
Updaing Jenkinsfile
simon-peacock Nov 8, 2018
2265717
Updaing Jenkinsfile
simon-peacock Nov 8, 2018
71fd321
Updaing Jenkinsfile
simon-peacock Nov 8, 2018
d2bfff3
Updaing Jenkinsfile
simon-peacock Nov 8, 2018
216a039
Updaing Jenkinsfile
simon-peacock Nov 8, 2018
a77d044
Updaing Jenkinsfile
simon-peacock Nov 8, 2018
0944d35
Updaing Jenkinsfile
simon-peacock Nov 8, 2018
184ef81
Updaing Jenkinsfile
simon-peacock Nov 8, 2018
6268b57
Updaing Jenkinsfile
simon-peacock Nov 8, 2018
24da6d5
Updaing Jenkinsfile
simon-peacock Nov 8, 2018
8ad8091
Updaing Jenkinsfile
simon-peacock Nov 8, 2018
a33c276
Updaing Jenkinsfile
simon-peacock Nov 8, 2018
cab574b
Updaing Jenkinsfile
simon-peacock Nov 8, 2018
4848f33
Updaing Jenkinsfile
simon-peacock Nov 8, 2018
2b664f5
Updaing Jenkinsfile
simon-peacock Nov 8, 2018
787f669
Updaing Jenkinsfile
simon-peacock Nov 8, 2018
84e67df
Updaing Jenkinsfile
simon-peacock Nov 8, 2018
eca6003
Updaing Jenkinsfile
simon-peacock Nov 8, 2018
058d00c
Updating JenkinsFile
simon-peacock Nov 8, 2018
5098988
Updating JenkinsFile
simon-peacock Nov 8, 2018
e049078
Updating JenkinsFile
simon-peacock Nov 8, 2018
41f8dff
Updating Jenkins
simon-peacock Nov 8, 2018
22cb94d
Updating Jenkins
simon-peacock Nov 8, 2018
df168cc
Updating Jenkins
simon-peacock Nov 8, 2018
e8c1f87
Updating Jenkins
simon-peacock Nov 8, 2018
448d4f6
Updating Jenkins
simon-peacock Nov 8, 2018
625d383
Updating Jenkins
simon-peacock Nov 8, 2018
77a95f8
Updating Jenkins
simon-peacock Nov 8, 2018
e271d4e
Updating Jenkinsfile
simon-peacock Nov 8, 2018
44a555c
Updating Jenkinsfile
simon-peacock Nov 8, 2018
c09cab7
Updating Jenkinsfile
simon-peacock Nov 8, 2018
3bf92ab
Updating Jenkinsfile
simon-peacock Nov 9, 2018
9e6a92e
Updating Jenkinsfile
simon-peacock Nov 9, 2018
1065b04
Updating Jenkinsfile
simon-peacock Nov 9, 2018
af0e2cd
Updating Jenkinsfile
simon-peacock Nov 9, 2018
75db74d
Updating sonarfile
simon-peacock Nov 9, 2018
e2eb354
Updating sonarfile
simon-peacock Nov 9, 2018
eee26d1
Updating sonarfile
simon-peacock Nov 9, 2018
d49effc
Updating sonarfile
simon-peacock Nov 9, 2018
b87f995
Updating sonarfile
simon-peacock Nov 9, 2018
8b34c13
Updating sonarfile
simon-peacock Nov 9, 2018
64ac7d3
Ading files just for testing
simon-peacock Nov 9, 2018
d980d54
Updating Jenkinsfile
simon-peacock Nov 9, 2018
7f63fe2
Updating sonar
simon-peacock Nov 9, 2018
f0431d6
Updating jenkinsfile
simon-peacock Nov 9, 2018
1ad3f9a
Updating Jenkinsfile
simon-peacock Nov 9, 2018
f923bdd
Updaing Jenkinsfile
simon-peacock Nov 9, 2018
6e837f6
Updaing Jenkinsfile
simon-peacock Nov 9, 2018
22a4111
Updaing Jenkinsfile
simon-peacock Nov 9, 2018
8425a00
Updating sonar and Jenkins file
simon-peacock Nov 9, 2018
043697b
Updating Jenkinsfile
simon-peacock Nov 9, 2018
f19de53
Updating Jenkinsfile
simon-peacock Nov 12, 2018
a62bfbc
Updating Jenkinsfile
simon-peacock Nov 12, 2018
4f600fc
Updating Jenkinsfile
simon-peacock Nov 12, 2018
f378e07
Updating Jenkinsfile
simon-peacock Nov 12, 2018
0b6b201
Updating Jenkinsfile
simon-peacock Nov 12, 2018
9ce1476
Updating Jenkinsfile
simon-peacock Nov 12, 2018
f4e1045
Updating Jenkinsfile
simon-peacock Nov 12, 2018
effc9c5
Updating Jenkinsfile
simon-peacock Nov 12, 2018
b6bf72b
Updating Jenkinsfile
simon-peacock Nov 12, 2018
6f76cde
Updating Jenkinsfile
simon-peacock Nov 12, 2018
b27f2b7
Updating Jenkinsfile
simon-peacock Nov 12, 2018
885c5a9
Updating Jenkinsfile
simon-peacock Nov 12, 2018
98a36a8
Updating Jenkinsfile
simon-peacock Nov 12, 2018
1bf1cd0
Updating Jenkinsfile
simon-peacock Nov 12, 2018
9fc339b
Updating Jenkinsfile
simon-peacock Nov 12, 2018
82a42f8
Updating Jenkinsfile
simon-peacock Nov 12, 2018
013c9f7
Updating Jenkinsfile
simon-peacock Nov 12, 2018
d532a5c
Updating Jenkinsfile
simon-peacock Nov 12, 2018
c75392e
Updating Jenkinsfile
simon-peacock Nov 12, 2018
7725f6b
Updating Jenkinsfile
simon-peacock Nov 12, 2018
ff6316b
Updating Jenkinsfile
simon-peacock Nov 12, 2018
0e2b6ab
Updating Jenkinsfile
simon-peacock Nov 12, 2018
f92ddfd
Updating Jenkinsfile
simon-peacock Nov 12, 2018
4cea5f0
Updating Jenkinsfile
simon-peacock Nov 12, 2018
64a9c5e
Updating Jenkinsfile
simon-peacock Nov 12, 2018
5dd0500
Updating Jenkinsfile to use global libraries
simon-peacock Nov 13, 2018
60cdd6d
Updating function call
simon-peacock Nov 13, 2018
1bb3d89
Updating Jenkinsfile
simon-peacock Nov 13, 2018
5a7f506
Updating script
simon-peacock Nov 13, 2018
786c491
Updating pipeline
simon-peacock Nov 13, 2018
ead29c3
Updating Jenkinsfile
simon-peacock Nov 13, 2018
05152ff
Updating Jenkinsfile
simon-peacock Nov 13, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# PHP CircleCI 2.0 configuration file
#
# Check https://circleci.com/docs/2.0/language-php/ for more details
#
version: 2
jobs:
build:
docker:
# specify the version you desire here
- image: circleci/php:7.1-browsers

# Specify service dependencies here if necessary
# CircleCI maintains a library of pre-built images
# documented at https://circleci.com/docs/2.0/circleci-images/
# - image: circleci/mysql:9.4

working_directory: ~/repo

steps:
- checkout

# Download and cache dependencies
- restore_cache:
keys:
- v1-dependencies-{{ checksum "composer.json" }}
# fallback to using the latest cache if no exact match is found
- v1-dependencies-

- run: composer install -n --prefer-dist

- save_cache:
paths:
- ./vendor
key: v1-dependencies-{{ checksum "composer.json" }}

# run tests!
- run: phpunit

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.idea/
63 changes: 9 additions & 54 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,61 +1,16 @@
language: php

sudo: false

addons:
apt:
packages:
- libxml2-utils

php:
- 7.1
- 7.2
- 7.3
- master

matrix:
allow_failures:
- php: master
fast_finish: true

env:
matrix:
- DEPENDENCIES="high"
- DEPENDENCIES="low"
global:
- DEFAULT_COMPOSER_FLAGS="--no-interaction --no-ansi --no-progress --no-suggest"
- '7.1'

before_install:
- ./build/tools/composer clear-cache
addons:
sonarcloud:
organization: "simon-peacock-github"
token:
secure: "secure-string=666f24e3ccd30b982a2e1a78b4517210c2cf412b"

install:
- if [[ "$DEPENDENCIES" = 'high' ]]; then travis_retry ./build/tools/composer update $DEFAULT_COMPOSER_FLAGS; fi
- if [[ "$DEPENDENCIES" = 'low' ]]; then travis_retry ./build/tools/composer update $DEFAULT_COMPOSER_FLAGS --prefer-lowest; fi

before_script:
- echo 'zend.assertions=1' >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini
- echo 'assert.exception=On' >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini

- composer create-project drupal-composer/drupal-project:8.x-dev drupal --stability dev --no-interaction
- mkdir -p drupal/web/modules/${PWD##*/} && cp -a ${PWD##*/}* tests src drupal/web/modules/${PWD##*/}
script:
- ./phpunit --coverage-clover=coverage.xml
- ./phpunit --configuration ./build/travis-ci-fail.xml > /dev/null; if [ $? -eq 0 ]; then echo "SHOULD FAIL"; false; else echo "fail checked"; fi;
- xmllint --noout --schema phpunit.xsd phpunit.xml
- xmllint --noout --schema phpunit.xsd tests/_files/configuration.xml
- xmllint --noout --schema phpunit.xsd tests/_files/configuration_empty.xml
- xmllint --noout --schema phpunit.xsd tests/_files/configuration_xinclude.xml -xinclude

after_success:
- bash <(curl -s https://codecov.io/bash)

notifications:
email: false
- drupal/vendor/bin/phpunit -c drupal/web/core drupal/web/modules/${PWD##*/}/tests/

jobs:
include:
- stage: Static Code Analysis
php: 7.2
env: php-cs-fixer
install:
- phpenv config-rm xdebug.ini
script:
- ./build/tools/php-cs-fixer fix --dry-run -v --show-progress=dots --diff-format=udiff
7 changes: 7 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env groovy
// Repository can be found at https://github.com/dennisinteractive/lightning-jenkins-build-scripts
// Required Library call
@Library('lightning-shared-libraries@master') _

// CAll Drupal unit test
drupalUnitTest()
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
# phpunit_example
[![Build Status](https://travis-ci.org/simon-peacock/phpunit_example.svg?branch=master)](https://travis-ci.org/simon-peacock/phpunit_example)
16 changes: 16 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "drupal/phpunit_example",
"type": "drupal-module",
"description": "Allow a term to be configured to show the content on a referenced node rather than the default term view.",
"keywords": ["Drupal", "Term", "phpunit"],
"license": "GPL-2.0+",
"homepage": "https://www.drupal.org/project/term_node",
"minimum-stability": "dev",
"support": {
"issues": "https://www.drupal.org/project/issues/term_node",
"source": "http://cgit.drupalcode.org/term_node"
},
"require": {
"phpunit/phpunit": "7.x"
}
}
13 changes: 13 additions & 0 deletions sonar-project.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
sonar.projectKey=phpunit_example
sonar.projectName=phpunit example
sonar.links.homepage=https://github.com/simon-peacock/phpunit_example

sonar.sources=src
sonar.exclusions=**drupal**
sonar.host.url=http://ec2-34-255-179-73.eu-west-1.compute.amazonaws.com:9000
sonar.verbose=false
sonar.sourceEncoding=UTF-8
sonar.pullrequest.provider=github

sonar.dependencyCheck.reportPath=dependency-check-report.xml
sonar.dependencyCheck.htmlReportPath=dependency-check-report.html
55 changes: 55 additions & 0 deletions src/ContentPartnershipKickerBuilder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

namespace Drupal\dennis_kicker;

use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;

/**
* Class ContentPartnershipKickerBuilder.
*
* @package Drupal\dennis_kicker
*/
class ContentPartnershipKickerBuilder implements KickerBuilderInterface {

/**
* The entity type manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;

/**
* ContentPartnershipKickerBuilder constructor.
*
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager.
*/
public function __construct(EntityTypeManagerInterface $entity_type_manager) {
$this->entityTypeManager = $entity_type_manager;
}

/**
* {@inheritdoc}
*/
public function build(KickerInterface $kicker, ContentEntityInterface $entity, EntityViewDisplayInterface $display, $view_mode) {
// If it is tagged with a term from the Content Partnerships taxonomy,
// then that term is displayed.
if ($entity->hasField('field_sponsored')) {
if ($reference = $entity->get('field_sponsored')->first()) {
$term = $this->entityTypeManager->getStorage('taxonomy_term')
->load($reference->getString());
if ($term) {
// A Content Partnerships term,
// then use it as the kicker but with no path.
$kicker
->setEntity($term)
->setText($term->getName())
->setBuilt();
}
}
}
}

}
156 changes: 156 additions & 0 deletions src/DefaultKickerBuilder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
<?php

namespace Drupal\dennis_kicker;

use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\ParamConverter\ParamNotConvertedException;
use Drupal\Core\PathProcessor\InboundPathProcessorInterface;
use Drupal\Core\Routing\RouteMatch;
use Drupal\term_node\NodeResolverInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
use Symfony\Component\Routing\Exception\MethodNotAllowedException;
use Symfony\Component\Routing\Exception\ResourceNotFoundException;
use Symfony\Component\Routing\Matcher\RequestMatcherInterface;

/**
* Class DefaultKickerBuilder.
*
* @package Drupal\dennis_kicker
*/
class DefaultKickerBuilder implements KickerBuilderInterface {

/**
* The entity type manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;

/**
* The dynamic router service.
*
* @var \Symfony\Component\Routing\Matcher\RequestMatcherInterface
*/
protected $router;

/**
* The inbound path processor.
*
* @var \Drupal\Core\PathProcessor\InboundPathProcessorInterface
*/
protected $pathProcessor;

/**
* The service from term_node to get the tid of the referencing term.
*
* @var \Drupal\term_node\NodeResolverInterface
*/
protected $nodeResolver;

/**
* DefaultKickerBuilder constructor.
*
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager.
* @param \Symfony\Component\Routing\Matcher\RequestMatcherInterface $router
* The dynamic router service.
* @param \Drupal\Core\PathProcessor\InboundPathProcessorInterface $path_processor
* The inbound path processor.
* @param \Drupal\term_node\NodeResolverInterface $node_resolver
* The term_node resolver.
*/
public function __construct(
EntityTypeManagerInterface $entity_type_manager,
RequestMatcherInterface $router,
InboundPathProcessorInterface $path_processor,
NodeResolverInterface $node_resolver) {
$this->entityTypeManager = $entity_type_manager;
$this->router = $router;
$this->pathProcessor = $path_processor;
$this->nodeResolver = $node_resolver;
}

/**
* {@inheritdoc}
*/
public function build(KickerInterface $kicker, ContentEntityInterface $entity, EntityViewDisplayInterface $display, $view_mode) {
// The term used for the kicker should follow the same logic
// that we use for the breadcrumb/paths.
// It is the last entity that is in the path that should be used.
// NB: Cannot use the breadcrumb as it always builds the current page.
$path_elements = explode('/', $entity->toUrl()->toString());
while (count($path_elements) > 1) {
array_pop($path_elements);
// Build a request for the path.
$route_request = $this->getRequestForPath(implode('/', $path_elements));
if ($route_request) {
$route_match = RouteMatch::createFromRequest($route_request);
foreach ($route_match->getParameters() as $entity) {
if ($entity instanceof EntityInterface) {

// If the entity is a node, it may be a term node,
// in which case we want to use the term's label not the node's.
if ($entity->getEntityTypeId() == 'node' && $tid = $this->nodeResolver->getReferencedBy($entity->id())) {
$entity = $this->entityTypeManager->getStorage('taxonomy_term')
->load($tid);
}

$kicker->setEntity($entity)
->setText($entity->label())
->setUrl($entity->toUrl())
->setBuilt();
// Found the last entity, so do no more.
return;
}
}
}
}
}

/**
* Matches a path in the router.
*
* Shameless copy of core/modules/system/src/PathBasedBreadcrumbBuilder.php.
*
* @param string $path
* The request path with a leading slash.
*
* @return \Symfony\Component\HttpFoundation\Request
* A populated request object or NULL if the path couldn't be matched.
*/
protected function getRequestForPath($path) {
$request = Request::create($path);
// Performance optimization: set a short accept header to reduce overhead in
// AcceptHeaderMatcher when matching the request.
$request->headers->set('Accept', 'text/html');
// Find the system path by resolving aliases, language prefix, etc.
$processed = $this->pathProcessor->processInbound($path, $request);
if (empty($processed) || !empty($exclude[$processed])) {
// This resolves to the front page.
return NULL;
}

// Attempt to match this path to provide a fully built request.
try {
$request->attributes->add($this->router->matchRequest($request));
return $request;
}
catch (ParamNotConvertedException $e) {
return NULL;
}
catch (ResourceNotFoundException $e) {
return NULL;
}
catch (MethodNotAllowedException $e) {
return NULL;
}
catch (AccessDeniedHttpException $e) {
return NULL;
}
}

}
Loading