Proyectos de Subversion Moodle

Rev

Rev 11 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 11 Rev 1441
Línea 21... Línea 21...
21
 *
21
 *
22
 * @package    tool_dataprivacy
22
 * @package    tool_dataprivacy
23
 * @copyright  2018 David Monllao
23
 * @copyright  2018 David Monllao
24
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25
 */
25
 */
26
class expired_contexts_test extends \advanced_testcase {
26
final class expired_contexts_test extends \advanced_testcase {
Línea 27... Línea 27...
27
 
27
 
28
    /**
28
    /**
29
     * Setup the basics with the specified retention period.
29
     * Setup the basics with the specified retention period.
30
     *
30
     *
31
     * @param   string  $system Retention policy for the system.
31
     * @param   string  $system Retention policy for the system.
32
     * @param   string  $user Retention policy for users.
32
     * @param   string  $user Retention policy for users.
33
     * @param   string  $course Retention policy for courses.
33
     * @param   string  $course Retention policy for courses.
34
     * @param   string  $activity Retention policy for activities.
34
     * @param   string  $activity Retention policy for activities.
35
     */
35
     */
36
    protected function setup_basics(string $system, string $user, string $course = null, string $activity = null): \stdClass {
36
    protected function setup_basics(string $system, string $user, ?string $course = null, ?string $activity = null): \stdClass {
Línea 37... Línea 37...
37
        $this->resetAfterTest();
37
        $this->resetAfterTest();
38
 
38
 
39
        $purposes = (object) [
39
        $purposes = (object) [
Línea 1368... Línea 1368...
1368
                'delete_data_for_user',
1368
                'delete_data_for_user',
1369
                'delete_data_for_all_users_in_context',
1369
                'delete_data_for_all_users_in_context',
1370
            ])
1370
            ])
1371
            ->getMock();
1371
            ->getMock();
1372
        $mockprivacymanager->expects($this->atLeastOnce())->method('delete_data_for_user');
1372
        $mockprivacymanager->expects($this->atLeastOnce())->method('delete_data_for_user');
-
 
1373
        $deleteinvocations = $this->exactly(2);
1373
        $mockprivacymanager->expects($this->exactly(2))
1374
        $mockprivacymanager->expects($deleteinvocations)
1374
            ->method('delete_data_for_all_users_in_context')
1375
            ->method('delete_data_for_all_users_in_context')
-
 
1376
            ->willReturnCallback(function ($context) use (
1375
            ->withConsecutive(
1377
                $deleteinvocations,
1376
                [$blockcontext],
1378
                $blockcontext,
1377
                [$usercontext]
1379
                $usercontext,
-
 
1380
            ): void {
-
 
1381
                match (self::getInvocationCount($deleteinvocations)) {
-
 
1382
                    1 => $this->assertEquals($blockcontext, $context),
-
 
1383
                    2 => $this->assertEquals($usercontext, $context),
-
 
1384
                    default => $this->fail('Unexpected invocation count'),
-
 
1385
                };
1378
            );
1386
            });
Línea 1379... Línea 1387...
1379
 
1387
 
1380
        $manager = $this->getMockBuilder(\tool_dataprivacy\expired_contexts_manager::class)
1388
        $manager = $this->getMockBuilder(\tool_dataprivacy\expired_contexts_manager::class)
1381
            ->onlyMethods(['get_privacy_manager'])
1389
            ->onlyMethods(['get_privacy_manager'])
1382
            ->getMock();
1390
            ->getMock();
Línea 1586... Línea 1594...
1586
                'delete_data_for_user',
1594
                'delete_data_for_user',
1587
                'delete_data_for_all_users_in_context',
1595
                'delete_data_for_all_users_in_context',
1588
            ])
1596
            ])
1589
            ->getMock();
1597
            ->getMock();
1590
        $mockprivacymanager->expects($this->atLeastOnce())->method('delete_data_for_user');
1598
        $mockprivacymanager->expects($this->atLeastOnce())->method('delete_data_for_user');
-
 
1599
        $deleteinvocations = $this->exactly(2);
1591
        $mockprivacymanager->expects($this->exactly(2))
1600
        $mockprivacymanager->expects($deleteinvocations)
1592
            ->method('delete_data_for_all_users_in_context')
1601
            ->method('delete_data_for_all_users_in_context')
-
 
1602
            ->willReturnCallback(function ($context) use (
1593
            ->withConsecutive(
1603
                $deleteinvocations,
1594
                [$blockcontext],
1604
                $blockcontext,
1595
                [$usercontext]
1605
                $usercontext,
-
 
1606
            ): void {
-
 
1607
                match (self::getInvocationCount($deleteinvocations)) {
-
 
1608
                    1 => $this->assertEquals($blockcontext, $context),
-
 
1609
                    2 => $this->assertEquals($usercontext, $context),
-
 
1610
                    default => $this->fail('Unexpected invocation count'),
-
 
1611
                };
1596
            );
1612
            });
Línea 1597... Línea 1613...
1597
 
1613
 
1598
        $manager = $this->getMockBuilder(\tool_dataprivacy\expired_contexts_manager::class)
1614
        $manager = $this->getMockBuilder(\tool_dataprivacy\expired_contexts_manager::class)
1599
            ->onlyMethods(['get_privacy_manager'])
1615
            ->onlyMethods(['get_privacy_manager'])
1600
            ->getMock();
1616
            ->getMock();
Línea 1639... Línea 1655...
1639
                'delete_data_for_user',
1655
                'delete_data_for_user',
1640
                'delete_data_for_all_users_in_context',
1656
                'delete_data_for_all_users_in_context',
1641
            ])
1657
            ])
