diff --git a/.scripts/travis_setup.sh b/.scripts/travis_setup.sh index 3123d11f..61a75be1 100755 --- a/.scripts/travis_setup.sh +++ b/.scripts/travis_setup.sh @@ -3,16 +3,16 @@ 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 +#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 @@ -46,6 +46,7 @@ drush en -y syslog drush en -y serialization drush en -y basic_auth drush en -y rest +drush en -y simpletest drush dl rdfui --dev drush en -y rdfui @@ -71,6 +72,8 @@ cd $HOME/drupal/modules git clone https://github.com/DiegoPino/claw-jsonld.git drush en -y jsonld +drush en -y islandora + drush -y dl bootstrap drush -y en bootstrap drush -y config-set system.theme default bootstrap diff --git a/.travis.yml b/.travis.yml index b3d2ddec..5948f67c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -20,15 +20,17 @@ before_install: - export ISLANDORA_DIR=$TRAVIS_BUILD_DIR install: -# - $TRAVIS_BUILD_DIR/tests/scripts/travis_setup.sh + - $TRAVIS_BUILD_DIR/.scripts/travis_setup.sh - composer install - php vendor/bin/phpcs --config-set installed_paths vendor/drupal/coder/coder_sniffer script: - $ISLANDORA_DIR/.scripts/line_endings.sh . + - cd $HOME/drupal/modules/islandora - php vendor/bin/phpcs --standard=Drupal **/*.module **/*.php --ignore=tests,vendor . - php vendor/bin/phpcpd --names *.module,*.inc,*.test,*.php --exclude=vendor . + - cd $HOME/drupal; php core/scripts/run-tests.sh --php `which php` islandora notifications: irc: diff --git a/islandora/islandora.services.yml b/islandora/islandora.services.yml index 938de6ed..d1a94b40 100644 --- a/islandora/islandora.services.yml +++ b/islandora/islandora.services.yml @@ -6,3 +6,5 @@ services: tags: - { name: paramconverter } arguments: ['@entity.manager'] + islandora.eventgenerator: + class: Drupal\islandora\EventGenerator\EventGenerator diff --git a/islandora/src/EventGenerator/EventGenerator.php b/islandora/src/EventGenerator/EventGenerator.php new file mode 100644 index 00000000..e0463277 --- /dev/null +++ b/islandora/src/EventGenerator/EventGenerator.php @@ -0,0 +1,60 @@ + "https://www.w3.org/ns/activitystreams", + "type" => "Create", + "actor" => [ + "type" => "Person", + "id" => $user->toUrl()->setAbsolute()->toString(), + ], + "object" => $entity->toUrl()->setAbsolute()->toString(), + ]); + } + + /** + * {@inheritdoc} + */ + public function generateUpdateEvent(EntityInterface $entity, UserInterface $user) { + return json_encode([ + "@context" => "https://www.w3.org/ns/activitystreams", + "type" => "Update", + "actor" => [ + "type" => "Person", + "id" => $user->toUrl()->setAbsolute()->toString(), + ], + "object" => $entity->toUrl()->setAbsolute()->toString(), + ]); + } + + /** + * {@inheritdoc} + */ + public function generateDeleteEvent(EntityInterface $entity, UserInterface $user) { + return json_encode([ + "@context" => "https://www.w3.org/ns/activitystreams", + "type" => "Delete", + "actor" => [ + "type" => "Person", + "id" => $user->toUrl()->setAbsolute()->toString(), + ], + "object" => $entity->toUrl()->setAbsolute()->toString(), + ]); + } + +} diff --git a/islandora/src/EventGenerator/EventGeneratorInterface.php b/islandora/src/EventGenerator/EventGeneratorInterface.php new file mode 100644 index 00000000..766e1389 --- /dev/null +++ b/islandora/src/EventGenerator/EventGeneratorInterface.php @@ -0,0 +1,52 @@ +installSchema('system', 'sequences'); + $this->installEntitySchema('user'); + $this->installConfig('filter'); + $this->installEntitySchema('fedora_resource'); + + // Create a test user. + $this->user = $this->drupalCreateUser(); + + // Create a test entity. + $this->entity = FedoraResource::create([ + "type" => "rdf_source", + "uid" => 1, + "name" => "Test Fixture", + "langcode" => "und", + "status" => 1, + ]); + $this->entity->save(); + + // Create the event generator so we can test it. + $this->eventGenerator = new EventGenerator(); + } + + /** + * Tests the generateCreateEvent() method. + */ + public function testGenerateCreateEvent() { + $json = $this->eventGenerator->generateCreateEvent($this->entity, $this->user); + $msg = json_decode($json, TRUE); + + $this->assertBasicStructure($msg); + $this->assertTrue($msg["type"] == "Create", "Event type is 'Create'."); + } + + /** + * Tests the generateUpdateEvent() method. + */ + public function testGenerateUpdateEvent() { + $json = $this->eventGenerator->generateUpdateEvent($this->entity, $this->user); + $msg = json_decode($json, TRUE); + + $this->assertBasicStructure($msg); + $this->assertTrue($msg["type"] == "Update", "Event type is 'Update'."); + } + + /** + * Tests the generateDeleteEvent() method. + */ + public function testGenerateDeleteEvent() { + $json = $this->eventGenerator->generateDeleteEvent($this->entity, $this->user); + $msg = json_decode($json, TRUE); + + $this->assertBasicStructure($msg); + $this->assertTrue($msg["type"] == "Delete", "Event type is 'Delete'."); + + } + + /** + * Util function for repeated checks. + * + * @param array $msg + * The message parsed as an array. + */ + protected function assertBasicStructure(array $msg) { + // Looking for @context. + $this->assertTrue(array_key_exists('@context', $msg), "Context key exists"); + $this->assertTrue($msg["@context"] == "https://www.w3.org/ns/activitystreams", "Context is activity stream."); + + // Make sure it has a type. + $this->assertTrue(array_key_exists('type', $msg), "Type key exists"); + + // Make sure the actor exists, is a person, and has a uri. + $this->assertTrue(array_key_exists('actor', $msg), "Actor key exists"); + $this->assertTrue(array_key_exists("type", $msg["actor"]), "Type key exists for actor."); + $this->assertTrue($msg["actor"]["type"] == "Person", "Actor is a person."); + $this->assertTrue(array_key_exists("id", $msg["actor"]), "Id key exists for actor."); + $this->assertTrue($msg["actor"]["id"] == $this->user->toUrl()->setAbsolute()->toString(), "Id is user's uri"); + + // Make sure the object exists and is a uri. + $this->assertTrue(array_key_exists('object', $msg), "Object key exists"); + $this->assertTrue($msg["object"] == $this->entity->toUrl()->setAbsolute()->toString(), "Object is entity uri."); + } + +}