Browse Source

Add travis config and clean up to coding standards (#12)

* Clean up to Drupal coding standards

Add travis config

* Remove codesniffer from travis-setup.sh

* Not needed right now and breaks php on hhvm

* Deleted too much

* Revert type hinting.
pull/756/head
Jared Whiklo 8 years ago committed by dannylamb
parent
commit
38747f1cfd
  1. 39
      .travis.yml
  2. 34
      composer.json
  3. 2
      fedora_resource.page.inc
  4. 2
      islandora.module
  5. 34
      src/Controller/FedoraResourceAddController.php
  6. 43
      src/Entity/FedoraResource.php
  7. 4
      src/FedoraResourceHtmlRouteProvider.php
  8. 10
      src/FedoraResourceInterface.php
  9. 10
      src/FedoraResourceViewBuilder.php
  10. 17
      src/Form/FedoraResourceEntityInlineForm.php
  11. 6
      src/Form/IslandoraSettingsForm.php
  12. 22
      src/ParamConverter/UuidEntityConverter.php
  13. 9
      src/Plugin/Search/FedoraEntitySearch.php
  14. 14
      tests/scripts/line_endings.sh
  15. 81
      tests/scripts/travis_setup.sh

39
.travis.yml

@ -0,0 +1,39 @@
sudo: true
language: php
php:
- 5.5
- 5.6
- 7.0
- hhvm
matrix:
allow_failures:
- php: hhvm
fast_finish: true
branches:
only:
- /^8.x/
before_install:
- export ISLANDORA_DIR=$TRAVIS_BUILD_DIR
install:
# - $TRAVIS_BUILD_DIR/tests/scripts/travis_setup.sh
- composer install
- php vendor/bin/phpcs --config-set installed_paths vendor/drupal/coder/coder_sniffer
script:
- $ISLANDORA_DIR/tests/scripts/line_endings.sh .
- php vendor/bin/phpcs --standard=Drupal *.module src
- php vendor/bin/phpcpd --names *.module,*.inc,*.test,*.php --exclude=vendor .
notifications:
irc:
channels:
- "irc.freenode.org#islandora"
on_success: change
on_failure: always
skip_join: true

34
composer.json

@ -0,0 +1,34 @@
{
"name": "drupal/islandora",
"description": "A client for interacting with a Fedora 4 server using CLAW microservices.",
"type": "drupal-module",
"homepage": "https://github.com/islandora-claw/islandora",
"support": {
"issues": "https://github.com/islandora-claw/CLAW/issues",
"irc": "irc://irc.freenode.net/islandora"
},
"require-dev": {
"phpunit/phpunit": "^4.8",
"drupal/coder": "*",
"sebastian/phpcpd": "*"
},
"license": "GPL-2.0+",
"authors": [
{
"name": "Islandora Foundation",
"email": "community@islandora.ca",
"role": "Owner"
},
{
"name": "Daniel Lamb",
"email": "dlamb@islandora.ca",
"role": "Maintainer"
},
{
"name": "Diego Pino",
"email": "dpino@krayon.cl",
"role": "Maintainer"
}
]
}

2
fedora_resource.page.inc

@ -14,8 +14,8 @@
* file that was distributed with this source code. * file that was distributed with this source code.
* *
* @author Diego Pino Navarro <dpino@metro.org> https://github.com/diegopino * @author Diego Pino Navarro <dpino@metro.org> https://github.com/diegopino
*
*/ */
use Drupal\Core\Render\Element; use Drupal\Core\Render\Element;
use Drupal\Core\Link; use Drupal\Core\Link;
use Drupal\Core\Url; use Drupal\Core\Url;

2
islandora.module

@ -25,7 +25,7 @@ function islandora_help($route_name, RouteMatchInterface $route_match) {
case 'help.page.islandora': case 'help.page.islandora':
$output = ''; $output = '';
$output .= '<h3>' . t('About') . '</h3>'; $output .= '<h3>' . t('About') . '</h3>';
$output .= '<p>' . t('') . '</p>'; $output .= '<p>' . t('This is a placeholder for future help text about Islandora.') . '</p>';
return $output; return $output;
default: default:

34
src/Controller/FedoraResourceAddController.php

@ -4,13 +4,11 @@ namespace Drupal\islandora\Controller;
use Drupal\Core\Controller\ControllerBase; use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Entity\EntityStorageInterface; use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Url; use Drupal\Core\Url;
use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
/** /**
* Class FedoraResourceAddController. * Class FedoraResourceAddController.
* *
@ -18,6 +16,28 @@ use Symfony\Component\HttpFoundation\Request;
*/ */
class FedoraResourceAddController extends ControllerBase { class FedoraResourceAddController extends ControllerBase {
/**
* The Entity storage.
*
* @var \Drupal\Core\Entity\EntityStorageInterface
*/
protected $storage;
/**
* The Entity storage type.
*
* @var \Drupal\Core\Entity\EntityStorageInterface
*/
protected $typeStorage;
/**
* FedoraResourceAddController constructor.
*
* @param \Drupal\Core\Entity\EntityStorageInterface $storage
* The Entity storage.
* @param \Drupal\Core\Entity\EntityStorageInterface $type_storage
* The Entity storage type.
*/
public function __construct(EntityStorageInterface $storage, EntityStorageInterface $type_storage) { public function __construct(EntityStorageInterface $storage, EntityStorageInterface $type_storage) {
$this->storage = $storage; $this->storage = $storage;
$this->typeStorage = $type_storage; $this->typeStorage = $type_storage;
@ -34,6 +54,7 @@ class FedoraResourceAddController extends ControllerBase {
$entity_type_manager->getStorage('fedora_resource_type') $entity_type_manager->getStorage('fedora_resource_type')
); );
} }
/** /**
* Displays add links for available bundles/types for entity fedora_resource. * Displays add links for available bundles/types for entity fedora_resource.
* *
@ -41,8 +62,9 @@ class FedoraResourceAddController extends ControllerBase {
* The current request object. * The current request object.
* *
* @return array * @return array
* A render array for a list of the fedora_resource bundles/types that can be added or * A render array for a list of the fedora_resource bundles/types that can
* if there is only one type/bunlde defined for the site, the function returns the add page for that bundle/type. * be added or if there is only one type/bunlde defined for the site, the
* function returns the add page for that bundle/type.
*/ */
public function add(Request $request) { public function add(Request $request) {
$types = $this->typeStorage->loadMultiple(); $types = $this->typeStorage->loadMultiple();
@ -62,7 +84,7 @@ class FedoraResourceAddController extends ControllerBase {
} }
/** /**
* Presents the creation form for fedora_resource entities of given bundle/type. * Presents the creation form for fedora_resource entities of given type.
* *
* @param EntityInterface $fedora_resource_type * @param EntityInterface $fedora_resource_type
* The custom bundle to add. * The custom bundle to add.
@ -74,7 +96,7 @@ class FedoraResourceAddController extends ControllerBase {
*/ */
public function addForm(EntityInterface $fedora_resource_type, Request $request) { public function addForm(EntityInterface $fedora_resource_type, Request $request) {
$entity = $this->storage->create(array( $entity = $this->storage->create(array(
'type' => $fedora_resource_type->id() 'type' => $fedora_resource_type->id(),
)); ));
return $this->entityFormBuilder()->getForm($entity); return $this->entityFormBuilder()->getForm($entity);
} }

43
src/Entity/FedoraResource.php

@ -70,13 +70,23 @@ class FedoraResource extends ContentEntityBase implements FedoraResourceInterfac
use EntityChangedTrait; use EntityChangedTrait;
/** /**
* Override this to have a rel ='uuid' for islandora entities.
*
* Stolen (but not inherited from EntityInterface)
*
* @param string $rel * @param string $rel
* The link relationship type, for example: canonical or edit-form.
* @param array $options * @param array $options
* @return $this|\Drupal\Core\Url * See \Drupal\Core\Routing\UrlGeneratorInterface::generateFromRoute() for
* the available options.
*
* @return \Drupal\Core\Url
* The URL object.
*/ */
public function toUrl($rel = 'canonical', array $options = []) { public function toUrl($rel = 'canonical', array $options = []) {
// TODO: I Will override this to have a rel ='uuid' for islandora entities // TODO: I Will override this to have a rel ='uuid' for islandora entities
return parent::toUrl($rel, $options); // TODO: Change the autogenerated stub // TODO: Change the autogenerated stub.
return parent::toUrl($rel, $options);
} }
/** /**
@ -92,7 +102,8 @@ class FedoraResource extends ContentEntityBase implements FedoraResourceInterfac
* An array of URI placeholders. * An array of URI placeholders.
*/ */
protected function urlRouteParameters($rel) { protected function urlRouteParameters($rel) {
$uri_route_parameters = parent::urlRouteParameters($rel); // TODO: Change the autogenerated stub // TODO: Change the autogenerated stub.
$uri_route_parameters = parent::urlRouteParameters($rel);
if ($rel === 'uuid') { if ($rel === 'uuid') {
$uri_route_parameters[$this->getEntityTypeId()] = $this->uuid(); $uri_route_parameters[$this->getEntityTypeId()] = $this->uuid();
} }
@ -100,7 +111,6 @@ class FedoraResource extends ContentEntityBase implements FedoraResourceInterfac
} }
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
@ -118,8 +128,8 @@ class FedoraResource extends ContentEntityBase implements FedoraResourceInterfac
parent::postSave($storage, $update); parent::postSave($storage, $update);
// Reindex the entity when it is updated. The entity is automatically // Reindex the entity when it is updated. The entity is automatically
// indexed when it is added, simply by being added to the {fedora_resource} table. // indexed when it is added, simply by being added to the {fedora_resource}
// Only required if using the core search index. // table. Only required if using the core search index.
if ($update) { if ($update) {
if (\Drupal::moduleHandler()->moduleExists('search')) { if (\Drupal::moduleHandler()->moduleExists('search')) {
search_mark_for_reindex('fedora_resource_search', $this->id()); search_mark_for_reindex('fedora_resource_search', $this->id());
@ -208,32 +218,32 @@ class FedoraResource extends ContentEntityBase implements FedoraResourceInterfac
$this->set('status', $published ? NODE_PUBLISHED : NODE_NOT_PUBLISHED); $this->set('status', $published ? NODE_PUBLISHED : NODE_NOT_PUBLISHED);
return $this; return $this;
} }
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function hasParent() public function hasParent() {
{ return ($this->get('fedora_has_parent') !== NULL);
return ($this->get('fedora_has_parent') !== null);
} }
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function getParent() public function getParent() {
{
return $this->get('fedora_has_parent')->getEntity(); return $this->get('fedora_has_parent')->getEntity();
} }
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function getParentId() public function getParentId() {
{
return $this->get('fedora_has_parent')->getEntity()->id(); return $this->get('fedora_has_parent')->getEntity()->id();
} }
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function setParent(EntityTypeInterface $entity) public function setParent(EntityTypeInterface $entity) {
{
$this->set('fedora_has_parent', $entity); $this->set('fedora_has_parent', $entity);
return $this; return $this;
} }
@ -247,11 +257,10 @@ class FedoraResource extends ContentEntityBase implements FedoraResourceInterfac
* An array of default values. * An array of default values.
*/ */
public static function getFedoraRoot() { public static function getFedoraRoot() {
// Just stub code, we need to figure out what "root is" in this context // Just stub code, we need to figure out what "root is" in this context.
return array('root'); return array('root');
} }
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */

4
src/FedoraResourceHtmlRouteProvider.php

@ -44,11 +44,11 @@ class FedoraResourceHtmlRouteProvider extends AdminHtmlRouteProvider implements
$collection->add("entity.{$entity_type_id}.uuid", $uuid_route); $collection->add("entity.{$entity_type_id}.uuid", $uuid_route);
} }
return $collection; return $collection;
} }
/** Gets the UUID route. /**
* Gets the UUID route.
* *
* @param \Drupal\Core\Entity\EntityTypeInterface $entity_type * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
* The entity type. * The entity type.

10
src/FedoraResourceInterface.php

@ -14,8 +14,6 @@ use Drupal\user\EntityOwnerInterface;
*/ */
interface FedoraResourceInterface extends ContentEntityInterface, EntityChangedInterface, EntityOwnerInterface { interface FedoraResourceInterface extends ContentEntityInterface, EntityChangedInterface, EntityOwnerInterface {
// Add get/set methods for your configuration properties here.
/** /**
* Gets the Fedora resource type. * Gets the Fedora resource type.
* *
@ -76,7 +74,8 @@ interface FedoraResourceInterface extends ContentEntityInterface, EntityChangedI
* Sets the published status of a Fedora resource. * Sets the published status of a Fedora resource.
* *
* @param bool $published * @param bool $published
* TRUE to set this Fedora resource to published, FALSE to set it to unpublished. * TRUE to set this Fedora resource to published, FALSE to set it to
* unpublished.
* *
* @return \Drupal\islandora\FedoraResourceInterface * @return \Drupal\islandora\FedoraResourceInterface
* The called Fedora resource entity. * The called Fedora resource entity.
@ -110,11 +109,12 @@ interface FedoraResourceInterface extends ContentEntityInterface, EntityChangedI
/** /**
* Get the parent entity. * Get the parent entity.
* *
* @param \Drupal\islandora\FedoraResourceInterface $parent * @param \Drupal\Core\Entity\EntityTypeInterface $entity
* The parent entity * The parent entity.
* *
* @return \Drupal\islandora\FedoraResourceInterface * @return \Drupal\islandora\FedoraResourceInterface
* The called Fedora resource entity. * The called Fedora resource entity.
*/ */
public function setParent(EntityTypeInterface $entity); public function setParent(EntityTypeInterface $entity);
} }

10
src/FedoraResourceViewBuilder.php

@ -1,19 +1,11 @@
<?php <?php
/**
* Created by PhpStorm.
* User: dpino
* Date: 8/16/16
* Time: 11:49 PM
*/
namespace Drupal\islandora; namespace Drupal\islandora;
use Drupal\node\NodeViewBuilder; use Drupal\node\NodeViewBuilder;
/** /**
* Class FedoraResourceViewBuilder * Class FedoraResourceViewBuilder view builder handler.
* view builder handler.
* *
* @TODO this should manage how fedora_resource are build to be viewed. * @TODO this should manage how fedora_resource are build to be viewed.
* *

17
src/Form/FedoraResourceEntityInlineForm.php

@ -173,7 +173,8 @@ class FedoraResourceEntityInlineForm extends EntityInlineForm implements InlineF
foreach ($form_state->getErrors() as $name => $message) { foreach ($form_state->getErrors() as $name => $message) {
// $name may be unknown in $form_state and // $name may be unknown in $form_state and
// $form_state->setErrorByName($name, $message) may suppress the error message. // $form_state->setErrorByName($name, $message)
// may suppress the error message.
$form_state->setError($triggering_element, $message); $form_state->setError($triggering_element, $message);
} }
} }
@ -221,7 +222,12 @@ class FedoraResourceEntityInlineForm extends EntityInlineForm implements InlineF
// Invoke all specified builders for copying form values to entity fields. // Invoke all specified builders for copying form values to entity fields.
if (isset($entity_form['#entity_builders'])) { if (isset($entity_form['#entity_builders'])) {
foreach ($entity_form['#entity_builders'] as $function) { foreach ($entity_form['#entity_builders'] as $function) {
call_user_func_array($function, [$entity->getEntityTypeId(), $entity, &$entity_form, &$form_state]); call_user_func_array($function, [
$entity->getEntityTypeId(),
$entity,
&$entity_form,
&$form_state,
]);
} }
} }
} }
@ -232,11 +238,12 @@ class FedoraResourceEntityInlineForm extends EntityInlineForm implements InlineF
* After field_attach_submit() has run and the form has been closed, the form * After field_attach_submit() has run and the form has been closed, the form
* state still contains field data in $form_state->get('field'). Unless that * state still contains field data in $form_state->get('field'). Unless that
* data is removed, the next form with the same #parents (reopened add form, * data is removed, the next form with the same #parents (reopened add form,
* for example) will contain data (i.e. uploaded files) from the previous form. * for example) will contain data (i.e. uploaded files) from the previous
* form.
* *
* @param $entity_form * @param array $entity_form
* The entity form. * The entity form.
* @param $form_state * @param \Drupal\Core\Form\FormStateInterface $form_state
* The form state of the parent form. * The form state of the parent form.
*/ */
public static function submitCleanFormState(&$entity_form, FormStateInterface $form_state) { public static function submitCleanFormState(&$entity_form, FormStateInterface $form_state) {

6
src/Form/IslandoraSettingsForm.php

@ -1,9 +1,5 @@
<?php <?php
/**
* @file
* Settings form for Islandora.
*/
namespace Drupal\islandora\Form; namespace Drupal\islandora\Form;
use Drupal\Core\Form\ConfigFormBase; use Drupal\Core\Form\ConfigFormBase;
@ -86,5 +82,5 @@ class IslandoraSettingsForm extends ConfigFormBase {
parent::submitForm($form, $form_state); parent::submitForm($form, $form_state);
} }
}
}

22
src/ParamConverter/UuidEntityConverter.php

@ -1,25 +1,8 @@
<?php <?php
/**
* @file
* Contains UuidEntityConverter.php
*
* This file is part of the Islandora Project.
*
* (c) Islandora Foundation
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @author Diego Pino Navarro <dpino@metro.org> https://github.com/diegopino
*/
namespace Drupal\islandora\ParamConverter; namespace Drupal\islandora\ParamConverter;
use Drupal\Core\ParamConverter\EntityConverter; use Drupal\Core\ParamConverter\EntityConverter;
use Drupal\Core\ParamConverter\ParamConverterInterface;
use Drupal\Component\Uuid\Uuid;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\Routing\Route; use Symfony\Component\Routing\Route;
/** /**
@ -30,18 +13,17 @@ use Symfony\Component\Routing\Route;
class UuidEntityConverter extends EntityConverter { class UuidEntityConverter extends EntityConverter {
/** /**
* @inheritDoc * {@inheritdoc}
*/ */
public function convert($value, $definition, $name, array $defaults) { public function convert($value, $definition, $name, array $defaults) {
return $this->entityManager->loadEntityByUuid($name, $value); return $this->entityManager->loadEntityByUuid($name, $value);
} }
/** /**
* @inheritDoc * {@inheritdoc}
*/ */
public function applies($definition, $name, Route $route) { public function applies($definition, $name, Route $route) {
return (!empty($definition['type']) && $definition['type'] == 'uuid'); return (!empty($definition['type']) && $definition['type'] == 'uuid');
} }
} }