1642
            ->getMock();
1658
            ->getMock();
1643
        $mockprivacymanager->expects($this->atLeastOnce())->method('delete_data_for_user');
1659
        $mockprivacymanager->expects($this->atLeastOnce())->method('delete_data_for_user');
-
 
1660
        $deleteinvocations = $this->exactly(2);
1644
        $mockprivacymanager->expects($this->exactly(2))
1661
        $mockprivacymanager->expects($deleteinvocations)
1645
            ->method('delete_data_for_all_users_in_context')
1662
            ->method('delete_data_for_all_users_in_context')
-
 
1663
            ->willReturnCallback(function ($context) use (
1646
            ->withConsecutive(
1664
                $deleteinvocations,
1647
                [$blockcontext],
1665
                $blockcontext,
1648
                [$usercontext]
1666
                $usercontext,
-
 
1667
            ): void {
-
 
1668
                match (self::getInvocationCount($deleteinvocations)) {
-
 
1669
                    1 => $this->assertEquals($blockcontext, $context),
-
 
1670
                    2 => $this->assertEquals($usercontext, $context),
-
 
1671
                    default => $this->fail('Unexpected invocation count'),
-
 
1672
                };
1649
            );
1673
            });
Línea 1650... Línea 1674...
1650
 
1674
 
1651
        $manager = $this->getMockBuilder(\tool_dataprivacy\expired_contexts_manager::class)
1675
        $manager = $this->getMockBuilder(\tool_dataprivacy\expired_contexts_manager::class)
1652
            ->onlyMethods(['get_privacy_manager'])
1676
            ->onlyMethods(['get_privacy_manager'])
1653
            ->getMock();
1677
            ->getMock();
Línea 1858... Línea 1882...
1858
                'delete_data_for_user',
1882
                'delete_data_for_user',
1859
                'delete_data_for_all_users_in_context',
1883
                'delete_data_for_all_users_in_context',
1860
            ])
1884
            ])
1861
            ->getMock();
1885
            ->getMock();
1862
        $mockprivacymanager->expects($this->never())->method('delete_data_for_user');
1886
        $mockprivacymanager->expects($this->never())->method('delete_data_for_user');
-
 
1887
        $deleteinvocations = $this->exactly(2);
1863
        $mockprivacymanager->expects($this->exactly(2))
1888
        $mockprivacymanager->expects($deleteinvocations)
1864
            ->method('delete_data_for_all_users_in_context')
1889
            ->method('delete_data_for_all_users_in_context')
-
 
1890
            ->willReturnCallback(function ($context) use (
1865
            ->withConsecutive(
1891
                $deleteinvocations,
1866
                [$forumcontext],
1892
                $forumcontext,
1867
                [$coursecontext]
1893
                $coursecontext,
-
 
1894
            ): void {
-
 
1895
                match (self::getInvocationCount($deleteinvocations)) {
-
 
1896
                    1 => $this->assertEquals($forumcontext, $context),
-
 
1897
                    2 => $this->assertEquals($coursecontext, $context),
-
 
1898
                    default => $this->fail('Unexpected invocation count'),
-
 
1899
                };
1868
            );
1900
            });
Línea 1869... Línea 1901...
1869
 
1901
 
1870
        $manager = $this->getMockBuilder(\tool_dataprivacy\expired_contexts_manager::class)
1902
        $manager = $this->getMockBuilder(\tool_dataprivacy\expired_contexts_manager::class)
1871
            ->onlyMethods(['get_privacy_manager'])
1903
            ->onlyMethods(['get_privacy_manager'])
1872
            ->getMock();
1904
            ->getMock();
Línea 1916... Línea 1948...
1916
    /**
1948
    /**
1917
     * Data provider for the can_process_deletion tests.
1949
     * Data provider for the can_process_deletion tests.
1918
     *
1950
     *
1919
     * @return  array
1951
     * @return  array
1920
     */
1952
     */
1921
    public function can_process_deletion_provider(): array {
1953
    public static function can_process_deletion_provider(): array {
1922
        return [
1954
        return [
1923
            'Pending' => [
1955
            'Pending' => [
1924
                expired_context::STATUS_EXPIRED,
1956
                expired_context::STATUS_EXPIRED,
1925
                false,
1957
                false,
1926
            ],
1958
            ],
Línea 1954... Línea 1986...
1954
    /**
1986
    /**
1955
     * Data provider for the is_complete tests.
1987
     * Data provider for the is_complete tests.
1956
     *
1988
     *
1957
     * @return  array
1989
     * @return  array
1958
     */
1990
     */
1959
    public function is_complete_provider(): array {
1991
    public static function is_complete_provider(): array {
1960
        return [
1992
        return [
1961
            'Pending' => [
1993
            'Pending' => [
1962
                expired_context::STATUS_EXPIRED,
1994
                expired_context::STATUS_EXPIRED,
1963
                false,
1995
                false,
1964
            ],
1996
            ],
Línea 1989... Línea 2021...
1989
    /**
2021
    /**
1990
     * Data provider for the is_fully_expired tests.
2022
     * Data provider for the is_fully_expired tests.
1991
     *
2023
     *
1992
     * @return  array
2024
     * @return  array
1993
     */
2025
     */
1994
    public function is_fully_expired_provider(): array {
2026
    public static function is_fully_expired_provider(): array {
1995
        return [
2027
        return [
1996
            'Fully expired' => [
2028
            'Fully expired' => [
1997
                [
2029
                [
1998
                    'status' => expired_context::STATUS_APPROVED,
2030
                    'status' => expired_context::STATUS_APPROVED,
1999
                    'defaultexpired' => 1,
2031
                    'defaultexpired' => 1,