コード例 #1
0
ファイル: queryTest.php プロジェクト: antidot/php_api
 public function testCloneQuery()
 {
     $query = new AfsQuery();
     $query = $query->set_query('query')->add_filter('foo', 'bar')->add_filter('foo', 'baz')->add_filter('fox', 'bat')->add_filter('fox', 'bas')->add_feed('feed')->add_feed('food')->set_replies(666)->set_lang('en')->set_sort(AfsSortBuiltins::WEIGHT, AfsSortOrder::ASC)->add_sort('foo')->add_sort('BAR')->set_cluster('CLUSTER', 42666)->set_max_clusters(66642)->set_overspill()->set_count(AfsCount::CLUSTERS)->set_page(42)->set_from(AfsOrigin::SEARCHBOX)->add_log('loggy')->add_advanced_filter(filter('foo')->greater->value(666))->auto_set_from();
     $clone = new AfsQuery($query);
     $this->assertTrue($clone->get_query('query') == 'query');
     $this->assertTrue($clone->has_filter('foo', 'bar'));
     $this->assertTrue($clone->has_filter('foo', 'baz'));
     $this->assertTrue($clone->has_filter('fox', 'bat'));
     $this->assertTrue($clone->has_filter('fox', 'bas'));
     $this->assertTrue(in_array('feed', $clone->get_feeds()));
     $this->assertTrue(in_array('food', $clone->get_feeds()));
     $this->assertTrue($clone->get_page() == 42);
     $this->assertTrue($clone->get_replies() == 666);
     $this->assertTrue($clone->get_lang() == 'en');
     $this->assertEquals(AfsSortOrder::ASC, $clone->get_sort_order('afs:weight'));
     $this->assertTrue($clone->has_sort('foo'));
     $this->assertEquals(AfsSortOrder::DESC, $clone->get_sort_order('foo'));
     $this->assertTrue($clone->has_sort('BAR'));
     $this->assertEquals(AfsSortOrder::DESC, $clone->get_sort_order('BAR'));
     $this->assertTrue($clone->has_cluster());
     $this->assertEquals('CLUSTER', $clone->get_cluster_id());
     $this->assertEquals(42666, $clone->get_nb_replies_per_cluster());
     $this->assertTrue($clone->has_max_clusters());
     $this->assertEquals(66642, $clone->get_max_clusters());
     $this->assertTrue($clone->has_overspill());
     $this->assertEquals(AfsCount::CLUSTERS, $clone->get_count_mode());
     $this->assertEquals(AfsOrigin::SEARCHBOX, $clone->get_from());
     $logs = $clone->get_logs();
     $this->assertEquals(1, count($logs));
     $this->assertEquals('loggy', $logs[0]);
     $this->assertTrue($clone->has_advanced_filter());
     $adv_filters = $clone->get_advanced_filters();
     $this->assertEquals('foo>666', $adv_filters[0]);
     // Need to call specific method to check that auto set from is active
     $clone = $clone->add_filter('youhou', 'bloublou');
     $this->assertEquals(AfsOrigin::FACET, $clone->get_from());
 }