Skip to content

Commit

Permalink
Fixes #1087: Auto-discovery of multisite.name. (#1119)
Browse files Browse the repository at this point in the history
* Auto-populate multisite.name if not provided by user.

* Add testing for multisite properties.

* Return an empty string if property doesn't exist.

* Update expected multisite.name value, and make configurable.
  • Loading branch information
bobbygryzynger authored and grasmash committed Feb 22, 2017
1 parent 8218a86 commit a220e86
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 5 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ script:
- source ${BLT_DIR}/scripts/travis/run_tests
- source ${BLT_DIR}/scripts/blt/ci/internal/doctor.sh
- phpunit ${BLT_DIR}/tests/phpunit --group blt-project -c ${BLT_DIR}/tests/phpunit/phpunit.xml
- phpunit ${BLT_DIR}/tests/phpunit --group blt-multisite -c ${BLT_DIR}/tests/phpunit/phpunit.xml
# Deploy build artifact.
- blt deploy:build
- source ${BLT_DIR}/scripts/blt/ci/internal/test_artifact.sh
Expand Down
12 changes: 7 additions & 5 deletions phing/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,13 @@ git:
pre-commit: ${blt.root}/scripts/git-hooks
commit-msg: ${blt.root}/scripts/git-hooks

multisite:
# The docroot/sites/default directory is used by default.
name:
- default
# - another_site
# You may provide a list of sites for BLT to run commands against,
# otherwise BLT will generate this sites list based on directories
# in ${docroot}/sites/*/
#
# multisite:
# name:
# - default

reports:
localDir: ${repo.root}/reports
Expand Down
12 changes: 12 additions & 0 deletions phing/tasks/properties.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,18 @@
</then>
</if>

<if>
<not>
<isset property="multisite.name"/>
</not>
<!-- Build the sites list if not specified by the user. -->
<then>
<!-- Find directories in ${docroot}/sites/*/ and format into a comma-separated list. -->
<exec command="find ${docroot}/sites/* -maxdepth 0 -type d | sed -e 's%${docroot}/sites/%%g' -e '2,$s%^%,%' | tr -d '\n'"
outputProperty="multisite.name" logoutput="false" checkreturn="true"/>
</then>
</if>

<if>
<!-- There is multisite config. Allow it to override default values. -->
<available file="${blt.config-files.multisite}" />
Expand Down
65 changes: 65 additions & 0 deletions tests/phpunit/BltProject/PropertiesTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php

namespace Acquia\Blt\Tests\BltProject;

use Acquia\Blt\Tests\BltProjectTestBase;

/**
* Class PropertiesTest.
*
* Verifies that Phing properties are being parsed as expected.
*/
class PropertiesTest extends BltProjectTestBase {

/**
* Tests whether multisite.name is parsed as expected.
*
* @group blt-multisite
*/
public function testMultisiteProperties() {
$this->assertPropertyEquals('multisite.name', BLT_MULTISITE_NAME);
}

/**
* Asserts that a given property has an expected value.
*
* @param string $property
* The property to check.
* @param string $expected
* The expected value of $property.
* @param string $site
* An optional site name.
*/
protected function assertPropertyEquals($property, $expected, $site = '') {
$value = $this->getProperty($property, $site);
$this->assertEquals($expected, $value,
"Expected value at $property to equal '$expected'. Instead, $property equals '$value'.");
}

/**
* Gets the value a given property (optionally specifying a site).
*
* @param string $property
* The property to check.
* @param string $site
* An optional site name.
*
* @return string
* The value of $property.
*/
private function getProperty($property, $site = '') {
$output = [];
$blt_bin = $this->projectDirectory . '/vendor/bin/blt';
exec(
// Run the echo-property task (optionally providing a site name)
// and parse its output.
"$blt_bin echo-property -Dproperty.name=$property " . (!empty($site) ? "-Dmultisite.name=$site" : "") .
// Run command with minimal output and console styling.
" -emacs -silent", $output
);
// Property value will be output to the 1st line.
// Return an empty string if $property does not exist.
return !empty($output[0]) ? $output[0] : '';
}

}
1 change: 1 addition & 0 deletions tests/phpunit/phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<php>
<const name="BLT_ENV" value="ci"/>
<const name="BLT_ALIAS" value="self"/>
<const name="BLT_MULTISITE_NAME" value="default,g"/>
</php>

</phpunit>

0 comments on commit a220e86

Please sign in to comment.