Skip to content

Commit

Permalink
fixes #3 - exclude post types that have been excluded from search
Browse files Browse the repository at this point in the history
  • Loading branch information
parisholley committed Jul 25, 2013
1 parent bbcf83c commit acdd778
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 14 deletions.
2 changes: 1 addition & 1 deletion docs
14 changes: 13 additions & 1 deletion src/elasticsearch/Defaults.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,19 @@ static function fields(){
* @return string[] post type names
**/
static function types(){
return get_post_types();
$types = get_post_types();

$available = array();

foreach($types as $type){
$tobject = get_post_type_object($type);

if(!$tobject->exclude_from_search && $type != 'attachment'){
$available[] = $type;
}
}

return $available;
}

/**
Expand Down
4 changes: 3 additions & 1 deletion tests/selenium.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ phantomjs --webdriver=127.0.0.1:8910 --webdriver-selenium-grid-hub=http://127.0.

echo "$!" > phantom.pid

sleep 2s
echo "Waiting for phantomjs to register with grid.."

sleep 10s

type pear >/dev/null 2>&1 || { echo >&2 "Pear is not installed."; exit 1; }

Expand Down
27 changes: 24 additions & 3 deletions tests/unit-tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,37 @@ function get_posts($args){
return count(elasticsearch\TestContext::$posts) > 0 ? elasticsearch\TestContext::$posts : $args;
}

function get_post_type_object($name){
foreach(elasticsearch\TestContext::$types as $type){
if($type->name == $name){
return $type;
}
}

return null;
}

function &get_option($name){
return elasticsearch\TestContext::$options;
}

function get_post_types(){
return elasticsearch\TestContext::$types;
$names = array();

foreach(elasticsearch\TestContext::$types as $type){
$names[] = $type->name;
}

return $names;
}

function register_post_type($type){
elasticsearch\TestContext::$types[count(elasticsearch\TestContext::$types)] = $type;
function register_post_type($type, $args = array()){
$args = array_merge(array(
'exclude_from_search' => false,
'name' => $type
), $args);

elasticsearch\TestContext::$types[count(elasticsearch\TestContext::$types)] = (object) $args;
elasticsearch\TestContext::$taxes[$type] = array();
}

Expand Down
10 changes: 6 additions & 4 deletions tests/unit-tests/elasticsearch/ConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,17 @@ public function testTaxonomiesDefault()
$this->assertEquals(array('tax1', 'tax2'), Config::taxonomies());
}

public function testTypesDefined()
public function testTypesUndefined()
{
register_post_type('post');
register_post_type('review');
register_post_type('review', array(
'exclude_from_search' => true
));

$this->assertEquals(array('post', 'review'), Config::types());
$this->assertEquals(array('post'), Config::types());
}

public function testTypesDefault()
public function testTypesDefined()
{
update_option('types', array('post' => 1, 'review' => 1));

Expand Down
2 changes: 1 addition & 1 deletion vendor/autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@

require_once __DIR__ . '/composer' . '/autoload_real.php';

return ComposerAutoloaderInit2f7f268913eec9074616a6dfab64738b::getLoader();
return ComposerAutoloaderInit3ef2204e0bdae39773b3713b45f21c74::getLoader();
6 changes: 3 additions & 3 deletions vendor/composer/autoload_real.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

// autoload_real.php generated by Composer

class ComposerAutoloaderInit2f7f268913eec9074616a6dfab64738b
class ComposerAutoloaderInit3ef2204e0bdae39773b3713b45f21c74
{
private static $loader;

Expand All @@ -19,9 +19,9 @@ public static function getLoader()
return self::$loader;
}

spl_autoload_register(array('ComposerAutoloaderInit2f7f268913eec9074616a6dfab64738b', 'loadClassLoader'), true, true);
spl_autoload_register(array('ComposerAutoloaderInit3ef2204e0bdae39773b3713b45f21c74', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader();
spl_autoload_unregister(array('ComposerAutoloaderInit2f7f268913eec9074616a6dfab64738b', 'loadClassLoader'));
spl_autoload_unregister(array('ComposerAutoloaderInit3ef2204e0bdae39773b3713b45f21c74', 'loadClassLoader'));

$vendorDir = dirname(__DIR__);
$baseDir = dirname($vendorDir);
Expand Down

0 comments on commit acdd778

Please sign in to comment.