Title: ユニットテストで日付指定で作った投稿の日付の取得
Last modified: 2016年9月15日

---

# ユニットテストで日付指定で作った投稿の日付の取得

 *  [ShinichiN](https://ja.wordpress.org/support/users/shinichin/)
 * (@shinichin)
 * [11年、 1ヶ月前](https://ja.wordpress.org/support/topic/%e3%83%a6%e3%83%8b%e3%83%83%e3%83%88%e3%83%86%e3%82%b9%e3%83%88%e3%81%a7%e6%97%a5%e4%bb%98%e6%8c%87%e5%ae%9a%e3%81%a7%e4%bd%9c%e3%81%a3%e3%81%9f%e6%8a%95%e7%a8%bf%e3%81%ae%e6%97%a5%e4%bb%98%e3%81%ae/)
 * 以下のテストがある際に、get_the_date() で日付を取得すると、`January 1, 1970`が
   返ってきます。
 *     ```
       <?php
   
       class SampleTest extends WP_UnitTestCase {
   
       	public $the_post;
   
       	public function setUp() {
   
       		parent::setUp();
   
       		$post_date     = '2015-09-21 00:00:00';
       		$post_date_gmt = get_gmt_from_date( $post_date );
   
       		$this->the_post = $this->factory->post->create_and_get( array(
       			'post_title'    => 'Posted on 21th Sept, 2015',
       			'post_date'     => $post_date,
       			'post_date_gmt' => $post_date_gmt,
       		) );
   
       		update_option( 'date_format', 'F j, Y' );
   
       	}
   
       	public function test_this_test() {
   
       		// 通る
       		$this->assertEquals( 'Posted on 21th Sept, 2015', get_the_title( $this->the_post ) );
   
       	}
   
       	public function test_date_format_none() {
   
       		$this->assertEquals( 'September 21, 2015', get_the_date( '', $this->the_post ) );
   
       	}
   
       }
       ```
   
 *     ```
       $ phpunit
       Installing...
       Running as single site... To run multisite, use -c tests/phpunit/multisite.xml
       Not running ajax tests. To execute these, use --group ajax.
       Not running ms-files tests. To execute these, use --group ms-files.
       Not running external-http tests. To execute these, use --group external-http.
       PHPUnit 4.3.1 by Sebastian Bergmann.
   
       Configuration read from /var/www/wordpress/wp-content/plugins/buddha-calendar-converter/phpunit.xml
   
       .F
   
       Time: 1.75 seconds, Memory: 15.25Mb
   
       There was 1 failure:
   
       1) SampleTest::test_date_format_none
       Failed asserting that two strings are equal.
       --- Expected
       +++ Actual
       @@ @@
       -'September 21, 2015'
       +'January 1, 1970'
   
       /var/www/wordpress/wp-content/plugins/buddha-calendar-converter/tests/test-sample.php:34
   
       FAILURES!
       Tests: 2, Assertions: 2, Failures: 1.
       ```
   
    - WP_Postオブジェクトをvar_dumpすると日付がきちんと入っている
    - `post_date_gmt`パラメータの有無は結果に関係がない
    - `post_date`パラメータの有無も結果に関係がない
    - $this->go_to( ‘/?p=’ . $this->the_post->ID ); してから get_the_date(); して
      も同じ
 * という状態です。

 トピック「ユニットテストで日付指定で作った投稿の日付の取得」には新たに返信すること
はできません。

## タグ

 * [ユニットテスト](https://ja.wordpress.org/support/topic-tag/%e3%83%a6%e3%83%8b%e3%83%83%e3%83%88%e3%83%86%e3%82%b9%e3%83%88/)

 * フォーラム: [プラグイン](https://ja.wordpress.org/support/forum/plugins/)
 * 0件の返信
 * 1人の参加者
 * 最後の返信者: [ShinichiN](https://ja.wordpress.org/support/users/shinichin/)
 * 最後の活動: [11年、 1ヶ月前](https://ja.wordpress.org/support/topic/%e3%83%a6%e3%83%8b%e3%83%83%e3%83%88%e3%83%86%e3%82%b9%e3%83%88%e3%81%a7%e6%97%a5%e4%bb%98%e6%8c%87%e5%ae%9a%e3%81%a7%e4%bd%9c%e3%81%a3%e3%81%9f%e6%8a%95%e7%a8%bf%e3%81%ae%e6%97%a5%e4%bb%98%e3%81%ae/)
 * 状態: 未解決

## トピック

### 人気のトピック

### 返信がないトピック

### サポート関連ではないトピック

### 解決済みのトピック

### 未解決のトピック

### すべてのトピック
