Example #1
0
 /**
  * Enqueues the needed scripts and styles.
  */
 public function enqueue()
 {
     $bundle_url = $this->plugin->dir_url('assets/js/dist/idlikethis-admin.js');
     wp_enqueue_script('idlikethis-admin', $bundle_url, array('backbone'), null, true);
     $data = $this->data_provider->get_data();
     wp_localize_script('idlikethis-admin', 'idlikethisData', $data);
     wp_nonce_field('wp_rest', 'rest_nonce');
 }
 /**
  * @test
  * it should localize the script data
  */
 public function it_should_localize_the_script_data()
 {
     $sut = $this->make_instance();
     $this->plugin->dir_url('assets/js/dist/idlikethis-admin.js')->willReturn('foo.js');
     $data = ['some' => 'data'];
     $this->data_provider->get_data()->willReturn($data);
     $wp_localize_script = Test::replace('wp_localize_script');
     $sut->enqueue();
     $wp_localize_script->wasCalledWithOnce(['idlikethis-admin', 'idlikethisData', $data]);
 }