How to send

The following code prints “test” every 5 seconds. It also prints text that I type next the “Send” button and press “Send”. If I type “hello” I get “>h>e>l>l>o>”.

How do get the “test” be printed by my “if (Serial.available()) {…}” code? In other words how do I pipe text to Serial.available -function to handled by my own code?

long i4;

void setup()
{   //Begin serial comunication with Arduino and Arduino IDE (Serial Monitor)
Serial.begin(9600);
Serial.println("Setup Complete!");
i4=millis()+5000; 
}
 
void loop()
{
int i;  
if (Serial.available())
    {    
    i=Serial.read();
    Serial.print(">");
    Serial.print((char)i);
    }
if (millis()>i4)
   {
   Serial.println("test");
   i4=millis()+5000;
   }
}

How do get the "test" be printed by my "if (Serial.available()) {...}" code? In other words how do I pipe text to Serial.available -function to handled by my own code?

You cannot without modifying the IDE internal libraries. But this doesn't make sense anyway. Please describe what you're trying to achieve, not how you're trying to achieve it.
We might find a different solution that works.

Your way to time will work for longer than you care but not more than almost 25 days before a bug appears. It's only that long because millis() returns a 32 bit value.

What always works is to use unsigned integers whether 8 bit byte, 16 bit word or 32 bit unsigned long. Whichever you choose, time will be a repeating count-up to rollover cycle. You can find the correct time between any 2 times in that cycle by subtracting the unsigned start time from the unsigned end time. There is no problem with rollover when using unsigned subtraction. It is like a round clock, if the hour hand is at 2 and I want to know how long ago was 8, I move the hand 8 hours to the left (end time 2 - start time 8) and the answer is 6 hours ago.

The -subtraction- yields the -difference-.

unsigned long i4; // or a better name like tStart;

// i4=millis()+5000; // in setup, get rid of this line, i4 starts at 0



if (millis() - i4 >= 5000 ) // this always works
   {
   Serial.println("test");
   i4 += 5000;  // i4 was the old start time, now is what it should be even when the if() is > 5000 instead of ==
   }

How do get the "test" be printed by my "if (Serial.available()) {...}" code? In other words how do I pipe text to Serial.available -function to handled by my own code?

What you print goes to Serial monitor where you type entries.
You want your own code in the Serial.available function then just put it there.

newuser:
The following code prints "test" every 5 seconds. It also prints text that I type next the "Send" button and press "Send". If I type "hello" I get ">h>e>l>l>o>".

Have a look at the examples in Serial Input Basics - simple reliable ways to receive data. The second example is probably what you need.

How do get the "test" be printed by my "if (Serial.available()) {...}" code? In other words how do I pipe text to Serial.available -function to handled by my own code?

Create a char variable

char myText[] = "test ";

and include that when you are printing

if (newData == true) {
   Serial.print(myText);
   Serial.println(receivedChars);
}

...R