Make WordPress Core

Ticket #22233: 22233 update-option-unit-test.patch

File 22233 update-option-unit-test.patch, 2.1 KB (added by jrf, 10 years ago)
  • tests/phpunit/tests/option/updateOption.php

    From 2660b1cd98dacd65af82a15bb063af5c629d1a62 Mon Sep 17 00:00:00 2001
    From: jrfnl <github_nospam@adviesenzo.nl>
    Date: Thu, 10 Dec 2015 06:24:51 +0100
    Subject: [PATCH] Add unit test for ticket 22233. Props @exz.
    
    ---
     tests/phpunit/tests/option/updateOption.php | 27 ++++++++++++++++++++++++---
     1 file changed, 24 insertions(+), 3 deletions(-)
    
    diff --git a/tests/phpunit/tests/option/updateOption.php b/tests/phpunit/tests/option/updateOption.php
    index 01064ca..a3c1fbd 100644
    a b class Tests_Option_UpdateOption extends WP_UnitTestCase { 
    9999        }
    100100
    101101        /**
    102          * @group 26394
     102         * @ticket 26394
    103103         */
    104104        public function test_autoload_should_be_updated_for_existing_option_when_value_is_changed() {
    105105                global $wpdb;
    class Tests_Option_UpdateOption extends WP_UnitTestCase { 
    120120        }
    121121
    122122        /**
    123          * @group 26394
     123         * @ticket 26394
    124124         */
    125125        public function test_autoload_should_not_be_updated_for_existing_option_when_value_is_unchanged() {
    126126                global $wpdb;
    class Tests_Option_UpdateOption extends WP_UnitTestCase { 
    142142        }
    143143
    144144        /**
    145          * @group 26394
     145         * @ticket 26394
    146146         */
    147147        public function test_autoload_should_not_be_updated_for_existing_option_when_value_is_changed_but_no_value_of_autoload_is_provided() {
    148148                global $wpdb;
    class Tests_Option_UpdateOption extends WP_UnitTestCase { 
    166166        }
    167167
    168168        /**
     169         * @ticket 22233
     170         */
     171        public function test_update_option_should_save_on_changed_instance_of_nested_object() {
     172                $key = rand_str();
     173
     174                $obj1 = new stdClass;
     175                $obj2 = new stdClass;
     176
     177                $obj1->prop = false;
     178                $obj2->prop = false;
     179
     180                $array = array( $obj1, $obj2 );
     181                $this->assertTrue( add_option( $key, $array ) );
     182
     183                $array[0]->prop = true;
     184                $this->assertTrue( update_option( $key, $array ) );
     185                $array[1]->prop = true;
     186                $this->assertTrue( update_option( $key, $array ) );
     187        }
     188
     189        /**
    169190         * `add_filter()` callback for test_should_respect_default_option_filter_when_option_does_not_yet_exist_in_database().
    170191         */
    171192        public function __return_foo() {