9
src/Plugin/Search/FedoraEntitySearch.php

@ -1,8 +1,4 @@
<? <?php
/**
* @file
* Contains \Drupal\islandora\Plugin\Search\FedoraEntitySearch.
*/
namespace Drupal\islandora\Plugin\Search; namespace Drupal\islandora\Plugin\Search;
@ -510,7 +506,7 @@ class FedoraResourceSearch extends ConfigurableSearchPluginBase implements Acces
/** /**
* Indexes a single contact. * Indexes a single contact.
* *
* @param \Drupal\content_entity_example\ContactInterface $entity * @param \Drupal\islandora\FedoraResourceInterface $entity
* The contact to index. * The contact to index.
*/ */
protected function indexFedoraResource(FedoraResourceInterface $entity) { protected function indexFedoraResource(FedoraResourceInterface $entity) {
@ -675,7 +671,6 @@ class FedoraResourceSearch extends ConfigurableSearchPluginBase implements Acces
$advanced = TRUE; $advanced = TRUE;
} }
// Advanced form, keywords fields. // Advanced form, keywords fields.
if ($form_state->getValue('or') != '') { if ($form_state->getValue('or') != '') {
if (preg_match_all('/ ("[^"]+"|[^" ]+)/i', ' ' . $form_state->getValue('or'), $matches)) { if (preg_match_all('/ ("[^"]+"|[^" ]+)/i', ' ' . $form_state->getValue('or'), $matches)) {

14
tests/scripts/line_endings.sh

@ -0,0 +1,14 @@
#!/bin/bash
RETURN=0
FILES=`find -L $1 -name "*.info" -o -name "*.txt" -o -name "*.md"`
echo "Testing for files with DOS line endings..."
for FILE in $FILES
do
file $FILE | grep CRLF
if [ $? == 0 ]
then
RETURN=1
fi
done
exit $RETURN

81
tests/scripts/travis_setup.sh

@ -0,0 +1,81 @@
#!/bin/bash
mysql -u root -e 'create database drupal;'
mysql -u root -e "GRANT ALL PRIVILEGES ON drupal.* To 'drupal'@'localhost' IDENTIFIED BY 'drupal';"
# Java (Oracle)
sudo apt-get install -y software-properties-common
sudo apt-get install -y python-software-properties
sudo add-apt-repository -y ppa:webupd8team/java
sudo apt-get update
echo debconf shared/accepted-oracle-license-v1-1 select true | sudo debconf-set-selections
echo debconf shared/accepted-oracle-license-v1-1 seen true | sudo debconf-set-selections
sudo apt-get install -y oracle-java8-installer
sudo update-java-alternatives -s java-8-oracle
sudo apt-get install -y oracle-java8-set-default
export JAVA_HOME=/usr/lib/jvm/java-8-oracle
# phpcpd
#sudo apt-get install -y phpcpd
cd $HOME
pear channel-discover pear.drush.org
pear upgrade --force Console_GetoptPlus
pear upgrade --force pear
pear channel-discover pear.drush.org
# Drush
cd /tmp
php -r "readfile('https://s3.amazonaws.com/files.drush.org/drush.phar');" > drush
php drush core-status
chmod +x drush
sudo mv drush /opt
sudo ln -s /opt/drush /usr/bin/drush
phpenv rehash
cd $HOME
drush dl drupal-8.2.2 --drupal-project-rename=drupal
cd $HOME/drupal
drush si minimal --db-url=mysql://drupal:drupal@localhost/drupal --yes
drush runserver --php-cgi=$HOME/.phpenv/shims/php-cgi localhost:8081 &>/tmp/drush_webserver.log &
ln -s $ISLANDORA_DIR modules/islandora
drush en -y rdf
drush en -y responsive_image
drush en -y syslog
drush en -y serialization
drush en -y basic_auth
drush en -y rest
drush dl rdfui --dev
drush en -y rdfui
drush en -y rdf_builder
drush dl restui
drush en -y restui
drush dl inline_entity_form
drush en -y inline_entity_form
drush dl media_entity
drush en -y media_entity
drush dl media_entity_image
drush en -y media_entity_image
drush dl search_api
drush -y pm-uninstall search
drush en -y search_api
cd $HOME/drupal/modules
git clone https://github.com/DiegoPino/claw-jsonld.git
drush en -y jsonld
drush -y dl bootstrap
drush -y en bootstrap
drush -y config-set system.theme default bootstrap
drush cr
# The shebang in this file is a bogeyman that is haunting the web test cases.
rm /home/travis/.phpenv/rbenv.d/exec/hhvm-switcher.bash
sleep 20
Loading…
Cancel
Save