Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
S
simple_sitemap
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Custom Issue Tracker
Custom Issue Tracker
Labels
Merge Requests
3
Merge Requests
3
Requirements
Requirements
List
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Analytics
Analytics
Code Review
Insights
Issue
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
project
simple_sitemap
Commits
cd0cfafe
Commit
cd0cfafe
authored
May 30, 2019
by
WalkingDexter
Committed by
atymchuk
May 30, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Another functional test.
parent
5c893234
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 @
cd0cfafe
...
...
@@ -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 @
cd0cfafe
...
...
@@ -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