Skip to content
This repository was archived by the owner on Apr 4, 2023. It is now read-only.

Commit 70950a1

Browse files
committed
fixed tests
1 parent 7e4f29e commit 70950a1

File tree

4 files changed

+60
-28
lines changed

4 files changed

+60
-28
lines changed

bin/install-wp-tests.sh

Lines changed: 52 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env bash
22

33
if [ $# -lt 3 ]; then
4-
echo "usage: $0 <db-name> <db-user> <db-pass> [db-host] [wp-version]"
4+
echo "usage: $0 <db-name> <db-user> <db-pass> [db-host] [wp-version] [skip-database-creation]"
55
exit 1
66
fi
77

@@ -10,20 +10,30 @@ DB_USER=$2
1010
DB_PASS=$3
1111
DB_HOST=${4-localhost}
1212
WP_VERSION=${5-latest}
13+
SKIP_DB_CREATE=${6-false}
1314

14-
WP_TESTS_DIR=${WP_TESTS_DIR-/tmp/wordpress-tests-lib}
15-
WP_CORE_DIR=${WP_CORE_DIR-/tmp/wordpress/}
15+
TMPDIR=${TMPDIR-/tmp}
16+
TMPDIR=$(echo $TMPDIR | sed -e "s/\/$//")
17+
WP_TESTS_DIR=${WP_TESTS_DIR-$TMPDIR/wordpress-tests-lib}
18+
WP_CORE_DIR=${WP_CORE_DIR-$TMPDIR/wordpress/}
1619

1720
download() {
18-
if [ `which curl` ]; then
19-
curl -s "$1" > "$2";
20-
elif [ `which wget` ]; then
21-
wget -nv -O "$2" "$1"
22-
fi
21+
if [ `which curl` ]; then
22+
curl -s "$1" > "$2";
23+
elif [ `which wget` ]; then
24+
wget -nv -O "$2" "$1"
25+
fi
2326
}
2427

25-
if [[ $WP_VERSION =~ [0-9]+\.[0-9]+(\.[0-9]+)? ]]; then
26-
WP_TESTS_TAG="tags/$WP_VERSION"
28+
if [[ $WP_VERSION =~ ^[0-9]+\.[0-9]+$ ]]; then
29+
WP_TESTS_TAG="branches/$WP_VERSION"
30+
elif [[ $WP_VERSION =~ [0-9]+\.[0-9]+\.[0-9]+ ]]; then
31+
if [[ $WP_VERSION =~ [0-9]+\.[0-9]+\.[0] ]]; then
32+
# version x.x.0 means the first release of the major version, so strip off the .0 and download version x.x
33+
WP_TESTS_TAG="tags/${WP_VERSION%??}"
34+
else
35+
WP_TESTS_TAG="tags/$WP_VERSION"
36+
fi
2737
elif [[ $WP_VERSION == 'nightly' || $WP_VERSION == 'trunk' ]]; then
2838
WP_TESTS_TAG="trunk"
2939
else
@@ -49,18 +59,34 @@ install_wp() {
4959
mkdir -p $WP_CORE_DIR
5060

5161
if [[ $WP_VERSION == 'nightly' || $WP_VERSION == 'trunk' ]]; then
52-
mkdir -p /tmp/wordpress-nightly
53-
download https://wordpress.org/nightly-builds/wordpress-latest.zip /tmp/wordpress-nightly/wordpress-nightly.zip
54-
unzip -q /tmp/wordpress-nightly/wordpress-nightly.zip -d /tmp/wordpress-nightly/
55-
mv /tmp/wordpress-nightly/wordpress/* $WP_CORE_DIR
62+
mkdir -p $TMPDIR/wordpress-nightly
63+
download https://wordpress.org/nightly-builds/wordpress-latest.zip $TMPDIR/wordpress-nightly/wordpress-nightly.zip
64+
unzip -q $TMPDIR/wordpress-nightly/wordpress-nightly.zip -d $TMPDIR/wordpress-nightly/
65+
mv $TMPDIR/wordpress-nightly/wordpress/* $WP_CORE_DIR
5666
else
5767
if [ $WP_VERSION == 'latest' ]; then
5868
local ARCHIVE_NAME='latest'
69+
elif [[ $WP_VERSION =~ [0-9]+\.[0-9]+ ]]; then
70+
# https serves multiple offers, whereas http serves single.
71+
download https://api.wordpress.org/core/version-check/1.7/ $TMPDIR/wp-latest.json
72+
if [[ $WP_VERSION =~ [0-9]+\.[0-9]+\.[0] ]]; then
73+
# version x.x.0 means the first release of the major version, so strip off the .0 and download version x.x
74+
LATEST_VERSION=${WP_VERSION%??}
75+
else
76+
# otherwise, scan the releases and get the most up to date minor version of the major release
77+
local VERSION_ESCAPED=`echo $WP_VERSION | sed 's/\./\\\\./g'`
78+
LATEST_VERSION=$(grep -o '"version":"'$VERSION_ESCAPED'[^"]*' $TMPDIR/wp-latest.json | sed 's/"version":"//' | head -1)
79+
fi
80+
if [[ -z "$LATEST_VERSION" ]]; then
81+
local ARCHIVE_NAME="wordpress-$WP_VERSION"
82+
else
83+
local ARCHIVE_NAME="wordpress-$LATEST_VERSION"
84+
fi
5985
else
6086
local ARCHIVE_NAME="wordpress-$WP_VERSION"
6187
fi
62-
download https://wordpress.org/${ARCHIVE_NAME}.tar.gz /tmp/wordpress.tar.gz
63-
tar --strip-components=1 -zxmf /tmp/wordpress.tar.gz -C $WP_CORE_DIR
88+
download https://wordpress.org/${ARCHIVE_NAME}.tar.gz $TMPDIR/wordpress.tar.gz
89+
tar --strip-components=1 -zxmf $TMPDIR/wordpress.tar.gz -C $WP_CORE_DIR
6490
fi
6591

6692
download https://raw.github.com/markoheijnen/wp-mysqli/master/db.php $WP_CORE_DIR/wp-content/db.php
@@ -79,13 +105,14 @@ install_test_suite() {
79105
# set up testing suite
80106
mkdir -p $WP_TESTS_DIR
81107
svn co --quiet https://develop.svn.wordpress.org/${WP_TESTS_TAG}/tests/phpunit/includes/ $WP_TESTS_DIR/includes
108+
svn co --quiet https://develop.svn.wordpress.org/${WP_TESTS_TAG}/tests/phpunit/data/ $WP_TESTS_DIR/data
82109
fi
83110

84-
cd $WP_TESTS_DIR
85-
86111
if [ ! -f wp-tests-config.php ]; then
87112
download https://develop.svn.wordpress.org/${WP_TESTS_TAG}/wp-tests-config-sample.php "$WP_TESTS_DIR"/wp-tests-config.php
88-
sed $ioption "s:dirname( __FILE__ ) . '/src/':'$WP_CORE_DIR':" "$WP_TESTS_DIR"/wp-tests-config.php
113+
# remove all forward slashes in the end
114+
WP_CORE_DIR=$(echo $WP_CORE_DIR | sed "s:/\+$::")
115+
sed $ioption "s:dirname( __FILE__ ) . '/src/':'$WP_CORE_DIR/':" "$WP_TESTS_DIR"/wp-tests-config.php
89116
sed $ioption "s/youremptytestdbnamehere/$DB_NAME/" "$WP_TESTS_DIR"/wp-tests-config.php
90117
sed $ioption "s/yourusernamehere/$DB_USER/" "$WP_TESTS_DIR"/wp-tests-config.php
91118
sed $ioption "s/yourpasswordhere/$DB_PASS/" "$WP_TESTS_DIR"/wp-tests-config.php
@@ -95,6 +122,11 @@ install_test_suite() {
95122
}
96123

97124
install_db() {
125+
126+
if [ ${SKIP_DB_CREATE} = "true" ]; then
127+
return 0
128+
fi
129+
98130
# parse DB_HOST for port or socket references
99131
local PARTS=(${DB_HOST//\:/ })
100132
local DB_HOSTNAME=${PARTS[0]};
@@ -117,4 +149,4 @@ install_db() {
117149

118150
install_wp
119151
install_test_suite
120-
install_db
152+
#install_db

includes/class-linkbacks-mf2-handler.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,8 @@ public static function generate_commentdata( $commentdata ) {
145145
$mf_array = $parser->parse( true );
146146

147147
// check for rel-alternate links
148-
if ( $source = self::get_alternate_source( $mf_array ) ) {
149-
$mf_array = $source;
148+
if ( $alternate_source = self::get_alternate_source( $mf_array ) ) {
149+
$mf_array = $alternate_source;
150150
}
151151

152152
// get all 'relevant' entries

tests/test-microformats.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<?php
22
class MicroformatsTest extends WP_UnitTestCase {
33

4-
public static function assertArraySubset( array $expectation, array $reality, $strict = false, $message = '' ) {
4+
public static function assert_array_subset( array $expectation, array $reality, $strict = false, $message = '' ) {
55
foreach ( $expectation as $key => $value ) {
66
self::assertArrayHasKey( $key, $reality, $message );
77
if ( is_array( $value ) ) {
8-
self::assertArraySubset( $value, $reality[ $key ], $strict, $message . '[' . $key . ']' );
8+
self::assert_array_subset( $value, $reality[ $key ], $strict, $message . '[' . $key . ']' );
99
} else {
1010
self::assertEquals( $value, $reality[ $key ], $message . '[' . $key . ']' );
1111
}
@@ -27,7 +27,7 @@ public function test_interpreter( $path ) {
2727
);
2828

2929
$subset = json_decode( file_get_contents( substr( $path, 0, -4 ) . 'json' ), true );
30-
$this->assertArraySubset( $subset, $comment );
30+
$this->assert_array_subset( $subset, $comment );
3131
}
3232

3333
public function templateProvider() {

tests/test-rendering.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function test_facepile_markup() {
4141
$this->assertStringMatchesFormat(
4242
'<ul class="mention-list linkback-mention"><li class="webmention even thread-even depth-1 linkback-mention-single u-like h-cite" id="comment-2">
4343
<span class="p-author h-card">
44-
<a class="u-url" title="Person 0 liked this Article on example.com." href="http://example.com/person0"><img alt=\'\' src=\'http://example.com/photo\' srcset=\'http://example.com/photo 2x\' class=\'avatar avatar-64 photo avatar-default u-photo avatar-semantic-linkbacks\' height=\'64\' width=\'64\' /> </a>
44+
<a class="u-url" title="Person 0 liked this Post on example.com." href="http://example.com/person0"><img alt=\'\' src=\'http://example.com/photo\' srcset=\'http://example.com/photo 2x\' class=\'avatar avatar-64 photo avatar-default u-photo avatar-semantic-linkbacks\' height=\'64\' width=\'64\' /> </a>
4545
<span class="hide-name p-name">Person 0</span>
4646
</span>
4747
<a class="u-url" href=""></a>
@@ -52,8 +52,8 @@ public function test_facepile_markup() {
5252
public function test_facepile_fold() {
5353
$comments = $this->make_comments( 3 );
5454
$html = list_linkbacks( array( 'echo' => false ), $comments );
55-
$person_0 = strpos( $html, '<a class="u-url" title="Person 0 liked this Article on example.com."' );
56-
$person_1 = strpos( $html, '<a class="u-url" title="Person 1 liked this Article on example.com."' );
55+
$person_0 = strpos( $html, '<a class="u-url" title="Person 0 liked this Post on example.com."' );
56+
$person_1 = strpos( $html, '<a class="u-url" title="Person 1 liked this Post on example.com."' );
5757
$person_2 = strpos( $html, 'additional-facepile' );
5858
$ellipsis = strpos( $html, '<li class="toggle-additional-facepiles">' );
5959
$this->assertGreaterThan( 0, $person_0 );

0 commit comments

Comments
 (0)