WordPress.org

Make WordPress Core

Ticket #46577: 46577.diff

File 46577.diff, 2.1 KB (added by desrosj, 22 months ago)
  • tests/phpunit/tests/privacy/wpPrivacyGeneratePersonalDataExportFile.php

     
    214214        }
    215215
    216216        /**
     217         * When the index.html file cannot be created an error should be displayed.
     218         *
     219         * @ticket 44233
     220         */
     221        public function test_detects_cannot_create_index() {
     222                // Make the export directory read only so the index.html file can't be created.
     223                mkdir( self::$exports_dir );
     224                chmod( self::$exports_dir, 0444 );
     225
     226                if ( '444' !== substr( decoct( fileperms( self::$exports_dir ) ), -3 ) ) {
     227                        $this->markTestSkipped( 'Data export directory permissions were not changed correctly.' );
     228                }
     229
     230                $this->setExpectedException( 'WPDieException' );
     231                $this->expectOutputString( '{"success":false,"data":"Unable to protect export folder from browsing."}' );
     232                wp_privacy_generate_personal_data_export_file( self::$export_request_id );
     233        }
     234
     235        /**
    217236         * Test that an index.html file can be added to the export directory.
    218237         *
    219238         * @ticket 44233
     
    226245        }
    227246
    228247        /**
     248         * When the export directory is not writable the report should fail to write.
     249         *
     250         * @ticket 44233
     251         */
     252        public function test_detects_cannot_write_html() {
     253                // Make the folder read only so HTML writing will fail.
     254                mkdir( self::$exports_dir );
     255                touch( self::$exports_dir . 'index.html' );
     256                chmod( self::$exports_dir, 0555 );
     257
     258                if ( '555' !== substr( decoct( fileperms( self::$exports_dir ) ), -3 ) ) {
     259                        $this->markTestSkipped( 'Data export directory permissions were not changed correctly.' );
     260                }
     261
     262                $this->setExpectedException( 'WPDieException' );
     263                $this->expectOutputString( '{"success":false,"data":"Unable to open export file (HTML report) for writing."}' );
     264                wp_privacy_generate_personal_data_export_file( self::$export_request_id );
     265
     266                $this->assertEmpty( $this->export_file_name );
     267        }
     268
     269        /**
    229270         * Test that an export file is successfully created.
    230271         *
    231272         * @ticket 44233