Skip to content

Commit

Permalink
Fix test issues
Browse files Browse the repository at this point in the history
  • Loading branch information
mostafabarmshory committed Mar 16, 2020
1 parent 60104d2 commit 27851d1
Show file tree
Hide file tree
Showing 12 changed files with 78 additions and 79 deletions.
2 changes: 1 addition & 1 deletion .coveralls.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
service_name: travis-ci
coverage_clover: build/logs/clover.xml
# json_path: tests/coveralls-upload.json
#repo_token: VNsS1pG6yyIfxasg8yz8nf9IxTDRttlac
9 changes: 5 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name" : "pluf/seo",
"version" : "6.0.5",
"description" : "SEO package of pluf",
"type" : "library",
"license" : "MIT",
Expand Down Expand Up @@ -35,6 +36,9 @@
"restfull",
"pluf-module"
],
"include-path" : [
"src/"
],
"autoload" : {
"psr-0" : {
"" : "src"
Expand All @@ -43,15 +47,12 @@
"Pluf\\Seo\\" : "src6"
}
},
"include-path" : [
"src/"
],
"autoload-dev" : {
"psr-4" : {
"Pluf\\Test\\" : "tests"
}
},
"repositories" : [{
"repositories~" : [{
"type" : "path",
"url" : "../core",
"name" : "pluf/core",
Expand Down
13 changes: 10 additions & 3 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,15 @@
</whitelist>
</filter>
<logging>
<log type="coverage-html" target="build/tmp/report" lowUpperBound="35" highLowerBound="70"/>
<log type="coverage-clover" target="build/tmp/coverage.xml"/>
<log type="junit" target="build/tmp/logfile.xml"/>
<!-- <log -->
<!-- type="coverage-html" -->
<!-- target="build/tmp/report" -->
<!-- lowUpperBound="35" highLowerBound="70"/> -->
<log
type="coverage-clover"
target="build/logs/clover.xml"/>
<log
type="junit"
target="build/log/junit.xml"/>
</logging>
</phpunit>
2 changes: 1 addition & 1 deletion src/Seo/Engine/Global.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public function fetchContentBinary($request, $content)
try {
// maso, 2017: fetch data from server
$client = new \GuzzleHttp\Client(array(
'base_uri' => Pluf::f('seo.prerender.global.url', 'localhost')
'base_uri' => Pluf::f('seo_prerender_global_url', 'localhost')
));
if (! defined('IN_UNIT_TESTS')) {
$res = $client->request('GET', '/' . $content->url, array(
Expand Down
25 changes: 14 additions & 11 deletions src6/Middleware/Render.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@

use Jaybizzle\CrawlerDetect\CrawlerDetect;
use Pluf\Exception;
use Pluf\Middleware;
use Pluf;
use Pluf_HTTP_Request;
use Pluf_HTTP_Response;
use Pluf_Middleware;
use Seo_Backend;
use Seo_Request;
use Pluf\Logger;

/**
* SEO middleware
Expand All @@ -35,15 +36,15 @@
* @author maso <[email protected]>
*
*/
class Render implements Pluf_Middleware
class Render implements Middleware
{

/**
*
* {@inheritdoc}
* @see Pluf_Middleware::process_request()
* @see Middleware::process_request()
*/
function process_request(&$request)
function process_request(Pluf_HTTP_Request &$request)
{
if ($request->method !== 'GET') {
return false;
Expand Down Expand Up @@ -94,17 +95,17 @@ function prerenderResponse(Pluf_HTTP_Request $request)
return new Pluf_HTTP_Response($response);
}
} catch (Exception $error) {
// TODO: maso, 2014: log the error
Logger::warn('A SEO Prerender Backedn fails to process a request', $backend, $error);
}
}
// No prerender engine is set. So default prerender will be used.
if (Pluf::f('seo.prerender.default.enable', false)) {
if (Pluf::f('seo_prerender_default_enable', false)) {
$backend = new Seo_Backend();
$backend->title = 'Default global prerenderer';
$backend->symbol = 'global';
$backend->engine = 'global';
$backend->setMeta('period', Pluf::f('.prerender.default.period', '+7 days'));
$backend->setMeta('pattern', Pluf::f('seo.prerender.default.pattern', '.*'));
$backend->setMeta('period', Pluf::f('seo_prerender_default_period', '+7 days'));
$backend->setMeta('pattern', Pluf::f('seo_prerender_default_pattern', '.*'));
return $backend->render($renderRequest);
}

Expand All @@ -114,8 +115,10 @@ function prerenderResponse(Pluf_HTTP_Request $request)
/**
*
* {@inheritdoc}
* @see Pluf_Middleware::process_response()
* @see Middleware::process_response()
*/
public function process_response($request, $response)
{}
public function process_response(Pluf_HTTP_Request $request, Pluf_HTTP_Response $response): Pluf_HTTP_Response
{
return $response;
}
}
43 changes: 0 additions & 43 deletions src6/Middleware/Sitemap.php

This file was deleted.

File renamed without changes.
10 changes: 5 additions & 5 deletions tests/Prerender.default/DefaultPrerenderEngineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ class DefaultPrerenderGlobalEngineTest extends TestCase
public static function createDataBase()
{
$cfg = include (__DIR__ . '/../conf/config.php');
$cfg['seo.prerender.default.engine'] = 'global';
$cfg['seo.prerender.default.enable'] = true;
$cfg['seo.prerender.default.period'] = '+7 days';
$cfg['seo.prerender.default.pattern'] = '.*';
$cfg['seo_prerender_default_engine'] = 'fake';
$cfg['seo_prerender_default_enable'] = true;
$cfg['seo_prerender_default_period'] = '+7 days';
$cfg['seo_prerender_default_pattern'] = '.*';

Pluf::start($cfg);
$m = new Pluf_Migration();
Expand Down Expand Up @@ -120,7 +120,7 @@ public function botRequest()
$query = '/example/resource';
$_SERVER['REQUEST_METHOD'] = 'GET';
$_SERVER['REQUEST_URI'] = 'http://localhost/example/resource';
$_SERVER['HTTP_USER_AGENT'] = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.89 Safari/537.36';
$_SERVER['HTTP_USER_AGENT'] = 'Mozilla/5.0 (Linux; Android 5.0; SM-G920A) AppleWebKit (KHTML, like Gecko) Chrome Mobile Safari (compatible; AdsBot-Google-Mobile; +http://www.google.com/mobile/adsbot.html)';
$_SERVER['REMOTE_ADDR'] = 'not set';
$_SERVER['HTTP_HOST'] = 'localhost';
$GLOBALS['_PX_uniqid'] = 'example';
Expand Down
6 changes: 4 additions & 2 deletions tests/Seo/Content/BasicsRestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,10 @@ public function registerUnknownContent()

// call to get a link with crawler
$pageAddress = '/random/page/test-page-' . rand();
$client = new Client();
$client->get($pageAddress);
try {
$client = new Client();
$client->get($pageAddress);
} catch (\Pluf\Exception $ex) {}

// Check if link is registered
$url = "http://localhost" . $pageAddress;
Expand Down
8 changes: 7 additions & 1 deletion tests/Seo/MiddlewareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,13 @@ class MiddlewareTest extends TestCase
*/
public function setUpTest()
{
Pluf::start(__DIR__ . '/../conf/config.php');
$cfg = include (__DIR__ . '/../conf/config.php');
$cfg['seo_prerender_default_engine'] = 'fake';
$cfg['seo_prerender_default_enable'] = true;
$cfg['seo_prerender_default_period'] = '+7 days';
$cfg['seo_prerender_default_pattern'] = '.*';

Pluf::start($cfg);
$m = new Pluf_Migration();
$m->install();
$m->init();
Expand Down
8 changes: 6 additions & 2 deletions tests/Seo/Sitemap/XmlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,13 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
use PHPUnit\Framework\TestCase;
namespace Pluf\Test\Seo\Sitemap;

use Pluf\Test\Client;
require_once 'Pluf.php';
use Pluf\Test\TestCase;
use Pluf;
use Pluf_Migration;
use Seo_SitemapLink;

/**
*
Expand Down
31 changes: 25 additions & 6 deletions tests/conf/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,18 @@
$cfg['upload_path'] = '/tmp';
$cfg['tmp_folder'] = '/tmp';
$cfg['middleware_classes'] = array(
'Pluf_Middleware_Session',
'\Pluf\Seo\Middleware\Render',
'\Pluf\Middleware\Session',
'User_Middleware_Session'
);
$cfg['secret_key'] = '5a8d7e0f2aad8bdab8f6eef725412850';

// -------------------------------------------------------------------------
// Template manager and compiler
// -------------------------------------------------------------------------
$cfg['templates_folder'] = array(
dirname(__FILE__) . '/../templates'
$cfg['template_folders'] = array(
__DIR__ . '/../../templates', // /vendor/pluf/seo/templates
__DIR__ . '/../templates'
);
$cfg['template_tags'] = array(
'mytag' => 'Pluf_Template_Tag_Mytag'
Expand All @@ -43,12 +45,11 @@
$cfg['log_formater'] = '\Pluf\LoggerFormatter\Plain';
$cfg['log_appender'] = '\Pluf\LoggerAppender\Console';


// -------------------------------------------------------------------------
// Tenants
// -------------------------------------------------------------------------

// multitenant
// $cfg['tenant_notfound_url'] = 'https://pluf.ir/wb/blog/page/how-config-notfound-tenant';
// $cfg['multitenant'] = false;

// -------------------------------------------------------------------------
// user
Expand All @@ -57,4 +58,22 @@
$cfg['user_account_auto_activate'] = true;
$cfg['user_avatar_default'] = __DIR__ . '/avatar.svg';

// -------------------------------------------------------------------------
// SEO
// -------------------------------------------------------------------------
//
// Enable default prerender engine
//
// A prerender to use with all tenants if there is not render configuration.
//
// $cfg['seo_prerender_default_enable'] = false;

// $cfg['seo_prerender_default_engine'] = 'global';

// $cfg['seo_prerender_default_period'] = '+7 days';

// $cfg['seo_prerender_default_pattern'] = '.*';

// $cfg['seo_prerender_global_url'] = 'localhost';

return $cfg;

0 comments on commit 27851d1

Please sign in to comment.