Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Open sidebar
project
simple_sitemap
Commits
9185a39f
Commit
9185a39f
authored
Jun 01, 2019
by
Pawel G
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch '8.x-3.x' into feature/search-engines
parents
544f094e
a5eaa067
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
107 additions
and
5 deletions
+107
-5
modules/simple_sitemap_views/tests/src/Functional/SimpleSitemapViewsTest.php
...map_views/tests/src/Functional/SimpleSitemapViewsTest.php
+60
-5
modules/simple_sitemap_views/tests/src/Functional/SimpleSitemapViewsTestBase.php
...views/tests/src/Functional/SimpleSitemapViewsTestBase.php
+47
-0
No files found.
modules/simple_sitemap_views/tests/src/Functional/SimpleSitemapViewsTest.php
View file @
9185a39f
...
...
@@ -54,29 +54,29 @@ class SimpleSitemapViewsTest extends SimpleSitemapViewsTestBase {
public
function
testAddArgumentsToIndex
()
{
// Arguments with the wrong value should not be indexed.
$this
->
sitemapViews
->
addArgumentsToIndex
(
$this
->
testView
,
[
'page2'
]);
$this
->
assert
Equals
(
0
,
$this
->
sitemapViews
->
getArgumentsFromIndexCount
()
);
$this
->
assert
IndexSize
(
0
);
// Non-indexable arguments should not be indexed.
$args
=
[
'page'
,
$this
->
node
->
getTitle
(),
$this
->
node
->
id
()];
$this
->
sitemapViews
->
addArgumentsToIndex
(
$this
->
testView
,
$args
);
$this
->
assert
Equals
(
0
,
$this
->
sitemapViews
->
getArgumentsFromIndexCount
()
);
$this
->
assert
IndexSize
(
0
);
// The argument set should not be indexed more than once.
for
(
$i
=
0
;
$i
<
2
;
$i
++
)
{
$this
->
sitemapViews
->
addArgumentsToIndex
(
$this
->
testView
,
[
'page'
]);
$this
->
assert
Equals
(
1
,
$this
->
sitemapViews
->
getArgumentsFromIndexCount
()
);
$this
->
assert
IndexSize
(
1
);
}
// A new set of arguments must be indexed.
$args
=
[
'page'
,
$this
->
node
->
getTitle
()];
$this
->
sitemapViews
->
addArgumentsToIndex
(
$this
->
testView
,
$args
);
$this
->
assert
Equals
(
2
,
$this
->
sitemapViews
->
getArgumentsFromIndexCount
()
);
$this
->
assert
IndexSize
(
2
);
// The number of argument sets in the index for one view display should not
// exceed the maximum number of link variations.
$args
=
[
'page'
,
$this
->
node2
->
getTitle
()];
$this
->
sitemapViews
->
addArgumentsToIndex
(
$this
->
testView
,
$args
);
$this
->
assert
Equals
(
2
,
$this
->
sitemapViews
->
getArgumentsFromIndexCount
()
);
$this
->
assert
IndexSize
(
2
);
}
/**
...
...
@@ -99,4 +99,59 @@ class SimpleSitemapViewsTest extends SimpleSitemapViewsTestBase {
$this
->
assertSession
()
->
responseContains
(
"
$test_view_url
/page/
$title
"
);
}
/**
* Tests the garbage collection process.
*/
public
function
testGarbageCollector
()
{
// Disable cron generation, since data can be removed
// from the index during generation.
$this
->
generator
->
saveSetting
(
'cron_generate'
,
FALSE
);
// Record with the wrong set of indexed arguments must be removed.
$this
->
addRecordToIndex
(
$this
->
testView
->
id
(),
$this
->
testView
->
current_display
,
[
'type'
,
'title'
,
'nid'
],
[
'page'
,
$this
->
node
->
getTitle
(),
$this
->
node
->
id
()]
);
$this
->
cron
->
run
();
$this
->
assertIndexSize
(
0
);
// Record of a non-existent view must be removed.
$this
->
addRecordToIndex
(
'simple_sitemap_fake_view'
,
$this
->
testView
->
current_display
,
[
'type'
,
'title'
],
[
'page'
,
$this
->
node
->
getTitle
()]
);
$this
->
cron
->
run
();
$this
->
assertIndexSize
(
0
);
// Record of a non-existent display must be removed.
$this
->
addRecordToIndex
(
$this
->
testView
->
id
(),
'simple_sitemap_fake_display'
,
[
'type'
,
'title'
],
[
'page'
,
$this
->
node
->
getTitle
()]
);
$this
->
cron
->
run
();
$this
->
assertIndexSize
(
0
);
// The number of records should not exceed the specified limit.
for
(
$i
=
0
;
$i
<
3
;
$i
++
)
{
$this
->
addRecordToIndex
(
$this
->
testView
->
id
(),
$this
->
testView
->
current_display
,
[
'type'
,
'title'
],
[
'page2'
,
"Node
$i
"
]
);
}
$this
->
cron
->
run
();
$this
->
assertIndexSize
(
2
);
// Records about pages with empty result must be removed during generation.
$this
->
generator
->
generateSitemap
(
'backend'
);
$this
->
assertIndexSize
(
0
);
}
}
modules/simple_sitemap_views/tests/src/Functional/SimpleSitemapViewsTestBase.php
View file @
9185a39f
...
...
@@ -3,6 +3,7 @@
namespace
Drupal\Tests\simple_sitemap_views\Functional
;
use
Drupal\Tests\simple_sitemap
\
Functional\SimplesitemapTestBase
;
use
Drupal\simple_sitemap_views
\
SimpleSitemapViews
;
use
Drupal\views\Views
;
/**
...
...
@@ -25,6 +26,13 @@ abstract class SimpleSitemapViewsTestBase extends SimplesitemapTestBase {
*/
protected
$sitemapViews
;
/**
* The cron service.
*
* @var \Drupal\Core\CronInterface
*/
protected
$cron
;
/**
* Test view.
*
...
...
@@ -39,8 +47,47 @@ abstract class SimpleSitemapViewsTestBase extends SimplesitemapTestBase {
parent
::
setUp
();
$this
->
sitemapViews
=
$this
->
container
->
get
(
'simple_sitemap.views'
);
$this
->
cron
=
$this
->
container
->
get
(
'cron'
);
$this
->
testView
=
Views
::
getView
(
'simple_sitemap_views_test_view'
);
$this
->
testView
->
setDisplay
(
'page_1'
);
}
/**
* Asserts the size of the arguments index.
*
* @param int $size
* The expected size.
*/
protected
function
assertIndexSize
(
$size
)
{
$this
->
assertEquals
(
$size
,
$this
->
sitemapViews
->
getArgumentsFromIndexCount
());
}
/**
* Adds a record to the arguments index.
*
* @param string $view_id
* The view ID.
* @param string $display_id
* The view display ID.
* @param array $args_ids
* A set of argument IDs.
* @param array $args_values
* A set of argument values.
*/
protected
function
addRecordToIndex
(
$view_id
,
$display_id
,
array
$args_ids
,
array
$args_values
)
{
$args_ids
=
implode
(
SimpleSitemapViews
::
ARGUMENT_SEPARATOR
,
$args_ids
);
$args_values
=
implode
(
SimpleSitemapViews
::
ARGUMENT_SEPARATOR
,
$args_values
);
// Insert a record into the index table.
$query
=
$this
->
database
->
insert
(
'simple_sitemap_views'
);
$query
->
fields
([
'view_id'
=>
$view_id
,
'display_id'
=>
$display_id
,
'arguments_ids'
=>
$args_ids
,
'arguments_values'
=>
$args_values
,
]);
$query
->
execute
();
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment