######################################################################
#
# File editing edit_xml
#
######################################################################
body common control
{
  inputs => { "../../default.sub.cf" };
  bundlesequence => { default("$(this.promise_filename)") };
  version => "1.0";
}

#######################################################
bundle agent init
{
  vars:
    "states" slist => { "actual", "expected" };

    "actual"
      string => "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>
<Potatoes>
  <Potato name=\"OnePotato\">
  </Potato>
  <Potato name=\"TwoPotato\">
  </Potato>
  <Potato name=\"ThreePotato\">
  </Potato>
</Potatoes>";

    "expected"
      string => "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>
<Potatoes>
  <Potato name=\"OnePotato\">Hot Potatoes!!!</Potato>
  <Potato name=\"TwoPotato\">
  </Potato>
  <Potato name=\"ThreePotato\">
  </Potato>
</Potatoes>";

  files:
    "$(G.testfile).$(states)"
      create => "true",
      edit_line => init_insert("$(init.$(states))"),
      edit_defaults => init_empty;
}

bundle edit_line init_insert(str)
{
  insert_lines:
    "$(str)";
}

body edit_defaults init_empty
{
  empty_file_before_editing => "true";
}

#######################################################
bundle agent test
{
  meta:
    "test_soft_fail"
      string => "windows",
      meta => { "ENT-10215" };

  vars:
    "text" string => "Hot Potatoes!!!";

  files:
    "$(G.testfile).actual"
      create => "true",
      edit_xml => test_insert("$(test.text)");
}

bundle edit_xml test_insert(str)
{
  set_text:
    "$(str)" select_xpath => "/Potatoes/Potato[@name=\'OnePotato\']";
}

#######################################################
bundle agent check
{
  methods:
    "any"
      usebundle => xml_check_diff(
        "$(G.testfile).actual",
        "$(G.testfile).expected",
        "$(this.promise_filename)",
        "no"
      );
}

### PROJECT_ID: core
### CATEGORY_ID: 27
