function test_sppost1() { $SP = new SP_Post(); $post = $SP->get(21); $this->assertTrue($post['post_title'] == 'Page C-1'); $post['post_title'] = 'Page C-1-test'; $SP->update($post, 21); $post = $SP->get(21); $this->assertTrue($post['post_title'] == 'Page C-1-test'); $post['post_title'] = 'Page C-1'; $SP->update($post, 21); }
function test_insert3() { global $wpdb; $P = new SP_Post(); $post = array(); $post['post_title'] = 'Test Meta'; $post['a'] = 'Apple'; $post['b'] = 'Banana'; $post['c'] = 'Carrot'; $this->post_id = $P->insert($post); $this->assertTrue($this->post_id); // Make sure each custom field corresponds to one row in wp_postmeta $sql = $wpdb->prepare("SELECT meta_key, count(*) as cnt FROM {$wpdb->postmeta} WHERE post_id=%s GROUP BY meta_key", $this->post_id); $results = $wpdb->get_results($sql, ARRAY_A); $this->assertTrue($results); foreach ($results as $r) { $this->assertTrue($r['cnt'] == 1); } // Nothing changed: make sure additional rows weren't created. $result = $P->update($post, $this->post_id); $this->assertTrue($result == $this->post_id); // Make sure each custom field corresponds to one row in wp_postmeta $sql = $wpdb->prepare("SELECT meta_key, count(*) as cnt FROM {$wpdb->postmeta} WHERE post_id=%s GROUP BY meta_key", $this->post_id); $results = $wpdb->get_results($sql, ARRAY_A); $this->assertTrue($results); foreach ($results as $r) { $this->assertTrue($r['cnt'] == 1); } // Try nuking a custom field unset($post['c']); // Nothing changed: make sure additional rows weren't created. $result = $P->update($post, $this->post_id, true); $this->assertTrue($result == $this->post_id); $post = $P->get($this->post_id); $this->assertTrue(!isset($post['c'])); // Make sure each custom field corresponds to one row in wp_postmeta $sql = $wpdb->prepare("SELECT meta_key, count(*) as cnt FROM {$wpdb->postmeta} WHERE post_id=%s GROUP BY meta_key", $this->post_id); $results = $wpdb->get_results($sql, ARRAY_A); $this->assertTrue($results); foreach ($results as $r) { $this->assertTrue($r['cnt'] == 1); } // Cleanup: Make sure it's gone $P->delete($this->post_id); $post = $P->get($this->post_id); $this->assertTrue(empty($post)); }